Home / C Programming / Memory Allocation :: Discussion

Discussion :: Memory Allocation

  1. Point out the error in the following program.

     #include
     #include 
    
      int main() 
      {
          char *ptr;  
         *ptr = (char)malloc(30);     
         strcpy(ptr, "RAM");     
         printf("%s", ptr);    
         free(ptr);    
         return 0; 
     } 
    
    

     

  2. A.

    Error: in strcpy() statement.

    B.

    Error: in *ptr = (char)malloc(30);

    C.

    Error: in free(ptr);

    D.

    No error

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    Answer: ptr = (char*)malloc(30);


Be The First To Comment