edited by
756 views
0 votes
0 votes

Predict the output of following code segment:
 

#include<iostream.h>
Void main ( )
{
int x { } = {1,2,3,4,5};
int *p,**q,*t;
p=x;
cout<<*p;
t=x+2;
q=&t;
cout<<*++p <<**q <<**q <<*t;}

(a) 1233 (b) 1223 (d) 1234 (d) 2345

edited by

1 Answer

0 votes
0 votes

Ans will be 12333

p=x Here p is holding the address of to 1st element of x.

Now, p is printing 1st element of x, i.e. 1

t=x+2;

Here t is holding address of x+$2\times size of int$=2000+$2\times4$=2008, i.e. addess of 3

q is a pointer that holding address of t.

So, q pointing same element as t

Now, p is preincremented, so it increment the address by 4 Bytes.

So, value pointed by p is 2
q and t already pointing to address of 3

So, output 12333

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
4
altamash asked Apr 12, 2019
323 views
int main();{int a,*b, c, *d, e;a=10;b=&a;c=&b;d=&c;e=&d;print f(“a=%d b=%u c=%u d=%u e=%u e=%u\n”, a,b,c,d,e);print f(“ %d %d %d \n”,a,a+*b, c+ *d+, e);return 0...