Home / C Programming / Memory Allocation :: Point Out Correct Statements

C Programming :: Memory Allocation

  1. Which of the following statement is correct prototype of the malloc() function in c ?

  2. A.
    int* malloc(int);
    B.
    char* malloc(char);
    C.
    unsigned int* malloc(unsigned int);
    D.
    void* malloc(size_t);

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. 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;
      } 

     

  4. A.

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

    B.

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

    C.

    free(p->s);

    D.

    free(p);

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. Point out the correct statement which correctly allocates memory dynamically for 2D array following program?

     #include
     #include 
    
      int main() 
      {     
            int *p, i, j;  
            /* Add statement here */   
            for(i=0; i3; i++)    
            {         
                 for(j=0; j4; j++)       
                 {             
                     p[i*4+j] = i;      
                     printf("%d", p[i*4+j]);        
                 } 
             }  
             return 0;
         } 
    
    

  6. A.

    p = (int*) malloc(3, 4);

    B.

    p = (int*) malloc(3*sizeof(int));

    C.

    p = malloc(3*4*sizeof(int));

    D.

    p = (int*) malloc(3*4*sizeof(int));

    View Answer

    Workspace

    Discuss Discuss in Forum