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



main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); ..

Answer / guest

error

Is This Answer Correct ?    2 Yes 0 No

main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); ..

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

main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); ..

Answer / friend

i think above program ans ramesh

Is This Answer Correct ?    0 Yes 0 No

main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); ..

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

Post New Answer

More C Interview Questions

When you call malloc() to allocate memory for a local pointer, do you have to explicitly free() it?

2 Answers   Aloha Technology,


Can you write a programmer for FACTORIAL using recursion?

0 Answers   ADP,


Is it possible to execute code even after the program exits the main() function?

0 Answers  


how to print value of e(exp1)up to required no of digits after decimal?

1 Answers  


how to connect oracle in C/C++.

3 Answers   TCS, Wipro,






what are you see during placement time in the student.

0 Answers   Goldman Sachs, TCS, Tech Solutions,


Explain the use of fflush() function?

0 Answers  


Is an array parameter is always "by reference" ?

1 Answers  


what's the return value of malloc()

9 Answers  


what is the defrenece between structure and union

5 Answers   Aloha Technology,


How will you allocate memory to a double pointer ?

2 Answers  


What is the g value paradox?

0 Answers  


Categories