MCQ

C++ MCQ Questions and Answers – Part 2

Multiple choice questions and answers (MCQs) on C++ to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are taken from an interview. So you will find questions on basic techniques such as Variables, Operators, Conditional Statement, Functions, and more. This quiz will easily prepare anyone to pass their online test.
 

1. What is the output of the following C++ program?
#include <iostream>

using namespace std;

int main()
{
	cout << sizeof(char);
	cout << sizeof(int);
	cout << sizeof(float);
	return 0;
}

A 1 8 8

B 1 4 8

C 1 4 4

D Aucune de ces réponses n’est vraie.

C
For a character is 1 byte, for an integer is 4 bytes and for float is 4 bytes.
 

 

 

2. Which function is used to read a single character in the console in C++?

A scanf(c)

B read(c)

C getline(c)

D cin.get(c)

D
In C++, the cin.get() function reads a single character from the console.

 

 
 

3. Which function is used to write a single character to the console in C++?

A printf(c)

B write(c)

C cout.put(c)

D cout.putline(c)

C
In C++, the cout.put() function writes a single character to the console.

 

 

4. The size of an object or type can be determined with which operator?

A malloc

B sizeof

C malloc

D calloc

B
The sizeof operator gives the size of an object or type.

 

 

5. How many times does the “cout” in line 12 run?
#include <iostream> 

using namespace std; 
  
int main() 
{ 
    int n = 10; 
    for (int i = 0; i < n; i++ ) 
    { 
        n++; 
        continue; 
        cout << n; 
    } 
  
    return 1; 
}

A 10

B 11

C 1

D The “cout” never runs.

D
The “continue” instruction will never let the “cout” instruction be executed and therefore never executed.

 

 
 

6. Which of the following operators is called “Input Flow Operator”?

A <<

B >>

C >

D <

B
The >> operator is called “input flow operator”. It allow us to insert elements into the console or into a file. Example : cin >> age;

 

 

7. Which of the following operators is called “Output Flow Operator”?

A <<

B >>

C >

D <

A
The operator << is called the input stream operator, i.e. displaying elements in the console or in a file. cout << "Your age is : " << age;

 

 

8. A language able to generate new data types is called _________

A overloaded

B extensible

C encapsulated

D scalable

B
Languages that can generate new data types are called extensible languages because they can handle new data types.

 

 

9. What is the output of the following C++ code?
#include <iostream>

using namespace std;
  
int main()
{ 
    int n = 5, i;

    for (i = 0; i < n; i++)
    {
        n++;
        cout << n << endl;
        goto a;
    }

a: 
    do
    {
        cout << "label a" << endl; 
        break; 
    } 
    while( 0 );

    return 1;
}

A 5 label a

B 5

C label a

D 6
label a

D
This program is executed normally by entering the for loop and on the first iteration the control jumps to the label (label a). You have to be careful when using the goto statement because it could turn the program into an infinite loop. For example, in the above program, if we keep the for loop after the label, it will turn into an infinite iteration.
 

 

 

10. The size of objects in C++ is expressed in terms of multiples of ____ size and the size of a “char” is _______

A char, 4

B int, 1

C char, 1

D float, 8

C
Each object in C++ is expressed in terms of multiples of char size and the char size is one byte.

 

 
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *