adplus-dvertising
frame-decoration

Question

Point out the error in the following program.
#include <stdio.h>
#include  <stdlib.h>
int main()
{
    char *ptr;
    *ptr = (char)malloc(30);
    strcpy(ptr, "RAM");
    printf("%s", ptr);
    free(ptr);
    return 0;
}

a.

Error: in strcpy() statement

b.

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

c.

Error: in free(ptr);

d.

No Error

Posted under C Programming

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

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Point out the error in the following program.