Workbook Pointer
Workbook Pointer
Write the output of the given C++ code segments. Please note there are no syntax errors in the
given set of codes. And all the code snippet contains #include<iostream> and using namespace
std;
Code Output
(A) (2 Mark) What would be the output produced by executing the following C++ code?
float Mystery(int y, int x){ 16.5
return (y + x + 7.0 / 2);
}
int main(){
float i = 9.5;
int j = 4;
cout << Mystery(i, j) << endl;
return 0;
}
(B)(2 Mark) What would be the output produced by executing the following C++ code?
int main() ABCDEF
{
int i = 65;
for (char ch = i; ch <= 70; ++ch)
cout << ch << " ";
return 0;
}
(C) (2 Mark) What would be the output produced by executing the following C++ code?
int fun(int x){ 4-3
return x % 3 + 1;
}
int main()
{
int b = 5;
int y = 2 + fun(3 * b + 1);
int z = fun(fun(y));
cout << y << "-" << z;
return 0;
}
(D) (4 Mark) What would be the output produced by executing the following C++ code?
void PRINT(int i,int limit)
{
do
{
if (i++ < limit)
{
cout<<"MID"<<i;
continue;
}
}while(i==limit);
}
int main()
{
int i = 1;
PRINT(i, 3);
return 0;
}
MID2
(E) (4 Mark) What would be the output produced by executing the following C++ code?
int main(){ 3-3-5-9-
int x, y = 4;
for (x = 2; x < y; x++)
y = y - 1 % x;
cout << y << "-";
x = 4;
do{
cout << --x << "-";
x *= 2;
} while (x <= 10);
return 0;}
(F) (3 Mark) What would be the output produced by executing the following C++ code?
int main(){ 40
int i, j, sum = 10;
for (i = 0; i<5; i++)
if (i % 2)
for (j = 0; j <= 3; sum += j, j++);
else
for (j = 3; j>0; sum += j, j--);
cout << sum;
}
(G)(2 Mark) What would be the output produced by executing the following C++ code?
int main(){ 2
int y = 0;
switch (y){
case 0: y = y + 11;
case 1: y = y / 2;
case 2: y = y * 5;
case 3: y = y + 1;
default: y = y%3;
}
cout << y << endl;
return 0;
}