Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

April 3, 2018, 8:38 What is incorrect about the statements below? O Change the v

ID: 3699873 • Letter: A

Question



April 3, 2018, 8:38 What is incorrect about the statements below? O Change the vatue of x to 2 O Initializes x with the value 1 O Assign y the value 2: O The +is a postfox operator. QUESTION 12 Which control construct repeats a sequence of statements zero or more times? O while statoment O switch O t-else statement O do -while statement QUESTION 13 Which of the following control structures requires curly braces? O while O switch QUESTION 14 What is the output of the foilowing, t it were embedded in an otherwise comect and complete program and run? while (x >0, eoat ee The compiler deteets that this will be an infinite loop, so it docs not compile 3333 Gnfinite loop) O 10 13 16 19.. Gnfinite loop) ytHi..

Explanation / Answer

Answer : Incorrect statement is

Assign y the value 2;

Explanation: because as given y = x++; that is postfix imcremet operator.

y = x++ works in two steps: a) y = x b) x=x+1

Thus we can see that y will be assigned with the value 1 and x will get incremented by 1.

Answer 12: while statement

Explanation: Because while loop will repeat statments either zero or more times, as condition is evaluated first before entering the loop, if the condition is true then code will get executed, otherwise not.

Answer 13: switch

Answer 14: 10 13 16 19......(infinite loop)

It goes in infinite loop because value of x is get incremented by one each time and condition is checked x > 0 so, condition will become always true.

If we want to run the loop finite time that change the statement as x = x-3.

Correct code that will be run as follows:

int x=10;
while(x>0)
{
cout <<x<<" ";
x = x-3;
}
cout<<endl;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote