edited by
998 views
3 votes
3 votes

I am getting 'cd' , but answer is given as 'gh' . How come ??

edited by

3 Answers

3 votes
3 votes
Its 'cd' only. With a compiler having int size of 4, it is giving 'gh'. So, with 2 bytes of size , it should give 'cd'.
0 votes
0 votes

Here, Int size is given as 2.

so you can rewrite the following statement, 

t = (p+=sizeof(int))[-1] 

as, 

t = (p + 2)[-1] 

which can be further simplify as, 

t = *((p+2)-1)

 Now, t = * (p + 1) points to second element in the array

Hence, Answer is (B)  CD

Related questions

1 votes
1 votes
0 answers
1
0 votes
0 votes
1 answer
2
Hemant Parihar asked Feb 3, 2017
521 views
#include<stdio.h>int main() { char *p; p = "%d\n"; p++; p++; printf(p-2, 400); return 0;}Output : 400I ran this program and got 400 as output. But I don...
2 votes
2 votes
2 answers
4