872 views
1 votes
1 votes

2 Answers

Best answer
7 votes
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 votes
–1 votes
I've executed on 16 bit DOS Compiler. And d ans is c. :)

Related questions

0 votes
0 votes
1 answer
1
Ankush Tiwari asked Aug 20, 2016
473 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 votes
2 votes
1 answer
2
Registered user 7 asked Aug 19, 2016
543 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 votes
1 votes
1 answer
3
komal07 asked Aug 18, 2016
1,065 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?