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

Can you write the function prototype, definition and mention the other requirements.

0 Answers   Adobe,


What is character constants?

0 Answers  


What is static function in c?

0 Answers  


Where is volatile variable stored?

0 Answers  


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?

0 Answers  


two variables are added answer is stored on not for third variable how it is possible?

3 Answers  


Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?

0 Answers  


Why Modern OS are interrupt driven?Give an example

3 Answers  


Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.

0 Answers   Expedia,


Write a program to generate prime factors of a given integer?

2 Answers  


What is a dynamic array in c?

0 Answers  


Categories