main()

{

char *p="hai friends",*p1;

p1=p;

while(*p!='\0') ++*p++;

printf("%s %s",p,p1);

}

Answers were Sorted based on User's Feedback



main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++;..

Answer / susie

Answer :

ibj!gsjfoet

Explanation:

++*p++ will be parse in the given order

> *p that is value at the location currently pointed by p
will be taken

> ++*p the retrieved value will be incremented

> when ; is encountered the location will be incremented
that is p++ will be executed




Hence, in the while loop initial value pointed by p is ‘h’,
which is changed to ‘i’ by executing ++*p and pointer moves
to point, ‘a’ which is similarly changed to ‘b’ and so on.
Similarly blank space is converted to ‘!’. Thus, we obtain
value in p becomes “ibj!gsjfoet” and since p reaches ‘\0’
and p1 points to p thus p1doesnot print anything.

Is This Answer Correct ?    6 Yes 1 No

main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++;..

Answer / sourav punoriyar

checked in gcc.

it gives segmentation fault(core dump),in gcc...
because the char *p="hai friends",is a pointer pointing to
this string in the code section,(this string is present in
code section.)
now,
++*p=this is ++(*p)=h+1=i,and stores it in p,but data in
code section cannot be modified so core dump.
if
*p++,first dereference and then increases the pointer....so
it will point to a now.

Is This Answer Correct ?    2 Yes 0 No

main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++;..

Answer / sourav punoriyar

but in turbo c it can be the given ans ,as given by susie,
as there it gets stored in datasection which is modifiable

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Code Interview Questions

Write a c program to search an element in an array using recursion

1 Answers   Wipro,


What is the hidden bug with the following statement? assert(val++ != 0);

1 Answers  


PROG. TO PRODUCE 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

1 Answers  


main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }

1 Answers  


posted by surbhi just now main() { float a = 5.375; char *p; int i; p=(char*)&a; for(i=0;i<=3;i++) printf("%02x",(unsigned char) p[i]); } how is the output of this program is :: 0000ac40 please let me know y this output has come

2 Answers   GATE,






how to create a 3x3 two dimensional array that will give you the sums on the left and bottom columns

0 Answers  


How we will connect multiple client ? (without using fork,thread)

3 Answers   TelDNA,


main() { char *p; int *q; long *r; p=q=r=0; p++; q++; r++; printf("%p...%p...%p",p,q,r); }

1 Answers  


#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s; printf("%d",s->x); printf("%s",s->name); }

3 Answers   Hexaware,


main() { show(); } void show() { printf("I'm the greatest"); }

2 Answers  


write a program to Insert in a sorted list

4 Answers   Microsoft,


#include<stdio.h> int main() { int x=2,y; y=++x*x++*++x; printf("%d",y); } Output for this program is 64. can you explain how this output is come??

1 Answers  


Categories