MCQs
Step 1: int k, num=30; here variable k and num are declared as an integer type and
variable num is initialized to '30'.
Step 2: k = (num>5 ? (num <=10 ? 100 : 200): 500); This statement does not affect the
output of the program. Because we are going to print the variable num in the next statement.
So, we skip this statement.
Step 3: printf("%d`setminus`n", num); It prints the value of variable num '30'
Step 3: Hence the output of the program is '30'
No answer description available for this question.
The order of evaluation of arguments passed to a function call is unspecified.
Anyhow, we consider ++i, ++i are Right-to-Left associativity. The output of the program is 4, 3.
In TurboC, the output will be 4, 3.
In GCC, the output will be 4, 4.
Step 1: int x=55; here variable x is declared as an integer type and initialized to '55'.
Step 2: printf("%d, %d, %dn", x<=55, x=40, x>=10);
In printf the execution of expressions is from Right to Left.
here x>=10 returns TRUE hence it prints '1'.
x=40 here x is assigned to 40 Hence it prints '40'.
x<=55 returns TRUE. hence it prints '1'.
Step 3: Hence the output is "1, 40, 1".
Step 1: int a=100, b=200, c;
Step 2: c = (a == 100 || b > 200);
becomes c = (100 == 100 || 200 > 200);
becomes c = (TRUE || FALSE);
becomes c = (TRUE);(ie. c = 1)
Step 3: printf("c=%d`setminus`n", c); It prints the value of variable i=1
Hence the output of the program is '1'(one).
Step 1: int x=4, y, z; here variable x, y, z are declared as an integer type
and variable x is initialized to 4.
Step 2: y = --x; becomes y = 3; because (--x) is pre-decrement operator.
Step 3: z = x--; becomes z = 3;. In the next step variable x becomes 2, because
(x--) is post-decrement operator.
Step 4: printf("%d, %d, %d`setminus`n", x, y, z); Hence it prints "2, 3, 3".
Step 1: int i=-3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and
variable i, j, k are initialized to -3, 2, 0 respectively.
Step 2: m = ++i && ++j || ++k;
becomes m = (-2 && 3) || ++k;
becomes m = TRUE || ++k;.
(++k) is not executed because (-2 && 3) alone return TRUE.
Hence this statement becomes TRUE. So it returns '1'(one). Hence m=1.
Step 3: printf("%d, %d, %d, %d`setminus`n", i, j, k, m); In the previous step the value of i,j are increemented by '1'(one).
Hence the output is "-2, 3, 0, 1".
Step 1: static int a[20]; here variable a is declared as an integer type and static. If a variable is declared as static and it will be automatically initialized to value '0'(zero).
Step 2: int i = 0; here vaiable i is declared as an integer type and initialized to '0'(zero).
Step 3: a[i] = i ; becomes a[0] = 0;
Step 4: printf("%d, %d, %dn", a[0], a[1], i);
Here a[0] = 0, a[1] = 0(because all staic variables are initialized to '0') and i = 0.
Step 4: Hence the output is "0, 0, 0".
Step 1: int i=4, j=-1, k=0, w, x, y, z; here variable i, j, k, w, x, y, z are declared as an integer type
and the variable i, j, k are initialized to 4, -1, 0 respectively.
Step 2: w = i || j || k; becomes w = 4 || -1 || 0;. Hence it returns TRUE. So, w=1
Step 3: x = i && j && k; becomes x = 4 && -1 && 0; Hence it returns FALSE. So, x=0
Step 4: y = i || j &&k; becomes y = 4 || -1 && 0; Hence it returns TRUE. So, y=1
Step 5: z = i && j || k; becomes z = 4 && -1 || 0; Hence it returns TRUE. So, z=1.
Step 6: printf("%d, %d, %d, %d`setminus`n", w, x, y, z); Hence the output is "1, 0, 1, 1".
Step 1: int x=12, y=7, z; here variable x, y and z are declared as an integer and variable x and y are initialized to 12, 7 respectively.
Step 2: z = x!=4 || y == 2;
becomes z = 12!=4 || 7 == 2;
then z = (condition true) || (condition false); Hence it returns 1. So the value of z=1.
Step 3: printf("z=%dn", z); Hence the output of the program is "z=1".