- (10%) Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// True or False
#include <iostream>
int main()
{
int a = 0;
int b = 10;
if (b = a)
std::cout << "True \n";
else
std::cout << "False \n";
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Conditional Operator (P.103)
#include <iostream>
int main()
{
int i;
for (i=1; i<=12; i++)
std::cout << i << " - "
<< (i<8?(i%2?31:30):(i%2?30:31))
<< std::endl;
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// for-loop (P.110)
#include <iostream>
int main()
{
int i, sum;
for (i=3, sum=0; i<=100; i+=2)
sum += i;
std::cout << i << '\t' << sum << std::endl;
return 0;
}