What will be the output of the following code?
# include < sidio. h >
int main ( ) {
int a, b, c;
a = ox10; b = o10;
c = a + b:
printf ("%d", c);
return 0;
}
Solution
The correct answer is 24
EXPLANATION:
#include <stdio.h>
int main() {
int a, b, c;
a = 0x10; // Hexadecimal notation for 16
b = 010; // Octal notation for 8
c = a + b;
printf("%d", c);
return 0;
}
0x10 is a hexadecimal representation which is equivalent to 16 in decimal and 010 is an octal representation which is equivalent to 8 in decimal.
So, c = a + b calculates as c = 16 + 8.
Hence, the output will be 24.