Sample code for char pointer initialization in c:
What will be the output of below C program?
p = malloc(10);
compile time error
run time crash or may be some garbage value.
char *p; //p is a pointer, which has garbage value now.
p = malloc(10); // we are allocating some memory, and that address we are
placing in p. which is valid.
strcpy(p,"skill"); //now copy "skill" to memory pointed by p.
printf("%s",p); //so it prints "skill".
Back To Top