Correct Answer : A
Execution of program starts from main
. Inside main
five integer variables are declared and initialized as follows:
i = 200
j = 020
k = 0x02
l = 220
m = 0x202
variables i, l
are decimals (base = 10), variable j
is octal (base = 8) since preceeded by 0
and variables k, m
are hexadecimals since preceeded by 0x
. Variable sum
is declared and assigned to sum of all the above variables. But to add them, all numbers must be of same base. So convert octals to decimals, hexadecimals to decimals and add.
020 = 2 * 8 ^ 1 + 0 * 8 ^ 0 = 16
0x02 = 0 * 16 ^ 1 + 2 * 16 ^ 0 = 2
0x202 = 2 * 16 ^ 2 + 0 * 16 ^ 1 + 2 * 16 ^ 0 = 514
So sum = 200 + 16 + 2 + 220 + 514 = 952