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++ → Variables and Data Types 26

Which of these correctly initializes all elements to zero?
Both B and C
click to copy
What is the type of 'nullptr' in C++11?
std::nullptr_t
click to copy
What is the output: double d = 1/3; cout << d;
0
click to copy
What is the result: unsigned char x = 255; x++; cout << x;
0
click to copy
What does 'auto' deduce for: auto x = {1,2,3};
std::initializer_list<int>
click to copy
What is the size of: struct { char a; int b; char c; }?
Implementation-defined due to padding
click to copy
Which of these is NOT an integer type in C++?
float
click to copy
What is the output: int x=10; int &r=x; r=20; cout<<x;
20
click to copy
What is 'structured binding' introduced in C++17?
Decomposing an aggregate into named variables
click to copy
What is the output: int a=5; int b=a; b=10; cout<<a;
5
click to copy
Which storage class specifier makes a local variable persist between function calls?
static
click to copy
What is the output: int x=1; cout<<(x<<31);
Undefined behavior
click to copy
What is the difference between int* const p and const int* p?
int* const: pointer is const; const int*: pointee is const
click to copy
What is the output: bool b = true; cout << b + b;
2
click to copy
What is the value of: int x = 'a'; cout << x;
97
click to copy
What does 'register' keyword do in modern C++?
Compile error in C++17
click to copy
What is the type deduced by: auto& x = 42;
Compile error
click to copy
What is the output: int x=10; cout<<x/3<<' '<<x%3;
3 1
click to copy
What is 'POD type' in C++?
Plain Old Data — a type compatible with C data layout
click to copy
What is the output: char c='Z'-'A'; cout<<(int)c;
25
click to copy
Which of the following correctly declares a variable of type 'pointer to array of 5 ints'?
int (*p)[5]
click to copy
What is the output: int x=5; cout << (x>3 ? x<10 ? 'A' : 'B' : 'C');
A
click to copy
What is the output: double x = 0.1 + 0.2; cout << (x == 0.3);
0
click to copy
What is 'narrowing conversion' in C++?
A conversion that may lose information
click to copy
What is the output: int a=1,b=2; cout<<a+++b;
3
click to copy
What is the size of std::byte?
Same as char
click to copy

OOP Using C++ → Operators in C++ 14

What is the output: int a=5,b=3; cout<<(a&b)<<' '<<(a|b)<<' '<<(a^b);
1 7 6
click to copy
What does the spaceship operator <=> return in C++20?
std::strong_ordering or similar
click to copy
What is the output: int x=5; cout<<(x>>1)<<' '<<(x<<1);
2 10
click to copy
What is operator precedence for: a + b * c - d / e?
a + (b * c) - (d / e)
click to copy
What is the output: int x=10; cout << (x>5 && x++>9) << ' ' << x;
1 11
click to copy
What does operator-> overloading enable?
Custom pointer dereferencing
click to copy
What is the output: cout << (3,5,7);
7
click to copy
What is the result: int a=2; int b = a<<2 + 1;
16
click to copy
What is short-circuit evaluation in C++?
&& and || skip right operand if result determined from left
click to copy
What is the output: int x=5; x+=x-=x*=2; cout<<x;
Undefined behavior
click to copy
What is the output: int a=10,b=5; cout<<(a>b?a:b);
10
click to copy
What is the output: cout << ~0;
-1
click to copy
Which operator has the lowest precedence in C++?
throw
click to copy
What is the output: int x=6; cout<<(x%4)<<' '<<(-x%4);
2 -2
click to copy