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

how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?

0 Answers   Gopaljee, TCS,


Is an array parameter is always "by reference" ?

1 Answers  


What is static memory allocation? Explain

0 Answers  


What is the use of structure padding in c?

0 Answers  


What is the use of a semicolon (;) at the end of every program statement?

1 Answers  






Which is an example of a structural homology?

0 Answers  


C program to find all possible outcomes of a dice?

0 Answers  


If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402

0 Answers  


C program to find frequency of each character in a text file?

6 Answers  


Consider the following C program. #include <stdio.h> int main() { int i; for (i=0;i<3;++i) { fork();fork(); } } How many processes are created when running this program (including the initial one)? Explain

2 Answers  


How does #define work?

0 Answers  


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

0 Answers  


Categories