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 |
Can you write the function prototype, definition and mention the other requirements.
What is character constants?
What is static function in c?
Where is volatile variable stored?
How can I make a program in c to print 'Hello' without using semicolon in the code?
9 Answers C DAC, Practical Viva Questions,
Why do we need arrays in c?
two variables are added answer is stored on not for third variable how it is possible?
Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?
Why Modern OS are interrupt driven?Give an example
Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.
Write a program to generate prime factors of a given integer?
What is a dynamic array in c?