Quick Revision

GK One-Line Question & Answer

15541+ short questions with short answers, covering every category and sub-category on the site — no long articles to scroll through. Good for a fast recap before an exam, or a few minutes of daily practice.

OOP Using C++ → Introduction to C++ 34

What is the output of: int main(){int x=10; std::cout<<x++<<' '<<++x; return 0;}
Undefined behavior
click to copy
Which of these is NOT a valid C++ translation phase?
Template instantiation
click to copy
What does the One Definition Rule (ODR) state?
Every entity must have exactly one definition in the whole program
click to copy
What is the size of an empty class in C++?
Implementation defined, but at least 1
click to copy
Which statement about #include guard vs pragma once is correct?
pragma once may fail with identical file copies on different paths
click to copy
What is a 'translation unit' in C++?
A single .cpp file after preprocessing
click to copy
What happens when you call a pure virtual function from a constructor?
Undefined behavior
click to copy
What is the difference between 'struct' and 'class' in C++?
Default access is public in struct, private in class
click to copy
What does 'extern C' do in C++?
Disables name mangling for the declared function
click to copy
In C++, what is the result of sizeof('A')?
sizeof(char)
click to copy
What is the output of: cout << (true + true + true);
3
click to copy
Which C++ feature allows a function to have multiple definitions with different parameter types?
Overloading
click to copy
What is the output: int x=5; cout << x<<2;
20
click to copy
Which of the following correctly declares a reference to a pointer to const int?
Both A and B
click to copy
What is 'name mangling' in C++?
Encoding function names with type info for linking
click to copy
What is the value of: int a = 010 + 0x10 + 10;
42
click to copy
What is the maximum number of bytes a UTF-8 character can occupy?
4
click to copy
Which header must be included to use std::numeric_limits?
<limits>
click to copy
What is the output: cout << (1 == 1 == 1);
1
click to copy
In C++, which of the following has static storage duration?
Global variables
click to copy
What is the output: int i=0; cout << i++ << i++;
Undefined behavior
click to copy
What is the purpose of the 'volatile' keyword in C++?
Prevents compiler optimization on a variable
click to copy
What is 'RAII' in C++?
Resource Acquisition Is Initialization
click to copy
What is the output: int x=5,y=3; cout<<(x&y)<<' '<<(x|y)<<' '<<(x^y);
1 7 6
click to copy
Which is the correct way to prevent a class from being instantiated directly in C++?
Declare at least one pure virtual function
click to copy
What is the output: cout << sizeof(void*) == sizeof(int*);
1
click to copy
What does 'constexpr' guarantee?
Expression CAN be evaluated at compile time
click to copy
What is the output: int arr[3]={1,2,3}; cout<<arr[5];
Undefined behavior
click to copy
What is the meaning of 'ABI' in C++?
Application Binary Interface
click to copy
Which operator cannot be overloaded in C++?
::
click to copy
What is the output: int x = -1; unsigned int y = x; cout << (y > 0);
1
click to copy
What is a 'sequence point' in C++?
A point where all side effects are complete
click to copy
In C++, what does 'decltype(auto)' do?
Deduces exact type including references
click to copy
What is the maximum value of a signed 32-bit integer?
2^31 - 1
click to copy

OOP Using C++ → Variables and Data Types 6

What is the output: int x=INT_MIN; cout << -x;
Undefined behavior
click to copy
Which type can hold a pointer to any object type?
void*
click to copy
What is the value of: auto x = 3.14f; decltype(x) y = 2; cout << sizeof(y);
4
click to copy
What is the difference between int and long in C++?
sizeof(long) >= sizeof(int) is guaranteed
click to copy
What happens: const int x = 5; int* p = const_cast<int*>(&x); *p = 10; cout << x;
Undefined behavior
click to copy
What is the output: int x = 0b1010; cout << x;
10
click to copy