0 votes 0 votes Give the output of the following program #include <iostream.h> void main() { int x[]={5,2,6,9,8}; int *p,**q,*t; p=x; t=x+1; q=&t; cout<<endl<<*++p<<" "<<**q<<" "<<*t++; } (a) 1 1 1 1 (b) 5 2 6 (c) 2 6 2 (d) 2 6 9 Programming in C pointers array-of-pointers + – rohit vishkarma asked Oct 25, 2018 rohit vishkarma 756 views answer comment Share Follow See all 14 Comments See all 14 14 Comments reply Shaik Masthan commented Oct 25, 2018 reply Follow Share cout<<endl<<*++p<<" "<<**q<<" "<<*t++; convey us that it is C++ programming. in GATE, they ask about C programs... But we have to understand the concept behind this question. int x[]={5,2,6,9,8}; let starting at memory 200, the elements stored and integer takes 4 Bytes memory index 0 1 2 3 4 value 5 2 6 9 8 address 200 204 208 212 216 int *p,**q,*t; p is a single pointer, q is a double pointer and t is a single pointer let p stores at memory address 80 let q stores at memory address 810 let t stores at memory address 920 p=x; x is a 1-D array ===> the value of x is memory address of 0th element ==> p points to the 0th element of x ===> p value is 200 t=x+1; x is a 1-D array ===> the value of x is memory address of 0th element ∴ x + 1 is memory address of 1st element ==> t points to the 1st element of x ===> t value is 204 q=&t; q is a double pointer ===> it can store the memory address of the pointer ===> statement is valid the memory address of t is stored at q ===> q value is 920 *++p ===> *(++p) ===> p updated with the value 200+4 = 204 ===> *(204) = value at 204 = 2 **q ===> *( *q ) ===> *( *(920) ) ==> *( 204 ) = value at 204 = 2 *t++ ===> *( t++ ) ===> value update ( 204 + 4 = 208 ) after the sequence point ==> *(204) = value at 204 = 2 1 votes 1 votes Magma commented Oct 25, 2018 reply Follow Share Shaik Masthan answer should be 2 6 2 right ??? 0 votes 0 votes kumar.dilip commented Oct 25, 2018 reply Follow Share Yes, It will be (2, 2, 2). 0 votes 0 votes Magma commented Oct 25, 2018 reply Follow Share q is pointing to t right *t++ ===> *( t++ ) t = 204 +4 =208 So, *q = 208 right ?? 0 votes 0 votes Shaik Masthan commented Oct 25, 2018 reply Follow Share * Higher precedence that ++. ( * > ++) * and ++ have same precedence and their associativity is right to left ===> ++ is evaluated first then * applied @Magma But sequence point not yet reached. 0 votes 0 votes Magma commented Oct 25, 2018 reply Follow Share kumar.dilip try to understand this ! 0 votes 0 votes Magma commented Oct 25, 2018 reply Follow Share Shaik Masthan In C programming , function parameters are evaluated from right to left but printed from left to right 0 votes 0 votes kumar.dilip commented Oct 25, 2018 reply Follow Share What About this Question??? void A(char*S, char *t) { while( *s++ = *t++) } 0 votes 0 votes kumar.dilip commented Oct 25, 2018 reply Follow Share Here the answer will be 2, 6, 2. 0 votes 0 votes kumar.dilip commented Oct 25, 2018 reply Follow Share Shaik Masthan Yes, they are of the same precedence. 0 votes 0 votes kumar.dilip commented Oct 25, 2018 reply Follow Share For this answer will be 2,2,2. cout<<endl<< *++p << " " << *t++ <<" "<< **q; 0 votes 0 votes Magma commented Oct 25, 2018 reply Follow Share yup 0 votes 0 votes Shaik Masthan commented Oct 26, 2018 reply Follow Share In C programming , function parameters are evaluated from right to left but printed from left to right who said? 0 votes 0 votes Magma commented Oct 26, 2018 reply Follow Share Hmm my fault function parameters depends on compiler 0 votes 0 votes Please log in or register to add a comment.