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 13

What is the output: int x=5; cout<<clamp(x,1,4);
4
click to copy
What is 'integer sequence' std::integer_sequence?
Compile-time sequence of integers for template metaprogramming
click to copy
What is the output: int x=5; auto [a,b]=[x,x*2]; cout<<a<<b;
Compile error
click to copy
What is 'std::numeric_limits<int>::digits'?
Number of binary digits (bits-1 for signed)
click to copy
What is the output: int x=5; cout<<(x*2==10)<<(x/2==2)<<(x%2==1);
111
click to copy
What is 'volatile const' combination?
Read-only variable whose value may change externally
click to copy
What is the output: int x=-5; cout<<abs(x);
5
click to copy
What is 'std::tuple_size'?
Compile-time number of elements in tuple/pair/array
click to copy
What is the output: auto x=3.14; auto y=3.14f; cout<<(sizeof(x)==sizeof(y));
0
click to copy
What is 'std::get<N>(tuple)'?
Access Nth element of tuple at compile time
click to copy
What is the output: auto t=make_tuple(1,2.0,'A'); cout<<get<0>(t)<<get<2>(t);
1A
click to copy
What is 'std::variant::visit'?
Calls correct overload for currently held type
click to copy
What is the output: variant<int,double> v=3.14; cout<<holds_alternative<double>(v);
1
click to copy

OOP Using C++ → Operators in C++ 27

What is the output: int x=5; cout<<(x&1?'O':'E');
O
click to copy
What is the output: int x=12; cout<<(x&(x-1));
8
click to copy
What is the output: cout<<(true?1:2.0);
1.0
click to copy
What is the output: int x=5; cout<<(!x)<<(!!x)<<(!!!x);
010
click to copy
What is the output: int a=6,b=3; cout<<(a/=b,a*=b,a);
6
click to copy
What is 'conditional assignment' idiom?
x = cond ? a : b; assign based on condition
click to copy
What is the output: int x=0xFF; cout<<(x^=0x0F);
240
click to copy
What is the output: int x=5; cout<<(x<<0);
5
click to copy
What is the output: int x=5; cout<<(x>3&&x<10);
1
click to copy
What is 'safe bool idiom'?
Explicit operator bool to prevent implicit numeric conversions
click to copy
What is the output: int x=5; auto r=x>3?++x: (1, 6, 73, 3, 4, 'What is the output: int x=8; while(x&(x-1)) x&=x-1; cout<<x;', 'Clear bits until power of 2: x=8?', '8', '8', '4', '4', '1', '1', 'Compile error', 'Compile error', NULL, 'option_a', '8=1000 is already power of 2. 8&7=0: loop doesn't execute. Output: 8.
2026-05-25
click to copy
What is the output: int x=8; while(x&(x-1)) x&=x-1; cout<<x;
8
click to copy
What is the output: int x=0; cout<<(x=5,x*x);
25
click to copy
What is the output: cout<<(10>>1)<<(10<<1)<<(10%3);
5201
click to copy
What is the output: int x=5; cout<<~x;
-6
click to copy
What is the output: int x=7,y=3; cout<<(x/y)<<(x%y)<<(x/y*y+x%y);
217
click to copy
What is the output: bool a=true,b=true; cout<<(a^b)<<(a==b)<<(a!=b);
010
click to copy
What is the output: int x=5; cout<<(x|=0);
5
click to copy
What is the output: int x=5; cout<<(x&=x);
5
click to copy
What is the output: int a=0b1010,b=0b1100; cout<<(a&b)<<(a|b)<<(a^b);
8148
click to copy
What is the output: int x=256; cout<<(x>>8);
1
click to copy
What is 'operator new' overloading purpose?
All of above
click to copy
What is the output: int x=5; cout<<(x+=1)+(x+=1);
Undefined
click to copy
What is the output: int x=5; cout<<(x&&=0);
Compile error
click to copy
What is the output: int x=15; cout<<(x&=~0x7);
8
click to copy
What is the output: int a=5,b=10; int c=(a>b)?a:b; cout<<c;
10
click to copy
What is the output: int x=5; cout<<(x=x+1);
6
click to copy