Home / C Programming / Memory Allocation :: Discussion

Discussion :: Memory Allocation

  1. What will be the output of the program?

    #include 
    #include 
     
     int main()
     {    
          char *s;  
          char *fun();    
          s = fun();     
          printf("%s\n", s);    
          return 0;
     } 
     char *fun()
     {    
         char buffer[30];   
         strcpy(buffer, "RAM");     
         return (buffer); 
     } 
    

  2. A.

    0xffff

    B.

    Garbage value

    C.

    0xffee

    D.

    Error

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    The output is unpredictable since buffer is an auto array and will die when the control go back to main. Thus s will be pointing to an array , which not exists.


Be The First To Comment