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 Exam CPA Topic 2 Question 92 Discussion

Actual exam question for C++ Institute's CPA - C++ Certified Associate Programmer exam
Question #: 92
Topic #: 2
[All CPA - C++ Certified Associate Programmer 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
1 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
1 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
1 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
1 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
Viva
15 days ago
User3: Oh, so that's why it only prints the last character 'o'.
upvoted 0 times
...
Flo
17 days ago
User2: It prints each character of the string until it reaches the null character.
upvoted 0 times
...
Layla
27 days ago
User1: It prints: o
upvoted 0 times
...
...
Willodean
1 months ago
I'm not sure, but I think the answer is C) It prints: H.
upvoted 0 times
...
Sueann
1 months ago
I believe the answer is A) It prints: el.
upvoted 0 times
...
Lauran
1 months ago
I think the answer is B) It prints: Hello.
upvoted 0 times
...
Alita
1 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
20 days 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
27 days ago
A) It prints: el
upvoted 0 times
...
...
Chandra
2 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
24 days ago
D) It prints: o
upvoted 0 times
...
Roselle
27 days ago
C) It prints: H
upvoted 0 times
...
Nana
1 months ago
B) It prints: Hello
upvoted 0 times
...
Teri
1 months ago
A) It prints: el
upvoted 0 times
...
...

Save Cancel