C++ Programming
This test focuses on fundamental & programming skill concepts in C++ programming
Questions
What is the output of C++ program given below?
#include<iostream>
using namespace std;
int main()
{
typedef int hello;
hello i=9.9;
cout<<i;
}
- 9
- 9.9
- 9.0
- Error in the program
- None of the above
What is the output of C++ program given below?
#include<iostream>
using namespace std;
int main()
{
int y=8,x=6;
(x=5)&&(x=7) ? y=1:y=2;
cout<<x<<"_"<<y;
}
Note: _ (underscore is used in cout statement to differentiate x & y value.
- 1_7
- 7_1
- 5_1
- 6_2
- None of the above
Which of the following statements is false regarding to namespace in C++ programming?
- C++ provides declaring an alias name for a given namespace.
- Namespace can be declared without any name or even unnamed.
- Namespace defination can be extended over multiple files.
- Instance variable can be created for a namespace.
- Namespace defination should not be terminated by a semicolon.
What is the output of C++ program given below?
#include<iostream>
using namespace std;
int main()
{
int i,j,k=5;
for(i=1;i<=5;i++)
{
for(j=1;j<=k;j++)
{
cout<<j;
}
k=k-1;
cout<<"n";
}
}
- 12345
12345
12345
12345
12345 - 12345
1234
123
12
1 - 1
12
123
1234
12345 - Error in the program
- None of the above
What is the output of C++ program given below?
#include<iostream>
using namespace std;
class Test
{
public:
Test()
{
cout<<"constructor of Testn";
}
~Test()
{
cout<<"destructor of Testn";
}
};
int main()
{
Test a;
Test b;
}
- constructor of Test
constructor of Test
destructor of Test
destructor of Test - constructor of Test
destructor of Test
constructor of Test
destructor of Test - constructor of Test
constructor of Test - constructor of Test
destructor of Test - None of the above
What is the output of C++ program given below?
#include<iostream>
using namespace std;
class A
{
public:
A()
{
cout<<"Constructor of A"<<endl;
}
void Test();
};
void A::Test()
{
cout<<"This is Test"<<endl;
}
int main()
{
A a;
a.Test();
}
- This is Test
- This is Test
Constructor of A - Constructor of A
This is Test - Error in the program
- None of the above
Which of the following statements is false regarding inline function in C++?
- All functions declared inside a class are inline functions by default.
- Inline functions can be declared outside a class by using inline keyword.
- Any modifications in an inline function needs recompilation of the program to use modified functionality.
- Declarartion of a function which is inside a class with inline keyword leads to compile time error.
- By declaring small functions (with less computation time) as inline function, performance of the program is increased.
What is the output of C++ program given below?
#include<iostream>
using namespace std;
class Parent1
{
public:
int a=10;
};
class Parent2
{
public:
int a=5;
};
class Child:public Parent1,public Parent2
{
public:
int func()
{
return a;
}
};
int main()
{
Child ch;
cout<<ch.func();
}
- 10
- 5
- 10
5 - Compile time error
- None of the above
What is the output of C++ program given below?
#include<iostream>
using namespace std;
class Parent
{
public:
void func()
{
cout<<"function of Parent"<<endl;
}
};
class Child:public Parent
{
public:
void func()
{
cout<<"function of Child"<<endl;
}
};
int main()
{
Child ch;
ch.func();
}
- function of Parent
- function of Child
- function of Child
function of Parent - function of Child
function of Parent - Error in the program
Choose the appropriate true statement among the given options with reference to C++ programming.
- Friend function of a class cannot access private members of the given class.
- It is not mandatory to have a pure virtual function(s) in an abstract class.
- We can create object for an abstract class.
- If a class inherits abstract class and doesn't implement pure virtual functions of base class, then derived class also becomes abstract class.
- None of the above
What is the output of C++ program given below?
#include<iostream>
using namespace std;
class Test
{
public:
int a=9;
void func()
{
cout<<aa;
}
};
class Hello:public Test
{
public:
void func(int x)
{
cout<<ax;
}
};
int main()
{
Hello obj;
obj.func(5);
}
- 81
- 45
- 25
- Error in the program
- None of the above
What is the output of C++ program given below?
#include<iostream>
using namespace std;
class Test
{
protected:
int a=10,b=5;
public:
virtual int func()=0;
};
class Imp:public Test
{
public:
int func()
{
int x=++a*b++;
return x;
}
};
int main()
{
Imp i;
cout<<i.func();
}
- 60
- 66
- 50
- 55
- Compile time error
What is the output of C++ program given below?
#include<iostream>
using namespace std;
class Test
{
public:
mutable int a; /line1/
Test() /line2/
{
a=10; /line3/
}
void func() const /line4/
{
a++; /line5/
cout<<a;
}
};
int main()
{
const Test obj;
obj.func();
}
- Error at line5
- Error at line4
- Error at line3
- 11
- Error at line1
Identify the type of inheritance used in the following C++ code snippet.
class A
{ };
class B:public A
{ };
class C:public A
{ };
class D:public A
{ };
- Multiple inheritance
- Single or simple inheritance
- Hierarchical inheritance
- Multilevel inheritance
- None of the above
What is the output of C++ program given below?
#include<iostream>
using namespace std;
class Parent
{
public:
int a=10,b=20;
};
class Middle:protected Parent
{
public:
Middle()
{
a++;
b--;
}
};
class Child:private Middle
{
public:
int hello()
{
return a*b;
}
};
int main()
{
Child ch;
cout<<ch.hello();
}
- 200
- 209
- 189
- Compile time error
- None of the above