edited by
530 views
0 votes
0 votes
What will be the output of the following program

[Addresses of the variables are assigned continuous]

#include<stdio.h>

void main()

{

int a = 4, b = 8, c = 12, d, e, f ;

int *x=&a , *y=&b, *z =&c ;

d =x - y ;

e =y - z ;

f = d - e ;

printf("%d" ; f) ;

}

(A)Compiler error

(B) -8;

(C)8;

(D) 2;
edited by

1 Answer

0 votes
0 votes
Options are incorrect as the answer is 0.

Let's say address of 'a' = 104;

address of 'b' = 108

address of 'c' = 112

address of 'd' = 116

address of 'e' = 120

address of 'f' = 124

x, y, and z are pointer variables. Therefore, they will store the address of the variables 'a', 'b' and 'c'.

So,

d = x - y = 104 - 108 = -4 / 4 = -1 (Divided by the size of integer)

e = y - z = 108 - 112 = -4 / 4 = -1 (Divided by the size of integer)

f = -1 - (-1) = 0

Now, printf statement will print the answer = 0.
edited by

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
4
Mahbub Alam asked Nov 19, 2018
243 views
#include<stdio.h>void main(){ int i ;for(i=0; i<5; i++)f() ;}void f(){static int x ;x=5 ;x++ ;printf("%d", x);}OUTPUT OF THE FUNCTION IS(A)6,6,6,6,6(B)6,7,8,9,10(C)5,5,5,...