Home / C Programming / Functions :: Discussion

Discussion :: Functions

  1. If int is 2 bytes wide.What will be the output of the program?

    #include  
     void fun(char**); 
    
     int main() 
     {    
         char *argv[] = {"ab", "cd", "ef", "gh"};  
         fun(argv);  
         return 0;
     } 
     void fun(char **p)
     {   
         char *t;    
         t = (p+= sizeof(int))[-1];    
         printf("%s\n", t);
     } 
    

     

  2. A.

    ab

    B.

    cd

    C.

    ef

    D.

    gh

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    Since C is a machine dependent language sizeof(int) may return different values.

    The output for the above program will be cd in Windows (Turbo C) and gh in Linux (GCC).

    To understand it better, compile and execute the above program in Windows (with Turbo C compiler) and in Linux (GCC compiler).


Be The First To Comment