C++ Online Quiz


Advertisements


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 - A trigraph character begins with

A - #

B - ##

C - ?

D - ??

Answer : C

Explaination

Few characters have alternative representation and start with ??. Eg. Fro [ equivalent is ??(

Q 2 - A user defined header file is included by following statement in general.

A - #include “file.h”

B - #include <file.h>

C - #include <file>

D - #include file.h

Answer : A

Explaination

With the syntax as in (a) the compiler first looks for the file in the present working directory and then in the default include path if not found.

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

#include<iostream>

using namespace std;
main() { 

   int i = 1, j = 2, k = 3, r; 

   r = (i, j, k);

   cout<<r<<endl;

}

A - 1

B - 2

C - 3

D - Compile Error

Answer : C

Explaination

Comma is called as the separator operator and the associativity is from left to right. Therefore ‘k’ is the expressions resultant.

#include<iostream>

using namespace std;
main() { 

   int i = 1, j = 2, k = 3, r; 

   r = (i, j, k);

   cout<<r<<endl;

}

Q 4 - Choose the Object oriented programming language from below.

A - C++

B - Small talk

C - Simula

D - All the above.

Answer : D

Explaination

Answer : D

Explaination

Options (a), (b) & (c) are applicable.

Answer : C

Explaination

A constructor can’t be overridden.

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

#include<iostream>

using namespace std;
main() {
   char s[] = "hello", t[] = "hello";
   if(s==t)
      cout<<"eqaul strings";
}

A - Equal strings

B - Unequal strings

C - No output

D - Compilation error

Answer : C

Explaination

No output, as we are comparing both base addresses and are not same.

#include<iostream>

using namespace std;
main() {
   char s[] = "hello", t[] = "hello";
   if(s==t)
      cout<<"eqaul strings";
}

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

#include<iostream>

using namespace std;
main() { 
   int a[] = {1, 2}, *p = a;
   
   cout<<p[1]; 
}

A - 1

B - 2

C - Compile error

D - Runtime error

Answer : B

Explaination

as ‘p’ holds the base address then we can access array using ‘p’ just like with ‘a’

#include<iostream>

using namespace std;
main() { 
   int a[] = {1, 2}, *p = a;
   
   cout<<p[1]; 
}

Q 9 - Following is the invalid inclusion of a file to the current program. Identify it

A - #include <file>

B - #include "file"

C - #include < file

D - All of the above are invalid

Answer : C

Explaination

option (a) & (b) are valid. There is no such syntax or provision as in option (c).

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

#include<iostream>

using namespace std;
void main() {
   char *s = "C++";
   
	cout<<s<<" ";
	s++;
	cout<<s<<" ";
}

A - C++ C++

B - C++ ++

C - ++ ++

D - Compile error

Answer : B

Explaination

After s++, s points the string “++”.

#include<iostream>

using namespace std;
void main() {
   char *s = "C++";
   
	cout<<s<<" ";
	s++;
	cout<<s<<" ";
}

cpp_questions_answers.htm

Advertisements