IGDTUW 2026 — Computer PYQ
IGDTUW | Computer | 2026What is the output of the following C program?
#include <stdio.h>
int main() {
int x = 012;
printf("%d", x);
return 0;
}
Choose the correct answer:
- A.
10
(Correct Answer) - B.
12
- C.
14
- D.
Compilation Error
10
Explanation
Step-by-Step Explanation:
Identifying the Octal Literal: In C programming, any integer literal that begins with a leading zero (
0) is treated by the compiler as an octal number (base 8), rather than a standard decimal number (base 10).Value of x=0128
Converting Octal to Decimal: To print the value using the
%dformat specifier inprintf, the compiler interprets the integer value in decimal form. We convert the octal representation 12 into its base 10 equivalent by calculating its positional weights:Decimal Value=(1×81)+(2×80)
Decimal Value=(1×8)+(2×1)
Decimal Value=8+2=10
Output Generation: The
printf("%d", x);statement requests the base 10 signed decimal string representation of the variable x. Therefore, it outputs:10
Explanation
Step-by-Step Explanation:
Identifying the Octal Literal: In C programming, any integer literal that begins with a leading zero (
0) is treated by the compiler as an octal number (base 8), rather than a standard decimal number (base 10).Value of x=0128
Converting Octal to Decimal: To print the value using the
%dformat specifier inprintf, the compiler interprets the integer value in decimal form. We convert the octal representation 12 into its base 10 equivalent by calculating its positional weights:Decimal Value=(1×81)+(2×80)
Decimal Value=(1×8)+(2×1)
Decimal Value=8+2=10
Output Generation: The
printf("%d", x);statement requests the base 10 signed decimal string representation of the variable x. Therefore, it outputs:10
