Q121
Open questionSelect an option to see the answer and solution.
Practice every MCQ with options. Use Show answers when you want the correct option and solution.
176
Questions
7/9
Page
Pick an option on a question to see the right answer and solution.
Q121
Open questionSelect an option to see the answer and solution.
Q122
Open question#include<iostream>
using namespace std;
class Test
{
protected:
int x;
public:
Test (int i):x(i) { }
void fun() const { cout << "fun() const " << endl; }
void fun() { cout << "fun() " << endl; }
};
int main()
{
Test t1 (10);
const Test t2 (20);
t1.fun();
t2.fun();
return 0;
}Select an option to see the answer and solution.
Q123
Open question#include <iostream>
#include <stdarg.h>
using namespace std;
float avg( int Count, ... )
{
va_list Numbers;
va_start(Numbers, Count);
int Sum = 0;
for (int i = 0; i < Count; ++i )
Sum += va_arg(Numbers, int);
va_end(Numbers);
return (Sum/Count);
}
int main()
{
float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
cout << "Average of first 10 whole numbers : " << Average;
return 0;
}Select an option to see the answer and solution.
Q124
Open questionSelect an option to see the answer and solution.
Q125
Open question#include<iostream>
using namespace std;
int fun(int x = 0, int y = 0, int z)
{ return (x + y + z); }
int main()
{
cout << fun(10);
return 0;
}Select an option to see the answer and solution.
Q126
Open question#include <iostream>
using namespace std;
int main ()
{
cout << "Value of __LINE__ : " << __LINE__ << endl;
cout << "Value of __FILE__ : " << __FILE__ << endl;
cout << "Value of __DATE__ : " << __DATE__ << endl;
cout << "Value of __TIME__ : " << __TIME__ << endl;
return 0;
}Select an option to see the answer and solution.
Q127
Open questionSelect an option to see the answer and solution.
Q128
Open question#include <iostream>
using namespace std;
void copy (int& a, int& b, int& c)
{
a *= 2;
b *= 2;
c *= 2;
}
int main ()
{
int x = 1, y = 3, z = 7;
copy (x, y, z);
cout << "x =" << x << ", y =" << y << ", z =" << z;
return 0;
}Select an option to see the answer and solution.
Q129
Open question#include <iostream>
using namespace std;
void square (int *x, int *y)
{
*x = (*x) * --(*y);
}
int main ( )
{
int number = 30;
square(&number, &number);
cout << number;
return 0;
}Select an option to see the answer and solution.
Q130
Open questionSelect an option to see the answer and solution.
Q131
Open question#include <iostream>
#include <string>
using namespace std;
string askNumber(string prompt = "Please enter a number: ");
int main()
{
string number = askNumber();
cout << "Here is your number: " << number;
return 0;
}
string askNumber(string prompt)
{
string number;
cout << prompt;
cin << number;
return number;
}Select an option to see the answer and solution.
Q132
Open questionSelect an option to see the answer and solution.
Q133
Open question#include <iostream>
using namespace std;
int add(int a, int b);
int main()
{
int i = 5, j = 6;
cout << add(i, j) << endl;
return 0;
}
int add(int a, int b )
{
int sum = a + b;
a = 7;
return a + b;
}Select an option to see the answer and solution.
Q134
Open question#include <iostream>
using namespace std;
int max(int a, int b )
{
return ( a > b ? a : b );
}
int main()
{
int i = 5;
int j = 7;
cout << max(i, j );
return 0;
}Select an option to see the answer and solution.
Q135
Open questionSelect an option to see the answer and solution.
Q136
Open questionSelect an option to see the answer and solution.
Q137
Open question#include <iostream>
using namespace std;
void PrintSequence(int StopNum)
{
int Num;
Num = 1;
while (true)
{
if (Num >= StopNum)
throw Num;
cout << Num;
Num++;
}
}
int main(void)
{
try
{
PrintSequence(20);
}
catch(int ExNum)
{
cout << "Caught an exception with value: " << ExNum;
}
return 0;
}Select an option to see the answer and solution.
Q138
Open questionSelect an option to see the answer and solution.
Q139
Open questionSelect an option to see the answer and solution.
Q140
Open question#include <iostream>
using namespace std;
void fun(int &x)
{
x = 20;
}
int main()
{
int x = 10;
fun(x);
cout << "New value of x is " << x;
return 0;
}Select an option to see the answer and solution.