Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

main() { printf("%x",-1<<4); }

3 Answers   HCL, Sokrati, Zoho,


int a=1; printf("%d %d %d",a++,a++,a); need o/p in 'c' and what explanation too

1 Answers  


write a program to Insert in a sorted list

4 Answers   Microsoft,


Write, efficient code for extracting unique elements from a sorted list of array. e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) -> (1, 3, 5, 9).

13 Answers   Intel, Microsoft, TCS,


how to check whether a linked list is circular.

11 Answers   Microsoft,


Is the following code legal? struct a { int x; struct a b; }

1 Answers  


main() { int (*functable[2])(char *format, ...) ={printf, scanf}; int i = 100; (*functable[0])("%d", i); (*functable[1])("%d", i); (*functable[1])("%d", i); (*functable[0])("%d", &i); } a. 100, Runtime error. b. 100, Random number, Random number, Random number. c. Compile error d. 100, Random number

1 Answers   HCL, rsystems,


char *someFun() { char *temp = “string constant"; return temp; } int main() { puts(someFun()); }

1 Answers  


# include<stdio.h> aaa() { printf("hi"); } bbb(){ printf("hello"); } ccc(){ printf("bye"); } main() { int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; ptr[2](); }

1 Answers  


main() { printf("%d, %d", sizeof('c'), sizeof(100)); } a. 2, 2 b. 2, 100 c. 4, 100 d. 4, 4

18 Answers   HCL, IBM, Infosys, LG Soft, Satyam,


could you please send the program code for multiplying sparse matrix in c????

0 Answers  


main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); }

1 Answers  


Categories