Cyber Monday 2024! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPA Topic 2 Question 92 Discussion

Actual exam question for C++ Institute's CPA exam
Question #: 92
Topic #: 2
[All CPA Questions]

What happens when you attempt to compile and run the following code?

#include

using namespace std;

int main()

{

const char *s;

char str[] = "Hello";

s = str;

while(*s) {

cout << *s++;

}

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

Karl
5 months ago
This code is as straightforward as a game of tic-tac-toe. If you can't get this right, you might as well become a professional cat juggler.
upvoted 0 times
...
Monroe
5 months ago
A) It prints: el. Hmm, this is an interesting one. I wonder if the code is doing some kind of substring operation that I'm not aware of.
upvoted 0 times
...
Ma
5 months ago
I think the answer is A) It prints: el because the while loop will iterate through each character in the string 'Hello'.
upvoted 0 times
...
Lashaun
5 months ago
D) It prints: o. Wait, what? Why would it print just the last character? I must be missing something here.
upvoted 0 times
Alita
3 months ago
Oh, I see. So as the pointer moves to the next character, it prints 'o'.
upvoted 0 times
...
Casey
3 months ago
Because the pointer s is pointing to the last character in the string 'Hello'.
upvoted 0 times
...
Gerald
3 months ago
It prints: o
upvoted 0 times
...
Viva
4 months ago
Oh, so that's why it only prints the last character 'o'.
upvoted 0 times
...
Flo
4 months ago
It prints each character of the string until it reaches the null character.
upvoted 0 times
...
Layla
4 months ago
It prints: o
upvoted 0 times
...
...
Willodean
5 months ago
I'm not sure, but I think the answer is C) It prints: H.
upvoted 0 times
...
Sueann
5 months ago
I believe the answer is A) It prints: el.
upvoted 0 times
...
Lauran
5 months ago
I think the answer is B) It prints: Hello.
upvoted 0 times
...
Alita
5 months ago
C) It prints: H. I think this is a trick question, and the code actually only prints the first character of the string.
upvoted 0 times
Ilona
4 months ago
C) It prints: H. I think this is a trick question, and the code actually only prints the first character of the string.
upvoted 0 times
...
Meaghan
4 months ago
A) It prints: el
upvoted 0 times
...
...
Chandra
5 months ago
B) It prints: Hello. This is the correct answer, as the code simply prints the contents of the string str, which is 'Hello'.
upvoted 0 times
Janella
4 months ago
D) It prints: o
upvoted 0 times
...
Roselle
4 months ago
C) It prints: H
upvoted 0 times
...
Nana
5 months ago
B) It prints: Hello
upvoted 0 times
...
Teri
5 months ago
A) It prints: el
upvoted 0 times
...
...

Save Cancel