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 CPA-21-02 Exam - Topic 3 Question 49 Discussion

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
C) 055
D) None of these
A) 1010
B) 101010

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
Carlota
22 days ago
I thought it would print 10 at some point.
upvoted 0 times
...
Freeman
27 days ago
Wait, why does it print 0 first?
upvoted 0 times
...
Maddie
1 month ago
Totally agree, that's how scope works!
upvoted 0 times
...
Flo
1 month ago
The output will be 05.
upvoted 0 times
...
Jeff
1 month ago
Haha, this question is like a rite of passage for any C++ programmer. The output is a classic!
upvoted 0 times
...
Suzan
2 months ago
Wait, what? How can the output be 0 5 10? I'm so confused, someone please help!
upvoted 0 times
...
Aretha
2 months ago
Hmm, I thought the output would be 0 10 10. This C++ scoping thing is tricky.
upvoted 0 times
...
Nichelle
2 months ago
Ah, the good old scope resolution! The output is spot on.
upvoted 0 times
...
Audra
2 months ago
The inner block overrides the outer block's variable, so the output is 0 5 10.
upvoted 0 times
...
Hyun
2 months ago
The output is 0 5 10.
upvoted 0 times
...
Micah
2 months ago
I believe it prints 0, then 5, and finally 10. I just hope I got the scoping right!
upvoted 0 times
...
Marg
3 months ago
I’m a bit confused about the order of outputs. I practiced a question like this, but I can't recall the exact details.
upvoted 0 times
...
Torie
3 months ago
I remember something similar where inner scopes shadowed outer variables. So maybe it prints 0 first?
upvoted 0 times
...
Isabelle
4 months 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
4 months 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
4 months 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
4 months 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
4 months 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
4 months 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