| 1. |
Give the outputs of the following code segments, if any and justify your answers. |
|
Answer» (i) #define CUBE(x) } (i) Output is: 49 macro cube(x *x*x) is expanded into (4+5*4+5*4+5) which is evaluated as 4+20+20+5=49 due to priority of operators. So output is 49. (ii) Output is: 0 0 Both the expressions are evaluated as 0 so the output is 0. (iii) Output is: infinite loop There is an incorrect assignment, j=3 in test expression. (iv) Output is:12 2, The printf is printing the size of char array a and char b, null char is included. (v) Output is:1, The compiler automatically assigns integer digits beginning with 0 to all the enumeration constants so BLUE has value 1. (vi) Output is: u.j=1311,u.c=’β’,u.f=99.989998 The first two outputs are erroneous output which is machine dependent. During accessing a union member, we should make sure that we are accessing the member whose value is currently stored otherwise we will get errors. |
|