Variables and data types form the core building blocks of any C++ application, defining how data is stored, represented, and manipulated in memory. C++ is a statically typed language, meaning every variable must be declared with a specific data type (such as int, float, char, or bool) before use. Understanding fundamental types, modifiers (signed, unsigned, short, long), type casting mechanisms, and modern C++ type deduction (auto) is essential for writing efficient, type-safe, and high-performance software.
C++ Variables & Data Types MCQs
1 min read
Correct Answer: c) int
Explanation:
In C++, 'int' is a built-in fundamental data type used to store integer values.
Correct Answer: a) 1 byte
Explanation:
The C++ standard guarantees that the size of a 'char' is exactly 1 byte.
Correct Answer: b) bool
Explanation:
The 'bool' keyword is used in C++ to declare boolean variables holding true or false.
Correct Answer: a) An empty set of values
Explanation:
The 'void' type specifies that no value is available, often used for functions returning nothing.
Correct Answer: b) double
Explanation:
The 'double' data type provides double-precision floating-point numbers, offering more precision than 'float'.
Correct Answer: b)
Explanation:
The header must be included to use the C++ Standard Library std::string class.
Correct Answer: b) 4 bytes
Explanation:
In most common architectures, a 'float' typically occupies 4 bytes (32 bits) in memory.
Correct Answer: b) The compiler and system architecture
Explanation:
Aside from 'char', the exact sizes of types like 'int' depend on the compiler and hardware architecture.
Correct Answer: c) sizeof()
Explanation:
The 'sizeof' operator evaluates to the size, in bytes, of a specific variable or data type.
Correct Answer: b) wchar_t
Explanation:
'wchar_t' is the wide-character type used to represent characters requiring more memory, like Unicode.
Correct Answer: c) unsigned
Explanation:
The 'unsigned' modifier can be applied to both integer and character types to restrict them to non-negative values.
Correct Answer: b) 2 bytes
Explanation:
A 'short int' typically takes up 2 bytes of memory, storing values up to 32,767 (if signed).
Correct Answer: c) 255
Explanation:
An 8-bit unsigned char holds values from 0 to (2^8 - 1), which equals 255.
Correct Answer: d) The value wraps around to a large positive number
Explanation:
Assigning a negative value to an unsigned integer causes an underflow, wrapping around to a large positive value.
Correct Answer: d) medium
Explanation:
C++ supports 'short', 'long', 'signed', and 'unsigned'. 'medium' does not exist.
Correct Answer: b)
Explanation:
The header contains macros that define the minimum and maximum limits of integer types.
Correct Answer: c) long long int
Explanation:
C++11 standardized 'long long int' to ensure a minimum width of 64 bits across platforms.
Correct Answer: b) No, it is a compilation error
Explanation:
The 'unsigned' modifier is strictly for integral types. Applying it to 'float' or 'double' causes a compilation error.
Correct Answer: c) Implementation-defined
Explanation:
The C++ standard leaves whether plain 'char' is signed or unsigned up to the compiler implementation.
Correct Answer: c) long short int
Explanation:
You cannot combine 'long' and 'short' together on the same variable, as they are conflicting size requirements.
Correct Answer: b) *myVar
Explanation:
Variables can start with an underscore or letter. They cannot start with a number, contain spaces, or use hyphens.
Correct Answer: a) Yes
Explanation:
C++ is highly case-sensitive. Variables named 'count' and 'Count' are treated as completely distinct identifiers.
Correct Answer: c) class
Explanation:
'class' is a reserved keyword in C++ and cannot be used as a programmer-defined identifier.
Correct Answer: b) It is reserved for compiler implementations
Explanation:
Identifiers containing double underscores are reserved for the C++ standard library and compiler usage.
Correct Answer: d) No strict standard limit
Explanation:
The C++ standard defines no strict maximum length for identifiers, though individual compilers might impose practical limits.
Correct Answer: c) *
Explanation:
Only letters, digits, and underscores (*) are permitted in standard C++ variable names.
Correct Answer: b) No, because 'return' is a keyword
Explanation:
Keywords are reserved words in C++ and cannot be used as variable names.
Correct Answer: a) camelCase or snake_case
Explanation:
camelCase and snake_case are standard for variables, while PascalCase is used for classes, and UPPER_CASE for macros.
Correct Answer: a) Hyphens are parsed as the subtraction operator
Explanation:
Hyphens are interpreted by the compiler as the minus (subtraction) operator, making them invalid inside identifier names.
Correct Answer: c) Yes, it is a valid identifier
Explanation:
A single underscore is syntactically a valid identifier, though generally avoided for clarity.
Correct Answer: b) Garbage value
Explanation:
Uninitialized local variables contain whatever raw data was previously left at their memory location, known as a garbage value.
Correct Answer: a) 0
Explanation:
Global and static variables are zero-initialized by default before main() runs.
Correct Answer: c) Declares variable 'a' without defining it
Explanation:
The 'extern' keyword tells the compiler that the variable 'a' exists and its memory allocation is in another translation unit.
Correct Answer: c) int x{5};
Explanation:
Using curly braces {} for initialization is known as list initialization or uniform initialization, introduced in C++11.
Correct Answer: b) It prevents narrowing conversions by throwing an error
Explanation:
Brace initialization forbids narrowing conversions; trying to initialize an int with a float via braces causes a compilation error.
Correct Answer: a) int a, b = 10;
Explanation:
Multiple variables of the same type can be declared on a single line by separating them with commas.
Correct Answer: b) An expression that refers to an identifiable memory location
Explanation:
An L-value represents an object that occupies an identifiable location in memory, allowing it to appear on the left side of an assignment.
Correct Answer: c) A temporary value that does not persist beyond the expression
Explanation:
An R-value is typically a temporary literal or expression result that does not have a persistent memory address.
Correct Answer: a) True
Explanation:
C++ strictly requires all identifiers (variables) to be declared before they are used in any expression.
Correct Answer: b) int x(5);
Explanation:
Direct initialization uses parentheses to initialize a variable, invoking its constructor directly.
Correct Answer: c) The block or function it is declared in
Explanation:
Local variables are only accessible within the specific code block {} or function where they are defined.
Correct Answer: c) ::
Explanation:
The scope resolution operator (::) tells the compiler to access the global scope version of the variable.
Correct Answer: b) It persists for the duration of the entire program
Explanation:
A local static variable is initialized once and retains its value between function calls until the program terminates.
Correct Answer: c) The inner variable shadows (hides) the outer variable
Explanation:
Variable shadowing occurs when a variable in an inner scope has the same name as one in an outer scope, temporarily hiding it.
Correct Answer: b) A variable defined outside of all functions
Explanation:
Global variables are defined outside any function or block, making them globally accessible to the program.
Correct Answer: b) Only the file it is declared in
Explanation:
When 'static' is applied to a global variable, it gives it internal linkage, making it visible only within its own translation unit.
Correct Answer: c) The Heap
Explanation:
Dynamic memory allocation using 'new' creates variables on the heap (free store).
Correct Answer: a) The Stack
Explanation:
Automatic local variables are pushed onto the call stack and popped when they go out of scope.
Correct Answer: b) Store the variable in CPU registers for fast access
Explanation:
Historically, 'register' requested the compiler to store the variable in a CPU register for speed (deprecated in modern C++).
Correct Answer: c) thread_local
Explanation:
The 'thread_local' keyword specifies thread storage duration, creating a unique instance of the variable per thread.
Correct Answer: b) Prevents it from being modified after initialization
Explanation:
'const' creates a constant value, causing a compile error if code attempts to modify it.
Correct Answer: b) Exactly at the time of its declaration
Explanation:
Because a const variable cannot be assigned a value later, it must be initialized exactly when declared.
Correct Answer: b) constexpr is evaluated at compile-time; const can be runtime
Explanation:
'constexpr' guarantees that the variable is evaluated at compile time, while 'const' just guarantees immutability, even if initialized at runtime.
Correct Answer: b) The integer being pointed to cannot be modified through this pointer
Explanation:
This is a pointer to a constant integer. The memory address can change, but the value it points to cannot be altered via the pointer.
Correct Answer: a) The pointer itself cannot change, but the value it points to can
Explanation:
This is a constant pointer. The address it holds is locked, but the actual integer data can be modified.
Correct Answer: d) #define cannot handle strings
Explanation:
#define can handle string literals easily. The other statements are true advantages of using const.
Correct Answer: b) The variable's value may change externally, so the compiler shouldn't optimize it
Explanation:
'volatile' warns the compiler that a variable might be modified by hardware or other threads, preventing aggressive caching optimizations.
Correct Answer: b) mutable
Explanation:
The 'mutable' keyword overrides 'const', allowing specific members to be modified inside a constant object.
Correct Answer: b) Internal linkage
Explanation:
In C++, global const variables have internal linkage by default, meaning they are restricted to their own translation unit unless declared extern.
Correct Answer: a) const_cast
Explanation:
'const_cast' is uniquely designed to strip or add 'const' and 'volatile' qualifiers from pointers or references.
Correct Answer: b) The fractional part is simply truncated
Explanation:
Implicit conversion from float/double to int strictly truncates (drops) the decimal portion without rounding.
Correct Answer: d) static_cast
Explanation:
'static_cast' performs standard conversions (like float to int) and checks safety at compile time.
Correct Answer: a) dynamic_cast
Explanation:
'dynamic_cast' performs runtime type checking to safely cast pointers/references within polymorphic class hierarchies.
Correct Answer: b) It returns nullptr
Explanation:
If a dynamic_cast fails when casting pointers, it safely returns nullptr. (If it fails on a reference, it throws std::bad_cast).
Correct Answer: c) reinterpret_cast
Explanation:
'reinterpret_cast' overrides the type system, interpreting the raw memory as a completely different type.
Correct Answer: b) Automatically converting smaller integer types to 'int' for arithmetic
Explanation:
Types smaller than int (like char or short) are implicitly promoted to int before performing arithmetic operations.
Correct Answer: b) false
Explanation:
In C++, the integer 0 implicitly converts to the boolean value 'false'.
Correct Answer: a) true
Explanation:
Any non-zero integer (positive or negative) implicitly converts to 'true'.
Correct Answer: b) Explicit C-style casting
Explanation:
Using parentheses with a type name before a variable is the syntax for an explicit C-style cast.
Correct Answer: a) Returns a std::type_info object containing type information at runtime
Explanation:
'typeid' is part of RTTI (Run-Time Type Information) and returns type details of an expression.
Correct Answer: b) Deduces the type of a variable from its initializer at compile time
Explanation:
'auto' tells the compiler to deduce the variable's type based on the right-hand side expression.
Correct Answer: b) No
Explanation:
Because 'auto' deduces the type from the initialization value, the variable must be initialized immediately.
Correct Answer: c) int*
Explanation:
The '&' operator takes the address, returning a pointer. Thus, 'auto' deduces 'int*'.
Correct Answer: d) decltype
Explanation:
'decltype' determines the exact type of an expression at compile time without executing the expression itself.
Correct Answer: c) A keyword representing a type-safe null pointer literal
Explanation:
'nullptr' provides a type-safe pointer constant (of type std::nullptr_t), unlike NULL which is just an integer 0.
Correct Answer: a) char16_t
Explanation:
C++11 added 'char16_t' to explicitly support UTF-16 Unicode character representation.
Correct Answer: b) No
Explanation:
When copying a value, 'auto' strips top-level const qualifiers. You must write 'const auto' to keep it constant.
Correct Answer: b) Structured bindings
Explanation:
Structured bindings (e.g., auto [x, y] = myPair;) unpack structures or tuples into individual variable names.
Correct Answer: c) A distinct type implementing raw memory without arithmetic operations
Explanation:
std::byte provides a type-safe representation of memory bytes, supporting bitwise operations but intentionally lacking math operations.
Correct Answer: a) Yes
Explanation:
Unlike auto, decltype precisely deduces the exact type, retaining all const and reference qualifiers.
Correct Answer: b) To create an alias for an existing data type
Explanation:
'typedef' allows programmers to create custom name aliases for existing, often complex, types.
Correct Answer: c) using
Explanation:
The 'using' keyword (e.g., using Integer = int;) acts as a modern alternative to typedef and supports templates.
Correct Answer: c) A user-defined type consisting of a set of named integer constants
Explanation:
An enumeration defines a custom type restricted to a specific set of named integer values.
Correct Answer: a) 0
Explanation:
By default, enumerators begin at 0 and increment by 1.
Correct Answer: c) It prevents implicit conversion to integers and scopes the names
Explanation:
Enum classes provide strong type safety by not implicitly casting to int and by requiring scoped access (e.g., Color::Red).
Correct Answer: b) Yes, by adding a colon and the type (e.g., enum class Color : char)
Explanation:
C++11 allows explicit specification of the underlying integer type for an enum to optimize memory usage.
Correct Answer: b) Struct members are public by default; class members are private by default
Explanation:
In C++, the only functional difference between a struct and a class is default visibility.
Correct Answer: c) A type where all members share the exact same memory location
Explanation:
A union holds different data types but stores them in the exact same memory space, meaning only one member is valid at a time.
Correct Answer: b) The size of its largest member
Explanation:
To ensure it can hold any of its members safely, a union's size is determined by its largest data member.
Correct Answer: b) Variables specifying their exact memory size in bits
Explanation:
Bit-fields allow you to tightly pack data by specifying the exact number of bits an integer member will consume.
Correct Answer: b) 1 byte
Explanation:
C++ requires every distinct object to have a unique memory address, so an empty class/struct is assigned a size of at least 1 byte.
Correct Answer: c) 8 bytes
Explanation:
Memory addresses on a 64-bit system are 64 bits wide, which equates to 8 bytes of memory.
Correct Answer: b) A generic pointer that can hold the address of any data type
Explanation:
A void pointer is a generic pointer type that can store the address of any object without knowing its type.
Correct Answer: b) No, it must be explicitly cast to a specific type first
Explanation:
Because the compiler doesn't know the size or type of the underlying data, a void pointer cannot be dereferenced directly.
Correct Answer: b) An alternative name (alias) for an already existing variable
Explanation:
A reference acts as an alias. Changes made through the reference directly modify the original aliased variable.
Correct Answer: b) No
Explanation:
A reference must always be initialized to alias an existing variable exactly at the time of its declaration.
Correct Answer: b) No, it is bound permanently upon initialization
Explanation:
Once a reference is bound to an object, it cannot be reseated. Any assignment modifies the bound object, not the reference itself.
Correct Answer: c) It decays into a pointer to its first element
Explanation:
Raw arrays 'decay' into a pointer to their first element, which is why size information is lost when passing to functions.
Correct Answer: b) std::string manages its own memory and length, while a C-string is just a null-terminated char array
Explanation:
C-strings require manual memory and terminator management, whereas std::string is an object managing its own dynamic memory.
Correct Answer: b) No, it is explicitly illegal in C++
Explanation:
C++ forbids arrays of references because references are not distinct objects and do not take up standalone memory in an array context.
Related Posts
New
NewNew

C++ Classes and Objects - MCQs
In C++, a class is a fundamental building block of Object-Oriented Programming (OOP) that acts as a user-defined blueprint for…
October 19, 2026By MCQs Generator
No Image
C++ Exception / Error Handling - MCQs
1. Which of the following is a fundamental data type in C++? a) String b) Array c) int d) Class…
October 19, 2026By MCQs Generator

Latest C++ Basics MCQs
Created by Bjarne Stroustrup as an extension of the C programming language, C++ is a powerful, high-performance, statically typed language…
October 19, 2026By MCQs Generator








