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

Answer : A

Explaination

As inline function gets expanded at the line of call like a macro it executes faster.

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;

}

Answer : D

Explaination

Q 5 - Which operator is used to resolve the scope of the global variable?

A - −>

B - .

C - *

D - ::

Answer : D

Explaination

Scope resolution operator is used to resolve for the global scope of a variable if the local and global variables conflict by name.

Q 6 - A C++ program statements can be commented using

A - Single line comment

B - Multi line comment

C - Either (a) or (b)

D - Both (a) and (b).

Answer : D

Explaination

Both styles of commenting is available in C++.

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

#include<iostream>

using namespace std;
void f() {
   cout<<"Hello"<<endl;
}
main() {
}

A - No output

B - Error, as the function is not called.

C - Error, as the function is defined without its declaration

D - Error, as the main() function is left empty

Answer : A

Explaination

No output, apart from the option (a) rest of the comments against the options are invalid

#include<iostream>

using namespace std;
void f() {
	cout<<"Hello"<<endl;
}
main() 
{
}

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

#include<iostream>

using namespace std;
main() { 
   int i = 13, j = 60;
   
   i^=j;
   j^=i;
   i^=j;
   cout<<i<<" "<<j;
}

A - 73 73

B - 60 13

C - 13 60

D - 60 60

Answer : B

Explaination

60 13, its swapping.

#include<iostream>

using namespace std;
main() { 
   int i = 13, j = 60;
   
   i^=j;
   j^=i;
   i^=j;
   cout<<i<<" "<<j;
}

Q 9 - Identify the C++ compiler of Linux

A - cpp

B - g++

C - Borland

D - vc++

Answer : B

Explaination

g++ is GNU C++ compiler for linux. Borland and vc++ (Microsoft visual c++) for windows.

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

#include<iostream>
#include<string.h>

using namespace std;
main() { 
   char s[] = "Hello\0Hi";
   
   cout<<strlen(s)<<" "<<sizeof(s);
}

A - 5 9

B - 7 20

C - 5 20

D - 8 20

Answer : A

Explaination

Length of the string is count of character upto ‘\0’. sizeof – reports the size of the array.

#include<iostream>
#include<string.h>

using namespace std;
main() { 
   char s[] = "Hello\0Hi";
   
   cout<<strlen(s)<<" "<<sizeof(s);
}
cpp_questions_answers.htm
Advertisements