(4) 1. Simplify the following assignments/calculations if possible:
a. a = 0; b = 0; c = 0; d = 0; _____________________________
b. n1 = n1 % n2; _____________________________
c. n3 += 1; _____________________________
d. n4 = n5 / n4; _____________________________
2. Suppose that the statement x = 12; has already been done. What values will the following printf statements output assuming that the statements are done in the following order:
a. printf("%d\n", ++x); __________ b. printf("%d\n", x); __________ c. printf("%d\n", x--); __________ d. printf("%d\n", x); __________
(4) 1.
(a) a=b=c=d=0; (This is a multiple assignment statment, and associativity is from right to left, 0 assigned to d first,value of d(0) is assigned to c ,and c to b, and b to a)
(b) n1%=n2 ; ( x=x%y is same as x%=y)
(c) n3++ or ++n3 ( n3 += 1, n3=n3+1, the same is done by increment operator, which increments the value of variable by 1)
(d) n4=n5/n4
2) ( a) 13 //initially x=12, then ++x , its is preincrement operator, value is first incremented and then used inside the expression. so x is incrementd to x=13 and that value will be printed.
(b) 13 // the value in the previous epression is x=13, so 13 will be printed.
(3) 13 //x=13 then x-- (its post decrement operator,value is first used in a expression and then decremented. So value will be printed first i.e 13, then its decremented. x=12
(d)12 // print the value of x, which is 12 (set in the previous expression)
Get Answers For Free
Most questions answered within 1 hours.