#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char *p1="name";
char *p2;
p2=(char*)malloc(20);
memset(p2,0,20);
char *temp = p2; // add this line of code
// which stores the pointer location returned by malloc
while(*p2++=*p1++); // copy string content pointed by p1 to p2
// in this process both p1 and p2 gets incremented
printf("%s\n",temp);// temp still pointing to the start
// of newly created string
}