Example: What are the final values of the variables listed below after all the s
ID: 3903258 • Letter: E
Question
Example: What are the final values of the variables listed below after all the statements are executed.
#define SQRT(x) x*x
#define P(x, y) (x > y) ? x + 2 : y * 3
#define Q(x, y) x / y
#define NN 100
int a, b, d, f, g, h, n, aa, bb = 90;
double c, e, m;
int main(void)
{
int i = 5, j = -6, k = 9, z = 10, x = 1, y = 20;
a = NN / SQRT(5);
b = i < 2* j – i || i >=j;
c = (NN - 5) / 2;
d = P(i, -2*i);
e = k = --i;
f = j ? 20 : 5 + z;
g = (k == i – j + 5) * i;
h = Q(j + 20, SQRT(i + 1));
m = NN && z + 2 ;
n = z++ - j; x = !NN || k * 3;
y %= (int)(50.0/i);
return(0); }
a = ------- b = -------- c = ------- d = ------- e = -------- f = ------- g = ------- h = -------- m = ------- n = ------- i = -------- j = ------- n = ------- x = -------- y = ------- z = -------- aa = -------- bb = -------
please show step by step
Explanation / Answer
1)
a=NN/SQRT(5)=100/5*5=20*5=100
2)
b=i<2*j-i||i>=j (since i>=j is true as 5>=-6 and returns 1 so b=1)
3)
c=(NN-5)/2=(100-5)/2=95/2=47
4)
d=P(i,-2*i)=P(5,-10)=(5>-10) and it returns true so x+2 is evaluated and 5+2=7 is stored in d
5)
e=k=--i=--5=4 so 4 is assigned to k and e and i value becomes 4
6)
f=j?20:5+z=-6 is not equal to 0 and returns true so 20 is stored in f
7)
g=(k==i-j+5)*i=(4==4-(-6)+5)*4=(4==15)*4=0*4=0
8)
h=Q(j+20,SQRT(i+1))=Q(-6+20,SQRT(4+1))=-6+20/4+1*4+1=-6+5+4+1=4
9)
m=NN&&z+2=100&&10+2=100&&12=1
10)
n=z++-j=10-(-6)=10+6=16 and z value becomes 11
11)
x=!NN||k*3=!100||k*3=0||4*3=0||12=1
12)
y%=(int)(50.0/i)=(int)(50.0/4)=12
y=y%12=20%12=8
13)
z=11
aa=0 and bb=90
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.