What will the variable "age" be in class B?
class A {
int x;
protected:
int y;
public:
int age;
A () { age=5; };
};
class B : public A {
string name;
public:
B () { name="Bob"; };
void Print() {
cout << name << age;
}
};
A. public
B. private
C. protected
D. None of these
What happens when you attempt to compile and run the following code? #include
using namespace std;
#define FUN(arg) if(arg) cout<<"Test";
int main()
{
int i=1;
FUN(i<3);
return 0;
}
A. It prints: 0
B. It prints: T
C. It prints: T0
D. It prints: Test
What will the variable "age" be in class B?
class A {
int x;
protected:
int y;
public:
int age;
};
class B : private A {
string name;
public:
void Print() {
cout << name << age;
}
};
A. public
B. private
C. protected
D. None of these
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class A
{
public:
virtual void Print(){ cout<<"A";}
};
class B:public A
{
public:
void Print(){ cout<< "B";}
};
int main()
{
A *obj;
A ob1;
obj = andob1;
obj?>Print();
B ob2;
obj = andob2;
obj?>Print();
}
A. It prints: AB
B. It prints: AA
C. It prints: BA
D. It prints: BB
What is the output of the program if character 4 is supplied as input?
#include
using namespace std;
int main () {
int c;
cin >> c;
try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
case 3:
throw 'a';
default:
cout<<"No exception";
}
}
catch (int e)
{ cout << "int exception. Exception Nr. " << e; }
catch (float e)
{ cout << "float exception. Exception Nr. " << e; }
catch (...)
{ cout << "An exception occurred."; }
return 0;
}
A. It prints: float exception. Exception Nr.
B. It prints: int exception. Exception Nr.
C. It prints: An exception occurred
D. It prints: No exception
Which of the following can be checked in a switch?case statement?
A. char
B. int
C. enum
D. double
What will happen when you attempt to compile and run the following code?
#include
using namespace std;
int getValue();
int main()
{
const int x = getValue();
cout< return 0; } int getValue() { return 5; } A. It will print 0 B. The code will not compile. C. It will print 5 D. It will print garbage value
Which of the following statements are correct?
A. A function can be defined inside another function
B. A function may have any number of return statements each returning different values.
C. A function can return floating point value
D. In a function two return statements should never occur.
What is the output of the program if characters 't', 'e', 's' and 't' enter are supplied as input?
#include
#include
using namespace std;
int main()
{
string s;
getline( cin, s );
cout << s << " " << s.length();
return( 0 );
}
A. It prints: test 4
B. It prints: test
C. It prints: test 5
D. It prints: 4
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main(){
int i = 1;
for(i=10; i>-1; i/=2) {
if(!i)
break;
}
cout << i;
return 0;
}
A. It prints: 0
B. It prints: 1
C. It prints: -1
D. Compilation error
How many times will "HELLO" be printed?
#include
using namespace std;
int main()
{
for(int i=?1; i<=10; i++)
{
if(i < 5)
continue;
else
break;
cout<<"HELLO";
}
return 0;
}
A. 1
B. 2
C. 0
D. 20
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int min(int a, int b);
int main()
{
int min(int,int);
int b;
b = min(10,20);
cout << b;
return 0;
}
int min(int a, int b)
{
return(b);
}
A. It prints: 20
B. It prints: 10
C. It prints: 1020
D. It prints: 2010
What is the output of the program given below?
#include
using namespace std;
int main (int argc, const char * argv[])
{
enum state { ok, error, warning};
enum state s1, s2, s3, s4;
s1 = ok;
s2 = warning;
s3 = error;
s4 = ok;
cout << s1<< s2<< s3<< s4;
return 0;
}
A. 1234
B. compilation fails
C. 0210
D. 1322
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class A {
protected:
int y;
public:
int x, z;
A() : x(1), y(2), z(0) {}
A(int a, int b) : x(a), y(b) { z = x * y;}
void Print() { cout << z; }
};
class B : public A {
public:
int y;
B() : A() {}
B(int a, int b) : A(a,b) {}
void Print() { cout << z; }
};
int main () {
A b(2,5);
A. Print(); return 0; }
B. It prints: 10
C. It prints: 2
D. It prints: 5
E. It prints: 1
Which of the following is a user defined data type?
1:
struct person
{
char name[20];
int age;
};
2:
int l=2;
3:
enum color {red,blue, green};
A.
char c;
B.
1
C.
2
D.
3
E.
4