5 5 votes Answer given is D "gh" . how?? Programming in C + – atul_21 1.3k views answer comment Share Follow Print See all 7 Comments 7 7 Comments reply chandra sai commented Nov 14, 2017 i edited by chandra sai Nov 15, 2017 reply Follow flag t=p=*(p+2-1) That is *(p+1) i.e cd 0 0 replyShare atul_21 commented Nov 14, 2017 reply Follow flag Size of int is given 2 bytes. why did u take 4 here?? 0 0 replyShare Harish Kumar 2 commented Nov 14, 2017 reply Follow flag @chandra sai , I am getting the same answer while computing in IDE but there they are taking value of sizeof(int) as 4. But in this question it is given as 2. So i think answer should be different(i.e. option B). 0 0 replyShare atul_21 commented Nov 14, 2017 reply Follow flag I also marked B option. But given was D What is the conclusion now about this type of question? 0 0 replyShare Harish Kumar 2 commented Nov 14, 2017 reply Follow flag @atul_21, I will be sticking to my solution until someone gives better explanation. 0 0 replyShare chandra sai commented Nov 15, 2017 reply Follow flag @harish thanks for pointing out . now corrected. formerly i assumed default value of int 0 0 replyShare saipriyab commented Nov 20, 2017 reply Follow flag If we take size of int as 2 then answer is cd If we take size of int as 4 the answer is gh 0 0 replyShare Please log in or register to add a comment.
Best answer 3 3 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. santhoshdevulapally answered Nov 15, 2017 • selected Nov 15, 2017 by santhoshdevulapally santhoshdevulapally comment Share Follow 0 reply Please log in or register to add a comment.