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 2 Question 4 Discussion

Posted by Annabelle on Sep 26, 2026 at 08:24 AM

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

#include

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

int i = 2;

int d= i << 2;

d /= 2;

printf ("%d", d) ;

return 0;

}

Choose the right answer:

Suggested Answer: B

The program outputs 4 because the expression i << 2 performs a left shift operation on the binary representation of i, which is 00000010, by two bits, resulting in 00001000, which is equivalent to 8 in decimal. Then, the expression d /= 2 performs a division assignment operation, which divides d by 2 and assigns the result back to d, resulting in 4. The printf function then prints the value of d as a decimal integer using the %d format specifier.

Reference = CLA -- C Certified Associate Programmer Certification, [C Essentials 2 - (Intermediate)], C Bitwise Operators, C Assignment Operators


Get Premium CLA-11-03 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
4 comments · newest first
EV
Evette 3 days ago
I’m confused about the output. I thought left shifting would just add zeros, but I guess it’s actually multiplying by powers of two?
LE
Lenny 8 days ago
I practiced a similar question, and I feel like the output should be 4, but I could be wrong about the shift operation.
TR
Truman 13 days ago
I'm not entirely sure, but I remember something about division in C. Wouldn't `d /= 2` make it 4?
MI
Mindy 18 days ago
I think the left shift operator will double the value of `i`, so `d` should be 8 after the shift.
0/2000 characters

Save Cancel