New Year Sale 2026! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CPA-21-02 Exam - Topic 3 Question 49 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 49
Topic #: 3
[All CPA-21-02 Questions]

What is the output of the program given below?

#include

using namespace std;

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

{

int i=10;

{

int i=0;

cout<

}

{

i=5;

cout << i;

}

cout<

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

0/2000 characters
Torie
6 days ago
I remember something similar where inner scopes shadowed outer variables. So maybe it prints 0 first?
upvoted 0 times
...
Isabelle
11 days ago
I think the output will be 0, 5, and then 10, but I'm not completely sure about the scope rules.
upvoted 0 times
...
Jamie
16 days ago
Whoa, this is tricky. I better read through the code a few times and draw out the variable scopes to make sure I don't miss anything.
upvoted 0 times
...
Wava
21 days ago
I think I've got it! The first cout will print 0, the second will print 5, and the third will print 10. I'll double-check my work, but I'm feeling confident about this one.
upvoted 0 times
...
Ocie
27 days ago
I'm a bit confused by the nested blocks here. I'll need to make sure I understand how variable scope works in C++ to solve this one.
upvoted 0 times
...
Barrett
1 month ago
Okay, let me think this through step-by-step. There are three blocks of code, each with a different value for the variable 'i'. I'll need to pay attention to which 'i' is being used in each cout statement.
upvoted 0 times
...
Mozell
1 month ago
Hmm, this looks like a scope issue. I'll need to carefully trace the variable declarations and assignments to figure out the output.
upvoted 0 times
...

Save Cancel