What will be the output of the following program?
#include <stdio.h>
int main()
{
register int i = 2;
static char ch = 'A';
auto float j;
int k;
k = ++ch && i;
k = ++ch;
j = i-- + ++k * 2;
printf("%d %f", k, j);
return 0;
}
Answer: C
Correct answer: 68 138.000000
Follow the four statements, with ch starting at 'A' = 65.
k = ++ch && i;-chbecomes 66; both operands are non-zero, sokis 1.k = ++ch;-chbecomes 67 andktakes that value.j = i-- + ++k * 2;-i--contributes 2 (leavingiat 1);++kmakesk68, and \(68 \times 2 = 136\); so \(j = 2 + 136 = 138\).
Printed with %d and %f: 68 138.000000.
Please log in or register to report this question.