512 views
4 votes
4 votes

Answer given is D "gh" . how??

1 Answer

Best answer
2 votes
2 votes

old compilers the size of integer is 2bytes and new compilers the size of integer is 4B.

 If nothing is mention in the question about size of a integer then consider size of int is 4B.if they mention we have to consider that value.

Here size of int is 2B.

char *t;

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

t=(p+2)[-1]   // p+2 it skips 2 positions from start.and p is pointing to array position 2.

p[-1] again it goes back then p points to p[1].

print all characters in that string and output is cd.

So option should be B.

Suppose if we execute this programme on new compilers it gives 'gh' as outpot.

selected by

Related questions

3 votes
3 votes
1 answer
1
Storm_907 asked Apr 16, 2023
470 views
Please explain this question void main() { int a =300; char *ptr = (char*) &a ; ptr++; *ptr=2; printf("%d" , a); }
4 votes
4 votes
4 answers
3
Manoj Kumar Pandey asked May 22, 2019
828 views
https://gateoverflow.in/?qa=blob&qa_blobid=14433986388826671915int main() { int a = 10; int *b = &a; scanf("%d",b); printf("%d",a+50); }What will be the Output of the fol...