Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

C++ Online Quiz



Following quiz provides Multiple Choice Questions (MCQs) related to C++ Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - The default access specifer for the class members is

A - public

B - private

C - protected

D - None of the above.

Answer : B

Explaination

If a member/s appear in the class with following no access specifier, the default is private.

Q 2 - From the below class choose the proper definition of the member function f().

template <class T>

class abc {
   void f();
};

A - template <class T>

    void abc<T>::f() { }

B - template<class T>

    void abc::f() { }

C - template<T>

    void abc<class T>::f() { }

D - template<T>

    void abc<T>::f() { }

Answer : A

Explaination

Q 3 - We can have varying number of arguments for the overloaded form of () operator.

A - True

B - False

Answer : A

Explaination

Q 5 - What is the output of the following program?

#include<iostream>

using namespace std;
class Base {
public:
   void f() {
      cout<<"Base\n";
   }
};
class Derived:public Base {
public:
   void f() {
      cout<<"Derived\n";
   }
};
main() { 
   Derived obj; 
   obj.Base::f();
}

A - Base

B - Derived

C - Compile error

D - None of the above.

Answer : A

Explaination

The method f() inherited from Base is referred using :: operator.

#include<iostream>

using namespace std;
class Base {
public:
   void f() {
      cout<<"Base\n";
   }
};
class Derived:public Base {
public:
   void f() {
      cout<<"Derived\n";
   }
};
main() { 
   Derived obj; 
   obj.Base::f();
}

Q 6 - Which type of data file is analogous to an audio cassette tape?

A - Random access file

B - Sequential access file

C - Binary file

D - Source code file

Answer : B

Explaination

As the access is linear.

Q 7 - What is the output of the following program?

#include<iostream>

using namespace std;
void f() { 
   static int i; 
   
   ++i; 
   cout<<i<<" "; 
}

main() { 
   f(); 
   f(); 
   f(); 
}

A - 1 1 1

B - 0 0 0

C - 3 2 1

D - 1 2 3

Answer : D

Explaination

1 2 3, A static local variables retains its value between the function calls and the default value is 0.

#include<iostream>

using namespace std;
void f() { 
   static int i; 
   
   ++i; 
   cout<<i<<" "; 
}

main() { 
   f(); 
   f(); 
   f(); 
}

Q 8 - What is the output of the following program?

#include<iostream>

using namespace std;
void swap(int m, int n) {
   int x = m;

	m = n;
	n = x;
}
main() {
   int x = 5, y = 3;
   
	swap(x,y);
	cout<<x<<" "<<y;
}

A - 3 5

B - 5 3

C - 5 5

D - Compile error

Answer : B

Explaination

5 3, call by value mechanism cant alter actual arguments.

#include<iostream>

using namespace std;
void swap(int m, int n) {
   int x = m;

	m = n;
	n = x;
}
main() {
   int x = 5, y = 3;
   
	swap(x,y);
	cout<<x<<" "<<y;
}

Q 9 - Special symbol permitted with in the identifier name.

A - $

B - @

C - _

D - .

Answer : C

Explaination

The only permitted special symbol is under score (_) in the identifier.

Q 10 - What is the output of the following program?

#include<iostream>

using namespace std;
main() {	
   int a[] = {10, 20, 30};
   
	cout<<*a+1;
}

A - 10

B - 20

C - 11

D - 21

Answer : C

Explaination

*a refers to 10 and adding a 1 to it gives 11.

#include<iostream>

using namespace std;
main() {	
   int a[] = {10, 20, 30};
   
	cout<<*a+1;
}
cpp_questions_answers.htm
Advertisements