Just curious if this would be correct?

string s1 = "Hi", s2 = "Hello", s3;
s3 = (s1 < s2) ? s1 : s2;
cout << s3;

1.)Write out what output this code generates.
2.)Name the operation on the second line of the fragment and explain how it operates.
3.)Rewrite the second line using either branching or looping
statements.

1.)Hello.
2.)I am not to sure do they want string as operation, or is s1, s2?
evaluates the value of s2, since s1 is less than s2 which = s3
3.) if ((s1 < s2) ? s1 : s2;)

Im studying for a test let me know if this sounds right or wrong thank you!
Second line is wrong- they just want to know that you know what the ? is (it's ternary, by the way)

Third line is also wrong-

1
2
3
4
5
if(s1 < s2)
    s3 = s1;
else
    s3 = s2;
cout << s3;
Makes sense!
Just a quick question you used branching correct?
Thanks!
Last edited on
Topic archived. No new replies allowed.