9.5k views
4 votes
Suppose that ch1 and ch2 are char variables, and alpha is an int variable. The input is:

A 18
What are the values of ch1, ch2, and alpha after the following statement executes?

(ch1);
(ch2);
cin >> alpha;

User Ryan Chase
by
8.5k points

1 Answer

4 votes

Final answer:

With the input "A 18" and correct cin statements, ch1 would be 'A', ch2 would lack a value, and alpha would be 18. The given statement has a syntax error and thus cannot function as intended without proper input operations for ch1 and ch2.

Step-by-step explanation:

If ch1 and ch2 are char variables, and alpha is an int variable, and the input is "A 18" followed by the cin statements provided, there seems to be an error in the question since it lacks proper syntax to read the char variables. Assuming the intended cin statements are cin >> ch1 >> ch2 >> alpha;, then after these execute with the input of "A 18", the value of ch1 would be 'A', and ch2 would be read but won't have any value since there is no second char provided in the input. The alpha variable would correctly store the value 18. If the input should contain two characters before the integer, like "A B 18", ch1 would be 'A', ch2 would be 'B', and alpha would still be 18.

User Andrew Guenther
by
8.2k points