This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1In C++ programming language, cout is a
Option B
In C++, cout is an predefine object of the output stream class (ostream) defined in the header file iostream.
#include<iostream>
using namespace std;
int main()
{
cout<<"Suraku Academy";
return 0;
}
Q: 2The cout in C++ stands for
Option B
The cout is a predefined object in C++ from the iostream library used for console output. Generally the name cout is breaks down as, "c" for character (handles character streams) and "out" for output. It works with the insertion or put to operator << to print data.
Q: 3In C++, to create alias for previously defined variable, we use.
Option B
In C++, an alias means another name for an already existing variable. This is done using a reference variable.
Syntax:
Data_type &Reference_Name= Referent;

Q: 4If a semicolon is not used at the end of the statement, what message will be displayed by C++?
Option D
In C++, every statement must end with a semicolon. If a programmer forgets to write a semicolon, the compiler shows an error, but it does not display the messages given in the options.
Different C++ compilers show different error messages, such as “expected ‘;’ before …” or “missing ‘;’,” but none of these matches exactly with “Semicolon Missing,” “Statement Missing,” or “Error in Statements.”
Q: 5Which of the following is user-defined header file extension used in C++?
Option C
In C++, a header file contains declarations such as functions, classes, constants, and macros. These files are included in a program using the #include directive. There are two types of header files, predefine header files iostream.h, conio.h and user-defined header files created by the programmer.
User-defined header files in C++ typically use the extension “.h”. For example, #include "myheaderfile.h"
Q: 6Which of the following is the original creator of the C++ language?
Option C
C++ is an object-oriented programming language. It was developed by Bjarne Stroustrup at AT&T bell laboratories in the Murray Hill, New Jersey, USA in the year 1979. It is an extension to C with number of new features added.
The starting name of C++ was “C with Classes” and in 1983 the name is changed to C++.
The first use of class construct in a programming language occurred in 1962 in the language Simula67.
Q: 7The preprocessor directive in C++ always starts with?
Option B
In C++, all preprocessor directives always start with the hash symbol (#). Preprocessor directives are processed before compilation. They are used for tasks like file inclusion, macro definition, and conditional compilation.
E.g.:
#include <iostream>
#define PI 3.14
Q: 8In C++, namespace defines a ________ for the identifiers that are used in a program.
Option B
In C++, a Namespace is used to organize identifiers such as variables, functions, classes, and objects. It provides a separate scope to avoid naming conflicts in large programs.
When two identifiers have the same name, namespaces help distinguish them by placing them in different scopes.
#include<iostream>
using namespace std;
namespace A
{
int value = 10;
}
namespace B
{
int value = 20;
}
int main()
{
cout<<A::value<<endl;
cout<<B::value;
return 0;
}
The A::value and B::value belong to different namespaces. The namespace defines the scope of these identifiers.
Q: 9Which shortcut key is used to compile and run the program in C++?
Option C
In the traditional Turbo C++ environment, two different shortcut keys are used:
Q: 10Which of the following statement(s) is/are correct regarding void keyword in C++?
I. To specify the return type of a function when it is not returning any value.
II. To indicate an empty argument list to a function.
Option C
The void keyword in C++ is used to represent the absence of a data type or value. It tells the compiler that no value is associated in a particular situation. The void keyword is mainly used in functions, pointers, and parameter lists.
One common use of void is as a function return type. When a function performs some tasks but does not return any value, its return type is declared as void.
For example, in the function declaration void display();, the keyword void indicates that the display() function does not return any value.
The void keyword is also used to indicate that a function does not accept any arguments.
For example, in the function declaration void display(void);, the keyword void inside the parentheses indicates that the display() function does not accept any arguments.
Another important use of void is with pointers. A void pointer can store the address of any data type.
For example, in the declaration void *ptr;, the pointer ptr can point to an int, float, char, or any other data type.
| Use of void | Purpose |
|---|---|
| void function() | Function returns no value. |
| function(void) | Function accepts no arguments. |
| void *pointer | Generic pointer for any data type. |
Thus, the void keyword is very important in C++ because it specifies “no value”, “no argument”, or “generic type” depending on its usage.
Q: 11Which of the following statements is true about the new and malloc?
I. The ‘new’ is a type of operator while ‘malloc’ is a kind of function.
II. The ‘new’ invokes a constructor, whereas ‘malloc’ does not invoke the constructor.
III. The ‘malloc’ returns void pointer and also needed to typecast whereas ‘new’ returns required pointer.
Option C
In C++, new and malloc are both used for dynamic memory allocation, but they behave differently:
The new is an operator, while malloc is a function. This means new is handled by the compiler, whereas malloc is a library function from C. The statement (I) is true.
The new invokes the constructor for object initialization, while malloc only allocates raw memory and does not call any constructor. The statement (II) is true.
The malloc returns a void pointer, so it often needs typecasting in C++, whereas new automatically returns a pointer of the required type. The statement (III) is true.
| Feature | new | malloc() |
|---|---|---|
| Type | Operator. | Function. |
| Constructor | Called. | Not called. |
| Return Type | T* | void* |
Q: 12In C++, bool data type is used to hold how many values?
Option B
In C++, the bool data type is used to store Boolean values. A Boolean variable can hold only two possible values either true or false.
These values are mainly used in conditional statements, decision making, and logical operations.
Thus, the bool data type can store only two values.
Q: 13The cin and cout is the?
Option B
In C++, cin and cout are not functions. They are objects created by the C++ standard library. The cin is a predefined object of the class istream (input stream) while the cout is a predefined object of the class ostream (output stream). Both are declared in the <iostream> header file and belong to the std namespace.
Q: 14In C++, the operator << is known as ____________.
Option A
In C++, the operator << is known as the insertion operator when used with output streams. It is used to insert data into an output stream, such as cout and sends (inserts) data from the program to the output device (screen).
Q: 15Which of the following approaches is used by C++?
Option C
C++ uses the bottom-up approach, which is a core philosophy of object-oriented programming. In this approach, programs are built by first creating small, reusable components such as classes and objects, and then combining them to form larger and more complex systems.
| TOP-DOWN APPROACH | BOTTOM-UP APPROACH |
|---|---|
| Breaks the program into major modules first, then divides them into smaller parts. | Builds small components/modules first and combines them to form a complete system. |
| Used mostly in procedural programming. | Used mostly in object-oriented programming. |
| Focus on functions or procedures. | Focus on objects and classes. |
| The main function designed first. | Small reusable modules are designed first. |
| Lower reusability. | Higher reusability. |
You have reached the end of this topic. Continue learning with the next topic below.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.