Home / C Programming / Memory Allocation :: Discussion

Discussion :: Memory Allocation

  1. Point out the correct statement which correctly free the memory pointed to by 's' and 'p' in the following program?

     #include
     #include 
    
      int main() 
      {   
           struct ex    
           {       
              int i;    
              float j;  
              char *s  
          }; 
          struct ex *p;  
          p = (struct ex *)malloc(sizeof(struct ex));   
          p->s = (char*)malloc(20);   
          return 0;
      } 

     

  2. A.

    free(p); , free(p->s);

    B.

    free(p->s); , free(p);

    C.

    free(p->s);

    D.

    free(p);

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    No answer description available for this question.


Be The First To Comment