Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

20. What is the output of the following code? int s = 1, n = 1; while (s < 10) {

ID: 656407 • Letter: 2

Question

20. What is the output of the following code?

int s = 1, n = 1;

while (s < 10) {

}

++n;

s += n;

cout << s << ' ';

a.2 4 7 11 d. 3 6 9

b.3 6 10 e. 1 2 3 4 5 6 7 8 9

c.2 3 4 5 6 7 8 9 f. 10

For questions 22 and 23, assume two string variables, s1and s2are initialized as follows:

string s1 = "zelda", s2 = "link";

21. If string s3 = s1 + s2;what is the value of the expression s3.find("ali")?

a.4 d. 5

b.'a' e. string::npos

c.'k' f. Runtime Error

22. What is the result of the expression s2.at(s1.find("a"));

a.4 d. 5

b.'a' e. string::npos

c.'k' f. Runtime Error

Explanation / Answer

20. It contains an infinite loop .

the loop

while (s < 10) {

}

never terminates as the initial value of s is <10 and after entering the loop no change to the value of s is occuring.

21. answer is 4

22. answer is f.runtime error as s1.find("a") = 4 and there is no fifth element (i.e lenght of s2 is 4 and s2[4] accesses 5th element)