3 votes 3 votes I am getting 'cd' , but answer is given as 'gh' . How come ?? Programming in C ace-test-series programming programming-in-c array-of-pointers + – Tushar Shinde asked Jan 22, 2016 edited Mar 6, 2019 by akash.dinkar12 Tushar Shinde 998 views answer comment Share Follow See all 4 Comments See all 4 4 Comments reply __ commented Sep 1, 2016 reply Follow Share didn't understood wat they mean by t=(p+=sizeof(int))[-1] 0 votes 0 votes ManojK commented Sep 1, 2016 reply Follow Share For example a[-1]=*(a-1); So given statement will be evaluated as t = *((p+sizeof(int))-1); 0 votes 0 votes srestha commented Sep 1, 2016 reply Follow Share Here int 2 Byte,rt? how it is getting gh? 0 votes 0 votes ManojK commented Sep 1, 2016 reply Follow Share Output can be cd and gh depends on the size of int. 0 votes 0 votes Please log in or register to add a comment.
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'. Tushar Shinde answered Jan 22, 2016 Tushar Shinde comment Share Follow See 1 comment See all 1 1 comment reply cse23 commented Sep 2, 2016 reply Follow Share in gcc compiler it will give gh because it uses int as 4 byte but in turbo C it will give cd 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes t=(p+=sizeof(int))[-1] if int is 2 byte t=(p+=2)[-1] now p is point to ef t=(p+2)[-1] t=*(p+1) output is cd correct me if wrong akankshadewangan24 answered Apr 14, 2017 edited Apr 14, 2017 by akankshadewangan24 akankshadewangan24 comment Share Follow See all 0 reply Please log in or register to add a comment.
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 abhishekdave1 answered Aug 22, 2019 abhishekdave1 comment Share Follow See all 0 reply Please log in or register to add a comment.