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

simple c program for 12345 convert 54321 with out using string

7 Answers   TCS,


what is data structure.in linear and non linear data structures which one is better?Explain

3 Answers   Wipro,


WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management?

28 Answers   3D PLM, Code Studio, Deltech, IBM,


ratio,age,persentage

0 Answers  


What is the meaning When we write "#include" what is # and what does include does there???

22 Answers   HCL, Wipro,






How does normalization of huge pointer works?

0 Answers  


What language is windows 1.0 written?

0 Answers  


Is an array parameter is always "by reference" ?

1 Answers  


WAP to accept basic salary of an employee? Calculate it HRA=25%,DA=30%,PF=30%&net salary display all contents?

6 Answers   Finite Infotech, Lovely Professional University, Wipro,


What is Lazy evaluation in C? Give an example.

1 Answers  


int array[]={1,2,3,4,5,6,7,8}; #define SIZE (sizeof(array)/sizeof(int)) main() { if(-1<=SIZE) printf("1"); else printf("2"); }

2 Answers   Vector,


Write a program to find whether the given number is prime or not?

6 Answers  


Categories