C++ Programming

This test focuses on fundamental & programming skill concepts in C++ programming

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

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;
}

  1. 9
  2. 9.9
  3. 9.0
  4. Error in the program
  5. None of the above
Question 2 Multiple Choice (Single Answer)

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. 1_7
  2. 7_1
  3. 5_1
  4. 6_2
  5. None of the above
Question 3 Multiple Choice (Single Answer)

Which of the following statements is false regarding to namespace in C++ programming?

  1. C++ provides declaring an alias name for a given namespace.
  2. Namespace can be declared without any name or even unnamed.
  3. Namespace defination can be extended over multiple files.
  4. Instance variable can be created for a namespace.
  5. Namespace defination should not be terminated by a semicolon.
Question 4 Multiple Choice (Single Answer)

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";
}
}

  1. 12345
    12345
    12345
    12345
    12345
  2. 12345
    1234
    123
    12
    1
  3. 1
    12
    123
    1234
    12345
  4. Error in the program
  5. None of the above
Question 5 Multiple Choice (Single Answer)

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;
}

  1. constructor of Test
    constructor of Test
    destructor of Test
    destructor of Test
  2. constructor of Test
    destructor of Test
    constructor of Test
    destructor of Test
  3. constructor of Test
    constructor of Test
  4. constructor of Test
    destructor of Test
  5. None of the above
Question 6 Multiple Choice (Single Answer)

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();
}

  1. This is Test
  2. This is Test
    Constructor of A
  3. Constructor of A
    This is Test
  4. Error in the program
  5. None of the above
Question 7 Multiple Choice (Single Answer)

Which of the following statements is false regarding inline function in C++?

  1. All functions declared inside a class are inline functions by default.
  2. Inline functions can be declared outside a class by using inline keyword.
  3. Any modifications in an inline function needs recompilation of the program to use modified functionality.
  4. Declarartion of a function which is inside a class with inline keyword leads to compile time error.
  5. By declaring small functions (with less computation time) as inline function, performance of the program is increased.
Question 8 Multiple Choice (Single Answer)

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();
}

  1. 10
  2. 5
  3. 10
    5
  4. Compile time error
  5. None of the above
Question 9 Multiple Choice (Single Answer)

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();
}

  1. function of Parent
  2. function of Child
  3. function of Child
    function of Parent
  4. function of Child
    function of Parent
  5. Error in the program
Question 10 Multiple Choice (Single Answer)

Choose the appropriate true statement among the given options with reference to C++ programming.

  1. Friend function of a class cannot access private members of the given class.
  2. It is not mandatory to have a pure virtual function(s) in an abstract class.
  3. We can create object for an abstract class.
  4. If a class inherits abstract class and doesn't implement pure virtual functions of base class, then derived class also becomes abstract class.
  5. None of the above
Question 11 Multiple Choice (Single Answer)

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<<a
x;
}
};
int main()
{
Hello obj;
obj.func(5);
}

  1. 81
  2. 45
  3. 25
  4. Error in the program
  5. None of the above
Question 12 Multiple Choice (Single Answer)

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();
}

  1. 60
  2. 66
  3. 50
  4. 55
  5. Compile time error
Question 13 Multiple Choice (Single Answer)

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();
}

  1. Error at line5
  2. Error at line4
  3. Error at line3
  4. 11
  5. Error at line1
Question 14 Multiple Choice (Single Answer)

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
{ };

  1. Multiple inheritance
  2. Single or simple inheritance
  3. Hierarchical inheritance
  4. Multilevel inheritance
  5. None of the above
Question 15 Multiple Choice (Single Answer)

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();
}

  1. 200
  2. 209
  3. 189
  4. Compile time error
  5. None of the above