Which of the following contains at least one error errors th
Which of the following contain(s) at least one error (errors that are caught by the compile and/or errors that cause the program to perform in ways that the programmer does not intend)? Assume all the variables are defined and initialized. Select all that apply. a. if(x = 0) x = MAXINT; b. if x > 0 x = 3; c. if (x > 0) x = 3; else x = 4; d. for(int i = 0; i <10; i++); sum = sum +x;
Solution
a. if(x = 0)
x = MAXINT;
b. if x > 0
x = 3;
c. if (x > 0)
x = 3;
else
x = 4;
d.
for(int i = 0; i <10; i++);
sum = sum +x;
I am ssuming these are the C++ programming code:
a)
There is no compiler error, but in IF statement, we generally have CONDITIONAL expression, but here we have x =0 that is
assignment statement, it will assign 0 to x and then expression (x=0) evaluates to false
b)
Compiler error : condition x > 0 should be in parenthesis => if(x > 0)
c)
No Error
d)
No Error
