main()
{
char *p1=“name”;
char *p2;
p2=(char*)malloc(20);
memset (p2, 0, 20);
while(*p2++ = *p1++);
printf(“%sn”,p2);
}
I stumbled upon this piece of code when I was reading about C programming. The output of this code is an empty string. I don't understand what is happening in the while loop. I am completely stumped.
Any insight would be very helpful.
rsshetty.
It's always in the details.
{
char *p1=“name”;
char *p2;
p2=(char*)malloc(20);
memset (p2, 0, 20);
while(*p2++ = *p1++);
printf(“%sn”,p2);
}
I stumbled upon this piece of code when I was reading about C programming. The output of this code is an empty string. I don't understand what is happening in the while loop. I am completely stumped.
Any insight would be very helpful.
rsshetty.
It's always in the details.