Can someone please help me with this midterm questions? All the answers should b
ID: 3862230 • Letter: C
Question
Can someone please help me with this midterm questions? All the answers should be related to C++ language. Thank you is advance.
1)
After this statement is executed, what value does answer hold?
double answer = 6/12;
a) 0 b) .20 c) .50 d) 2
2)
What statement most accurately describes the output of this loop?
for (int i = 2; i < 99; i++)
{
if (i % 2 == 0)
cout << i << " ";
}
a) all of the even numbers between 2 and 99 b) all of the even numbers between 2 and 98
3)
int val;
if (val)
{
...
}
Which of the following values could be assigned to the variable val and result in the body of the if statement being executed?
a) 1 b) 66 c) -2 d) -1 e) all of the above
4)
What data type allows you to directly store the results of comparisons?
For example, you want to store the result of the expression x < 100.
Explanation / Answer
Answers:
1.c) .50 ,Reason:6/12 divides 6 by 12 till 2 decimal point
2.a) all of the even numbers between 2 and 99 ,Reason:if a number is divisible by 2 i.e a even number
3.a) 1 ,Reason:if statement will execute if the expression is true i.e 1
4.boolean data type
Note:please ask in case of any doubt,thanks.