43.4k views
3 votes
Which statement allows you to properly check the char variable code to determine whether

it is equal to a C and then output This is a check?
a. if code is equal to C

cout << "This is a check\\";

b. if (code = "C")

cout << "This is a check\\";

c. if (code == 'C')

cout << "This is a check\\";

d. if (code == C)

cout << "This is a check" << endl;

1 Answer

6 votes

Final answer:

The correct way to check if a char variable 'code' is equal to 'C' is using option c with the equality operator '==' and single quotes around 'C'.

Step-by-step explanation:

To check the char variable code to determine whether it is equal to 'C' and then output 'This is a check', you need to use the comparison operator '=='. The correct statement is:

if (code == 'C')
cout << "This is a check" << endl;

Option c is the correct answer because '==' is the equality operator and 'C' must be enclosed in single quotes to indicate that it is a character literal.

User Arlo Guthrie
by
9.2k points