Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CLA-11-03 Exam - Topic 3 Question 5 Discussion

What happens if you try to compile and run this program?#include int main (int argc, char *argv[]) {char i = 20 + 020 + 0x20;printf("%d",i);return 0;}Choose the right answer:
A) The program outputs 68
B) The program outputs 60
C) Compilation fails
D) The program outputs 86
E) The program outputs 62

C++ Institute CLA-11-03 Exam - Topic 3 Question 5 Discussion

Actual exam question for C++ Institute's CLA-11-03 exam
Question #: 5
Topic #: 3
[All CLA-11-03 Questions]

What happens if you try to compile and run this program?

#include

int main (int argc, char *argv[]) {

char i = 20 + 020 + 0x20;

printf("%d",i);

return 0;

}

Choose the right answer:

Show Suggested Answer Hide Answer
Suggested Answer: A

* The program is a valid C program that can be compiled and run without errors.

* The variable i is declared as a char, which is an 8-bit signed integer type that can store val-ues from -128 to 127.

* The expression 20 + 020 + 0x20 evaluates to 68, because:

o 20 is a decimal literal with the value 20

o 020 is an octal literal with the value 16 (8^1 * 2 + 8^0 * 0)

o 0x20 is a hexadecimal literal with the value 32 (16^1 * 2 + 16^0 * 0)

o The + operator performs arithmetic addition on the operands and returns the sum

* The printf function prints the value of i as a decimal integer using the %d format specifier.

* The output of the program is 68.


Contribute your Thoughts:

0/2000 characters

Currently there are no comments in this discussion, be the first to comment!


Save Cancel