1,917 views
1 1 vote

2 Answers

Best answer
7 7 votes

Output  is absolutely undefined behaviour.

cout <<endl<<*++p<<""<<**q<<""<<*t++;

This is compiler dependent statement because here variables q and t are pointing at same memory location . Whenever the same memory location is modified twice in a single statement not separated by sequence point the final result will be dependent on compiler implementation. 

The  code executed in the following manner by some compiler :

  1. *t++
  2. **q
  3. *++p

Hence the output can be 262

However when you execute this in other compilers execution can be done as follows

  1. *++p
  2. **q
  3. *t++

you can get  output as 2 2 2 

Well you can verify the compiler dependecy issue by executing

cout <<endl<<*++p<<""<<**q<<""<<*t++;

In different line as follows

#include<stdio.h>
#include<stdlib.h>

void main()
{
    int x[]={5,2,6,9,8};
    int *p,**q,*t;
    p=x;
    t=x+1;
    q=&t;
    printf("%d",*++p );
    printf("%d",**q );
    printf("%d",*t++ );
}

Now , output will be surely 2 2 2 .
 

• selected by
–1 –1 vote
I've executed on 16 bit DOS Compiler. And d ans is c. :)
Position:
Show:

Related questions

0 0 votes
1 1 answer
795
795 views
Ankush Tiwari asked Aug 20, 2016
795 views
#include<stdio.h int main() { char *p1="xyz"; char *p2="xyz"; if(p1==p2) printf("equal"); else printf("unequal"); }Output is equal how??? please explain
2 2 votes
1 answers 1 answer
831
831 views
Registered user 7 asked Aug 19, 2016
831 views
#include<stdio.h #include<stdlib.h int main() { int p=9; printf("%d %d",p++,++p); } how it executed and also how printf function executed left to right or right to left?
1 1 vote
1 answers 1 answer
1.4k
1.4k views
komal07 asked Aug 18, 2016
1,393 views
#include<stdio.h #define CUBE(x) (x*x*x) int main() { int a, b=3; a = CUBE(b++); printf("%d, %d ", a, b); return 0; }Why this give 27,6 as output?
1 1 vote
0 0 answers
860
860 views
PEKKA asked Nov 18, 2016
860 views
What are sequence Points ....?A sequence point defines any point in a computer program's execution at which it is guaranteed that all side effects of previous evaluations...