BlackFriday 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
4 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
4 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
4 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
4 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
2 months ago
Oh, I see. So as the pointer moves to the next character, it prints 'o'.
upvoted 0 times
...
Casey
2 months ago
Because the pointer s is pointing to the last character in the string 'Hello'.
upvoted 0 times
...
Gerald
2 months ago
It prints: o
upvoted 0 times
...
Viva
3 months ago
Oh, so that's why it only prints the last character 'o'.
upvoted 0 times
...
Flo
3 months ago
It prints each character of the string until it reaches the null character.
upvoted 0 times
...
Layla
3 months ago
It prints: o
upvoted 0 times
...
...
Willodean
4 months ago
I'm not sure, but I think the answer is C) It prints: H.
upvoted 0 times
...
Sueann
4 months ago
I believe the answer is A) It prints: el.
upvoted 0 times
...
Lauran
4 months ago
I think the answer is B) It prints: Hello.
upvoted 0 times
...
Alita
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
Ilona
3 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
3 months ago
A) It prints: el
upvoted 0 times
...
...
Chandra
4 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
3 months ago
D) It prints: o
upvoted 0 times
...
Roselle
3 months ago
C) It prints: H
upvoted 0 times
...
Nana
4 months ago
B) It prints: Hello
upvoted 0 times
...
Teri
4 months ago
A) It prints: el
upvoted 0 times
...
...

Save Cancel