Programming Skills MCQs

What does OOP stand for in C++?

a. Object-Oriented Programming
b. Output Operator
c. Overloading and Overriding Principles
d. None of the above

Which keyword is used for dynamic memory allocation in C++?

a. malloc
b. alloc
c. new
d. memoryalloc

What is the default access specifier in a class in C++?

a. Public
b. Protected
c. Private
d. Private if not specified

What is the size of the ‘char’ data type in C++?

a. 4 bytes
b. 2 bytes
c. 1 byte
d. 8 bytes

What is the output of the following code snippet?

a. 2.5
b. 2
c. 2.0
d. 2.25

What is the purpose of ‘cin’ in C++?

a. Character input
b. Console input
c. Standard input
d. None of the above

What is the correct syntax to declare a pointer in C++?

a. int *ptr;
b. ptr int;
c. pointer int;
d. Both a and b

What is the ‘this’ pointer in C++? a. It points to the base class
b. It points to the derived class
c. It points to the object itself
d. It points to the class definition

Which function is called automatically when an object is created in C++?

a. Initialize()
b. Begin()
c. Constructor()
d. Main()

What is the purpose of the ‘static’ keyword in C++?

a. It makes a variable constant
b. It specifies a constant value
c. It declares a variable with global scope
d. It declares a variable with a static lifetime

What is the use of the ‘const’ keyword in a function declaration?

a. It makes the function constant
b. It makes the parameters constant
c. It promises not to modify the object
d. It declares a constant return type

What is the correct syntax for a switch statement in C++?

a. switch(expr) { case 1: … }
b. case(expr) { switch 1: … }
c. switch(expr) { case 1: … }
d. switch case(expr) { 1: … }

What does the ‘endl’ manipulator do in C++?

a. Ends the program
b. Inserts a newline character and flushes the stream
c. Ends the loop
d. Clears the screen

Which header file is needed for file I/O in C++?

a. <fileio.h>
b. <inputoutput.h>
c. <fstream>
d. <iofile>

What is the purpose of the ‘typeid’ operator in C++?

a. It returns the type of a variable
b. It returns a type_info object representing the type of an expression
c. It checks if a type is valid
d. It converts types

What is the output of the following code snippet?

a. 5

b. 6
c. 5 followed by increment of x
d. 6 followed by increment of x

In C++, what is the difference between ‘++x’ and ‘x++’?

a. Both are the same
b. ‘++x’ increments x after its current value is used
c. ‘++x’ increments x before its current value is used
d. ‘x++’ is not a valid syntax

What is the scope of a variable declared inside a function in C++?

a. Local to the function
b. Limited to the block where it is declared
c. Global
d. It depends on the storage class

How do you declare a pure virtual function in C++?

a. virtual void func();
b. virtual void func() = 0;
c. void virtual func() = pure;
d. pure virtual void func();

What is the purpose of the ‘break’ statement in a loop or switch statement?

a. Terminates the program
b. Skips the next iteration of the loop
c. Exits the loop or switch statement
d. Jumps to the specified label

What is the output of the following code snippet?

a. 3
b. 4
c. 5
d. 4 (Array indexing starts from 0)

What is the purpose of the ‘friend’ keyword in C++?

a. It declares a function as a friend
b. It declares a class as a friend
c. It allows a function or class access to private members of another class
d. It specifies a function is friendly

Which of the following is a valid way to create a reference in C++?

a. int &ref = 10;
b. int *ref = &x;
c. int x = 5; int &ref = x;
d. int ref = x;

What is the purpose of the ‘try’, ‘catch’, and ‘throw’ keywords in C++?

a. Error handling
b. Exception handling
c. Debugging
d. Memory management

Which operator is used to access the member of a structure in C++?

a. .
b. ->
c. :
d. ::

What is the purpose of the ‘auto’ keyword in C++11 onwards?

a. Automatically converts data types
b. Automatically deduces the type of a variable
c. Automatically allocates memory
d. Automatically initializes variables

How is the ‘sizeof’ operator used in C++?

a. sizeof(x) returns the size of x in bytes
b. size(x) returns the size of x in bits
c. sizeof(x) returns the size of x in bytes or elements, depending on the type
d. size(x) returns the size of x in kilobytes

What is the purpose of the ‘virtual’ keyword in C++?

a. Declares a variable as virtual
b. Declares a function as virtual
c. Specifies virtual inheritance
d. Enables runtime polymorphism

Which header file is required for using ‘setw’ manipulator in C++?

a. <iomanip>
b. <setwidth>
c. <format>
d. <ios>

 

All Copyrights Reserved 2025 Reserved by T4Tutorials