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

What are enumerated types?

0 Answers  


How do you initialize function pointers? Give an example?

3 Answers  


Write a program to identify if a given binary tree is balanced or not.

0 Answers   JPMorgan Chase,


what is the self-referential structure?

1 Answers  


What is the meaning of 2d in c?

0 Answers  






What is call by reference in functions?

1 Answers  


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

1 Answers  


Write a code of a general series where the next element is the sum of last k terms.

0 Answers   Aspiring Minds,


What language is c written?

0 Answers  


Can we access RAM? How? Whats the range of access? Similarly What are other hardware we can access?

1 Answers  


the maximum value that an integer constant can have is a) -32767 b) 32767 c) 1.701e+38 d) -1.7014e+38

1 Answers  


What is the difference between exit() and _exit() function in c?

0 Answers  


Categories