Suppose that score is an int variable. Consider the following if statements: i.
ID: 639965 • Letter: S
Question
Suppose that score is an int variable. Consider the following if statements: i. if (score == 70) cout << "Grade is C." << endl; ii. if (score = 70) cout << "Grade is C." << endl;
If the value of score is 70: What is the output in (i)? What is the value of score after the if statement in (i) executes? What is the output in (ii)? What is the value of score after the if statement in (ii) executes? If the value of score is 80: What is the output in (i)? What is the value of score after the if statement in (i) executes? What is the output in (ii)? What is the value of score after the if statement in (ii) executes?
Explanation / Answer
a
in (i) '==' is used for conditional check. It is conditional check statement if condition is satisfied then goes inside if.
Since score = 70 condition satisfied it goes inside if and prints
Value of score remains unchanged (i.e. score = 70 ) after execution of (i)
for (ii)
'=' sign is used for assign not condition check. value of 70 is assigned to score and returns 1 to if thus is treats as condition satisfied and goes inside if and prints
Value of score is changed to 70 after execution of (ii).
b
if conditon not satisfied in (i). Thus (i) doesnt print anything.
Value of score remains unchanged (i.e. score = 80 ) after execution of (i)
for (ii)
for (ii)
'=' sign is used for assign not condition check. value of 70 is assigned to score and returns 1 to if thus is treats as condition satisfied and goes inside if and prints
Value of score is changed to 70 after execution of (ii).
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.