Assume we have strings as follows string str1 123 string st

Assume we have strings as follows: string str1 = \"123\"; string str2(\"456\");

(1) What are output from following cout statements? (4 points)

cout << str1 + str2 << endl;

cout << str2 + str1 << endl;

(2) Explain your outcome in less than 100 words. (6 points)

Solution

Question 1:

Answer:

This statement cout << str1 + str2 << endl; will print \"123456\"

This statement cout << str2 + str1 << endl; will print \"456123\"

Question 2:

Answer:

Using this statement string str1 = \"123\"; , we are declaring and initialling str1 string object with the value \"123\". So str1 object value is \"123\"

Using this statement string str2(\"456\") , we are declaring and initialling str2 string object with the value \"456\". So str2 object value is \"456\"

we can declare and initialze the string object in both the ways mentioned above.

when we write this statement str1 + str2, str1 and str2 objects will be concatenated and will print \"123456\"

when we write this statement str2 + str1, str2 and str1 objects will be concatenated and will print \"456123\"

Assume we have strings as follows: string str1 = \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site