main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
Answers were Sorted based on User's Feedback
Answer / subbu[iit kgp]
the given program gives some meaningless output, with some
modification to the given program as
#include<stdio.h>
#include<stdlib.h>
main()
{
char a[]="ramesh";
char *p1="Name";
char *p2=a;
while(*p2++=*p1++);/*copies contents of p1 to
p2*//* here it is not possible to use while(*a++=*p1++)
because a can not change its value*/
*p2='\0';
printf("%s\n",a);
}
The output will be Name
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / vignesh1988i
actually in this problem, the p2 will take characters after '\0' too from p1 upto the size of p2 come to an end.
so it prints
output :
Name #^$&dhd
thank u
Is This Answer Correct ? | 1 Yes | 1 No |
When you call malloc() to allocate memory for a local pointer, do you have to explicitly free() it?
Can you write a programmer for FACTORIAL using recursion?
Is it possible to execute code even after the program exits the main() function?
how to print value of e(exp1)up to required no of digits after decimal?
how to connect oracle in C/C++.
what are you see during placement time in the student.
0 Answers Goldman Sachs, TCS, Tech Solutions,
Explain the use of fflush() function?
Is an array parameter is always "by reference" ?
what's the return value of malloc()
what is the defrenece between structure and union
How will you allocate memory to a double pointer ?
What is the g value paradox?