CPA-21-02 practice question 10 of 35
What happens when you attempt to compile and run the following code? #include #include using namespace std; class A { public: string s; A(string s) { this?>s = s; } }; class B { public: string s; B (A a) { this?>s = a.s; } void print() { cout
Full set: 257 questionsThe provided code contains a syntax error. The character sequence ?> in the expressions this?>s = s; and this?>s = a.s; is not a valid C++ operator. The correct member access operator through a pointer is ->. Because of this invalid syntax, the compiler will fail to parse the code, resulting in a compilation error. Even if this was intended to be a typographical error for ->, the code must be evaluated exactly as written, which makes it uncompilable.
A: The code will not compile to print "Hello world" due to the invalid ?> syntax. B: The code will not compile, and there is no logic that would truncate the string to "Hello". D: Option C is the correct choice because a compilation error definitively occurs.
- ISO/IEC 14882:2017 (C++17 Standard), Section 5.4 [lex.operators], Table 12.
- Stroustrup, B. (2013). The C++ Programming Language (4th Ed.). Addison-Wesley. Chapter 10.
Keep practicing
Take the free CPA-21-02 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other CPA-21-02 practice questions
- Question 1What happens when you attempt to compile and run the following code? #include using names…
- Question 2What happens when you attempt to compile and run the following code? #include #include us…
- Question 3Which of the following statements are correct about an array? int tab[10];
- Question 4What happens when you attempt to compile and run the following code? #include #include us…
- Question 5What is the output of the program if characters 'h', 'e', 'l', 'l' , 'o' and enter are su…
- Question 6What happens when you attempt to compile and run the following code? #include using names…
