Created by Bjarne Stroustrup as an extension of the C programming language, C++ is a powerful, high-performance, statically typed language supporting both procedural and object-oriented programming paradigms. Mastery of C++ basics forms the critical foundation for software engineering, system architecture, game development, and high-performance applications. Core fundamentals include basic syntax, standard input/output streams, variable declarations, control structures, pointer manipulation, and fundamental object-oriented principles like classes and encapsulation.
Latest C++ Basics MCQs
1 min read
Correct Answer: b) Bjarne Stroustrup
Explanation:
Bjarne Stroustrup created C++ at Bell Labs in 1979 as an extension of the C language.
Correct Answer: c) C with Classes
Explanation:
C++ was initially named C with Classes because it introduced object-oriented features to C.
Correct Answer: a) .cpp
Explanation:
While .cxx and .cc are sometimes used, .cpp is the most common and standard extension for C++ source files.
Correct Answer: d) Multi-paradigm
Explanation:
C++ is a multi-paradigm language, supporting procedural, object-oriented, and generic programming.
Correct Answer: b) main()
Explanation:
Every C++ program must contain a main() function, which serves as the entry point for execution.
Correct Answer: b)
Explanation:
The header file contains definitions for standard streams like cin and cout.
Correct Answer: c) cout
Explanation:
cout is the standard output stream object in C++, used to display output on the console.
Correct Answer: b) <<
Explanation:
The stream insertion operator (<<) is used to send data to the standard output stream.
Correct Answer: c) cin
Explanation:
cin is the standard input stream object used to read input from the user.
Correct Answer: b) >>
Explanation:
The stream extraction operator (>>) is used to extract data from the standard input stream.
Correct Answer: c) Inserts a newline character and flushes the output buffer
Explanation:
endl inserts a newline character and ensures the output buffer is flushed to the console.
Correct Answer: b) To avoid prefixing standard library elements with std::
Explanation:
It brings all identifiers from the standard namespace into the current scope, simplifying code syntax.
Correct Answer: c) //
Explanation:
In C++, double slashes (//) are used to write single-line comments.
Correct Answer: a) /* comment */
Explanation:
Multi-line comments start with /* and end with */.
Correct Answer: b) int
Explanation:
The int data type is used to store whole numbers (integers) without decimals.
Correct Answer: c) 4 bytes
Explanation:
On most modern systems, the int data type occupies 4 bytes of memory.
Correct Answer: b) char
Explanation:
The char data type is used to store a single character, enclosed in single quotes.
Correct Answer: a) 1 byte
Explanation:
The char data type typically takes exactly 1 byte of memory.
Correct Answer: c) float
Explanation:
The float data type represents single-precision floating-point numbers.
Correct Answer: b) double
Explanation:
The double data type represents double-precision floating-point numbers.
Correct Answer: b) bool
Explanation:
The bool data type in C++ holds one of two values: true or false.
Correct Answer: c) void
Explanation:
The void keyword is used as a return type for functions that do not return a value.
Correct Answer: b) const
Explanation:
The const keyword ensures that the value of a variable cannot be changed after initialization.
Correct Answer: c) 1stVar
Explanation:
Variable names in C++ cannot begin with a number. They must start with a letter or an underscore.
Correct Answer: b) To determine the size of a variable or data type in bytes
Explanation:
The sizeof operator evaluates to the number of bytes required to store a type or a variable in memory.
Correct Answer: c) +
Explanation:
The + operator is an arithmetic operator used for addition.
Correct Answer: b) %
Explanation:
The modulo operator (%) returns the remainder of a division operation.
Correct Answer: b) Increments the value of a variable by 1
Explanation:
The increment operator (++) increases the integer value of its operand by exactly 1.
Correct Answer: b) ++x increments the value before it is used, x++ increments it after
Explanation:
Pre-increment (++x) increments the variable and then returns the new value. Post-increment (x++) returns the original value and then increments.
Correct Answer: b) ==
Explanation:
The == operator checks if the values of two operands are equal. The = operator is for assignment.
Correct Answer: c) !=
Explanation:
The != operator is the standard relational operator in C++ for inequality checking.
Correct Answer: c) &&
Explanation:
The && operator is the logical AND operator. It evaluates to true only if both operands are true.
Correct Answer: c) ||
Explanation:
The || operator is the logical OR operator. It evaluates to true if at least one of its operands is true.
Correct Answer: a) !
Explanation:
The ! operator is the logical NOT operator. It reverses the logical state of its operand.
Correct Answer: b) &
Explanation:
The single & is the bitwise AND operator, which performs a logical AND operation on each corresponding bit.
Correct Answer: c) ^
Explanation:
The ^ symbol is the bitwise XOR (exclusive OR) operator in C++.
Correct Answer: b) Adds 5 to x and stores the result in x
Explanation:
The compound assignment operator += is shorthand for x = x + 5.
Correct Answer: c) ?:
Explanation:
The conditional operator (?:) is the only ternary operator in C++, taking three operands.
Correct Answer: c) ::
Explanation:
The scope resolution operator (::) is used to specify the context to which an identifier belongs.
Correct Answer: a) if
Explanation:
The if statement evaluates a boolean condition and executes the subsequent block of code if the condition is true.
Correct Answer: b) else
Explanation:
The else keyword defines a block of code to be executed when the preceding if condition evaluates to false.
Correct Answer: c) switch
Explanation:
The switch statement evaluates an expression and branches to the case label matching the expression's value.
Correct Answer: c) To exit the switch block and prevent fall-through
Explanation:
Without a break, execution will fall through to subsequent cases. The break statement exits the switch statement entirely.
Correct Answer: d) default
Explanation:
The default case in a switch statement acts as a catch-all if none of the explicit case values match.
Correct Answer: b) for loop
Explanation:
The for loop is specifically structured with initialization, condition, and iteration statements in one line.
Correct Answer: c) while loop
Explanation:
A while loop checks its condition at the beginning. If the condition is false initially, the loop body never executes.
Correct Answer: c) do-while loop
Explanation:
A do-while loop evaluates its condition at the end of the iteration, meaning the body executes at least once.
Correct Answer: d) break
Explanation:
The break statement terminates the innermost enclosing loop or switch immediately.
Correct Answer: b) continue
Explanation:
The continue statement stops execution of the current iteration and jumps back to evaluate the loop's condition or increment.
Correct Answer: b) A loop that never terminates because its condition is never false
Explanation:
An infinite loop occurs when the terminating condition is never met or the condition is explicitly set to always be true.
Correct Answer: a) for(;;)
Explanation:
In a for loop, omitting the initialization, condition, and increment leaves for(;;). An empty condition evaluates to true.
Correct Answer: b) A block of code designed to perform a particular task
Explanation:
Functions help organize code into reusable blocks that execute a specific task when called.
Correct Answer: b) The function name and parameter list
Explanation:
In C++, a function's signature includes its name and the sequence of its parameter types. The return type is not part of the signature.
Correct Answer: c) return
Explanation:
The return keyword terminates function execution and specifies the value to be returned to the caller.
Correct Answer: b) An integer
Explanation:
The int preceding the function name dictates that the function must return an integer value.
Correct Answer: b) A copy of the value is passed, so the original variable is unchanged
Explanation:
Pass by value means the function works with a copy of the argument. Changes made inside the function do not affect the original variable.
Correct Answer: b) By using the & operator before the parameter name
Explanation:
The ampersand (&) in the parameter list indicates that the variable is passed by reference.
Correct Answer: b) Values automatically provided if the caller does not supply an argument
Explanation:
Default arguments allow a function to be called with fewer arguments than declared. The compiler fills in missing arguments with default values.
Correct Answer: b) From right to left
Explanation:
Default arguments must be specified from right to left. If a parameter has a default argument, all parameters to its right must also have default arguments.
Correct Answer: b) Multiple functions with the same name but different parameters
Explanation:
Function overloading allows you to use the same function name for multiple functions, provided they have a different number or type of parameters.
Correct Answer: b) No
Explanation:
C++ does not allow function overloading based solely on return type because the compiler cannot determine which function to call if the return value is ignored.
Correct Answer: b) A function whose body is inserted at the place where it is called, to reduce function call overhead
Explanation:
The inline keyword requests the compiler to expand the function code at the call site to eliminate the overhead of a function call.
Correct Answer: b) A collection of variables of the same data type stored in contiguous memory locations
Explanation:
An array is a fixed-size sequential collection of elements of the same type stored in contiguous memory blocks.
Correct Answer: c) 0
Explanation:
In C++, array indexing is zero-based, meaning the first element is accessed using index 0.
Correct Answer: b) int arr[5];
Explanation:
The correct syntax places the size inside square brackets after the variable name: type arrayName[arraySize];.
Correct Answer: c) Undefined behavior, which may cause a crash or garbage value to be read/written
Explanation:
C++ does not perform bounds checking on arrays. Accessing out of bounds leads to undefined behavior.
Correct Answer: c) int arr[3][4];
Explanation:
A 2D array is declared using two sets of square brackets: type name[rows][columns].
Correct Answer: c) The memory address of the first element
Explanation:
An array name decays into a pointer to its first element in most contexts, holding the base memory address of the array.
Correct Answer: b) Null character
Explanation:
C-style strings are null-terminated, meaning they end with a special null character to signify the string's conclusion.
Correct Answer: b) 4 bytes
Explanation:
It takes 4 bytes: 3 bytes for the characters 'c', 'a', 't', and 1 byte for the implicit null terminator.
Correct Answer: c) std::string
Explanation:
The std::string class from the standard library is the standard and recommended way to manage dynamic strings in C++.
Correct Answer: b) A variable that stores the memory address of another variable
Explanation:
A pointer is a variable whose value is the physical address of another variable in memory.
Correct Answer: c) &
Explanation:
The address-of operator (&) precedes a variable to return its memory address.
Correct Answer: b) *
Explanation:
The asterisk (*) is used in a declaration to indicate that the variable is a pointer.
Correct Answer: c) *
Explanation:
The dereference operator (*) accesses the value located at the memory address held by the pointer.
Correct Answer: b) A pointer that does not point to any valid memory location
Explanation:
A null pointer is explicitly assigned a value of 0 or nullptr to indicate it is not pointing to any valid object or function.
Correct Answer: c) nullptr
Explanation:
The nullptr keyword was introduced in C++11 as a type-safe null pointer constant, replacing the macro NULL.
Correct Answer: b) A pointer pointing to a memory location that has been deallocated or freed
Explanation:
Dangling pointers arise when an object is deleted or goes out of scope, but the pointer still holds the address of that freed memory.
Correct Answer: b) Pointers can be null, but references must be initialized to a valid object and cannot be null
Explanation:
A reference acts as an alias and must be bound to an existing object upon creation, meaning it cannot logically be null, unlike pointers.
Correct Answer: c) int &r = x;
Explanation:
The & symbol in a declaration specifies a reference. It makes r an alias for x.
Correct Answer: c) new
Explanation:
The new operator allocates memory on the heap and calls the constructor if an object is being created.
Correct Answer: b) A pointer to the beginning of the allocated memory block
Explanation:
The new operator requests memory from the OS and returns a pointer holding the address of the allocated block.
Correct Answer: d) delete
Explanation:
The delete operator deallocates memory previously allocated by new, preventing memory leaks.
Correct Answer: b) delete[] ptr;
Explanation:
When memory is allocated for an array using new[], it must be released using the array delete operator delete[].
Correct Answer: b) A memory leak occurs
Explanation:
If delete is not called, the memory remains occupied even after it is no longer used, resulting in a memory leak.
Correct Answer: b) Heap
Explanation:
Dynamic memory allocation at runtime happens in the Heap memory segment.
Correct Answer: a) Stack
Explanation:
The Stack memory segment is used for static memory allocation, managing local variables, and function call frames.
Correct Answer: b) A user-defined data type that groups different variables under a single name
Explanation:
A structure (struct) allows you to combine data items of different kinds into a single custom type.
Correct Answer: c) public
Explanation:
Unlike classes where members are private by default, all members of a struct are public by default in C++.
Correct Answer: c) person.age
Explanation:
The dot operator is used to access members of a struct or class instance directly.
Correct Answer: b) ptr->age
Explanation:
The arrow operator (->) is used to access members of a struct or class via a pointer.
Correct Answer: c) A user-defined data type consisting of integral constants
Explanation:
An enumeration (enum) assigns names to integer constants to make a program easier to read and maintain.
Correct Answer: b) 1
Explanation:
By default, enums start at 0 and increment by 1. RED is 0, GREEN is 1, and BLUE is 2.
Correct Answer: c) Classes and Objects
Explanation:
C++ introduced Object-Oriented Programming (OOP) features like Classes and Objects, which are absent in C.
Correct Answer: a) A blueprint or template for creating objects
Explanation:
A class defines a new data type containing data members and member functions. Objects are instances of a class.
Correct Answer: b) private
Explanation:
In a C++ class, if no access specifier is provided, all members default to private.
Correct Answer: a) A variable of type class
Explanation:
An object is an instantiation of a class. It holds the data and methods defined by its class blueprint.
Correct Answer: c) public
Explanation:
Public members can be accessed from anywhere the object is visible.
Correct Answer: b) A special member function automatically called when an object is instantiated
Explanation:
Constructors have the same name as the class and initialize objects when they are created.
Correct Answer: d) Constructors do not have a return type
Explanation:
Constructors are unique because they do not have any return type, not even void.
Correct Answer: b) A special member function automatically called when an object goes out of scope or is deleted
Explanation:
Destructors clean up resources before an object is destroyed. They have the class name preceded by a tilde.
Correct Answer: c) ~
Explanation:
A tilde precedes the class name to declare a destructor.
Correct Answer: b) Preserves its value between function calls
Explanation:
A static local variable is initialized only once and retains its value across multiple calls to the function.
Related Posts
NewNew
New
No Image
C++ Templates - MCQs
1. Who is the creator of the C++ programming language? a) Dennis Ritchie b) Bjarne Stroustrup c) James Gosling d)…
October 19, 2026By MCQs Generator

C++ Variables & Data Types MCQs
Variables and data types form the core building blocks of any C++ application, defining how data is stored, represented, and…
October 19, 2026By MCQs Generator
No Image
C++ Inheritance and Polymorphism - MCQs
1. Who is the creator of the C++ programming language? a) Dennis Ritchie b) Bjarne Stroustrup c) James Gosling d)…
October 19, 2026By MCQs Generator








