CrazyEngineers
  • C query

    ce_neha

    Member

    Updated: Oct 25, 2024
    Views: 1.8K
    Hi ,

    Please make me understand the output of the following code:-

    #include<stdio.h>
    void main()
    {
    char *s1;
    char far *s2;
    char huge *s3;
    printf("%d %d %d ",sizeof(s1),sizeof(s2),sizeof(s3));
    }
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • ameyaamu

    MemberAug 24, 2009

    ce_neha
    Hi ,

    Please make me understand the output of the following code:-

    #include<stdio.h>
    void main()
    {
    char *s1;
    char far *s2;
    char huge *s3;
    printf("%d %d %d ",sizeof(s1),sizeof(s2),sizeof(s3));
    }
    i know answer of 1st 1 byte,4 byte,4byte
    Are you sure? This action cannot be undone.
    Cancel
  • M.Pardhu

    MemberAug 26, 2009

    THE OUTPUT OF PROGRAM IS

    4 4 4



    😎PARDHU😎
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberSep 1, 2009

    The output is 4 4 4 because every pointer is 4 bytes long irrespective of what type it is pointing.
    Are you sure? This action cannot be undone.
    Cancel
  • devil_rads

    MemberSep 10, 2009

    I just ran the program and it is showing the output as 2 4 4....
    Can u please elaborate your ans...
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberSep 10, 2009

    devil_rads
    I just ran the program and it is showing the output as 2 4 4....
    Can u please elaborate your ans...
    The program gives errors on compiling.

    It runs only after modifying in this way
    #include<stdio.h>
    void main()
    {
         char *s1;
         char *s2;
         char *s3;
         printf("%d %d %d ",sizeof(s1),sizeof(s2),sizeof(s3));
         getch();
    }
    
    Output: 4 4 4
    Using dev-c++ compiler. (or gcc)
    Are you sure? This action cannot be undone.
    Cancel
  • brahmaasthra

    MemberSep 13, 2009

    First one char *str : str is a pointer variable which stores an address of a char datatype. So the size is 2 bytes (default). In which you can address from (0000)hexa to (FFFF)hexa. you cant go beyond that.

    Second one is char far *str: far pointer increases the addressable locations. where you can give address ranges from (00000000)hexa to (FFFFFFFF)hexa. Ex:- for the monitor output the address is 0800 0000 hexa.

    Third one is char huge *str: when far pointer overflows ie gets incremented from (FFFFFFFF) + 1 it again goes to (00000000) hexa. The address is inside the same process.
    But in the case of huge if it gets overflow (FFFFFFFF)+1 it goes to the next process 1 0000 0000 hexa.
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberSep 14, 2009

    char *s1;
    char far *s2;
    char huge *s3;
    What is far and huge ?
    Are you sure? This action cannot be undone.
    Cancel
  • Sahithi Pallavi

    MemberSep 14, 2009

    ce_neha
    Hi ,

    Please make me understand the output of the following code:-

    #include<stdio.h>
    void main()
    {
    char *s1;
    char far *s2;
    char huge *s3;
    printf("%d %d %d ",sizeof(s1),sizeof(s2),sizeof(s3));
    }



    hey first can you tell me what is far and huge in your program.?





    WINNERS DONT DO DIFFERENT THINGS....THEY DO THINGS DIFFERENTLY....
    Are you sure? This action cannot be undone.
    Cancel
  • pdpatel

    MemberSep 16, 2009

    ce_neha
    Hi ,

    Please make me understand the output of the following code:-

    #include<stdio.h>
    void main()
    {
    char *s1;
    char far *s2;
    char huge *s3;
    printf("%d %d %d ",sizeof(s1),sizeof(s2),sizeof(s3));
    }
    As per my knowledge:

    This is happen because simple pointer store in ram and far pointer use video memory.
    Are you sure? This action cannot be undone.
    Cancel
  • Saandeep Sreerambatla

    MemberSep 16, 2009

    brahmaasthra
    First one char *str : str is a pointer variable which stores an address of a char datatype. So the size is 2 bytes (default). In which you can address from (0000)hexa to (FFFF)hexa. you cant go beyond that.

    Second one is char far *str: far pointer increases the addressable locations. where you can give address ranges from (00000000)hexa to (FFFFFFFF)hexa. Ex:- for the monitor output the address is 0800 0000 hexa.

    Third one is char huge *str: when far pointer overflows ie gets incremented from (FFFFFFFF) + 1 it again goes to (00000000) hexa. The address is inside the same process.
    But in the case of huge if it gets overflow (FFFFFFFF)+1 it goes to the next process 1 0000 0000 hexa.

    I guess this is the correct answer!!!
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register