Home / C Programming / Memory Allocation :: Discussion

Discussion :: Memory Allocation

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

  2. 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

    Answer : Option D

    Explanation :

    No answer description available for this question.


Be The First To Comment