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

Answer : D

Explaination

C++ supports all the forms of inheritance.

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 - The following operator can be used to calculate the value of one number raised to another.

A - ^

B - **

C - ^^

D -None of the above

Answer : D

Explaination

There is no such operator in C/C++.

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 : A

Explaination

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 size of ‘int’?

A - 2

B - 4

C - 8

D - Compiler dependent

Answer : D

Explaination

The size of ‘int’ depends upon the complier i.e. whether it is a 16 bit or 32 bit.

Q 9 - An inline function can execute faster than a normal function.

A - True

B - False

Answer : A

Explaination

As the code of inline function gets expanded at the line of call, therefore it gets executed faster with no overhead of context switch

Q 10 - Does both the loops in the following programs prints the correct string length?

#include<iostream>

using namespace std;
main() {
   int i;
   
   char s[] = "hello";

   for(i=0; s[i]; ++i);
      cout<<i<<endl;

   i=0; 
   
   while(s[i++]);
      cout<<i;
}

A - Yes, both the loops prints the correct length

B - Only for loop prints the correct length

C - Only while loop prints the correct length

D - Compile error in the program.

Answer : B

Explaination

In while loop 'i' gets incremented after checking for '\0', hence giving 1 more than the length.

#include<iostream>

using namespace std;
main() {
   int i;
   
   char s[] = "hello";

   for(i=0; s[i]; ++i);
      cout<<i<<endl;

   i=0;
   
   while(s[i++]);
      cout<<i;
}

cpp_questions_answers.htm

Advertisements