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++ → Functions 35

What is the output: int f(int n,int s=0){return n?f(n/10,s+n%10):s;} cout<<f(123);
6
click to copy
What is 'lambda capture by move'?
[x=std::move(y)](){} — moves y into lambda
click to copy
What is the output: int f(int x){return x*x;} int g(int x){return x+1;} cout<<g(f(3));
10
click to copy
What is 'std::partial_application'?
Not standard; use std::bind or lambda
click to copy
What is the output: int f(int x,int y){return x*y+x+y;} cout<<f(2,3);
11
click to copy
What is 'std::bind_front' in C++20?
Binds leading arguments to function
click to copy
What is the output: int f(int n){return n<2?n:f(n-1)+f(n-2);} cout<<f(10);
55
click to copy
What is 'std::function' type erasure cost?
Possible heap allocation + indirect call overhead
click to copy
What is the output: template<int N> int f(){return N*f<N-1>();} template<> int f<0>(){return 1;} cout<<f<5>();
120
click to copy
What is 'immediately invoked function expression' (IIFE) use case?
Initialize const/constexpr with complex logic
click to copy
What is the output: int f(int a,int b=2,int c=3){return a*b*c;} cout<<f(1)<<f(1,4)<<f(1,4,5);
61220
click to copy
What is 'std::invoke_result_t'?
Type of result of invoking callable with args
click to copy
What is the output: int f(int n){int r=1; while(n>1) r*=n (1, 6, 75, 5, 4, 'What is 'noexcept' function and move semantics?
noexcept move constructor enables std::vector to move instead of copy on reallocation
click to copy
What is 'noexcept' function and move semantics?
noexcept move constructor enables std::vector to move instead of copy on reallocation
click to copy
What is the output: auto f=[](auto x,auto y){return x<y?x:y;}; cout<<f(3,5)<<f(4.0,2.0);
32.0
click to copy
What is 'overloading vs overriding'?
Overloading: same name diff params; overriding: replaces virtual
click to copy
What is the output: int f(int x){return x?x^f(x-1):0;} cout<<f(5);
1
click to copy
What is the output: int r=0; auto f=[&r](auto self,int n)->void{if(n>0){r+=n;self(self,n-1);}}; f(f,5); cout<<r;
15
click to copy
What is 'std::transform_reduce'?
Map then reduce: apply transform then reduction
click to copy
What is the output: int f(int x){return x;} auto& g=f; cout<<g(5);
5
click to copy
What is 'trailing requires clause' in C++20?
auto f(T x) requires Concept<T> — constrains template
click to copy
What is the output: int f(int x,int y){return x==0?y:f(y%x,x);} cout<<f(56,98);
14
click to copy
What is the output: int f(int n){return (n==0||n==1)?n:f(n-1)+f(n-2);} cout<<f(8);
21
click to copy
What is 'abbreviated function template' in C++20?
void f(auto x) — shorthand for template<typename T> void f(T x)
click to copy
What is the output: int f(int n,int k=1){return n?f(n-1,k*n):k;} cout<<f(5);
120
click to copy
What is the output: int f(int n){return n==1?1:f(n/2)+(n%2);} cout<<f(7);
3
click to copy
What is 'std::compose' equivalent in C++?
Not standard; use lambda chaining
click to copy
What is the output: int (*fp[3])(int)={[](int x){return x;}, [](int x){return x*2;}, [](int x){return x*3;}}; cout<<fp[2](5);
15
click to copy
What is the output: int f(int x){return x*(x+1)*(x+2)/6;} cout<<f(4);
20
click to copy
'What is the output: int a=0; auto inc=[&](){a++;}; auto dec=[&](){a (1, 6, 75, 5, 4, 'What is the output: auto square=[](auto x){return x*x;}; cout<<square(4)<<square(1.5);', 'Generic square lambda?', '162.25', '162.25', 'Compile error', 'Compile error', 'Undefined', 'Undefined', '16 2.25', '16 2.25', NULL, 'option_a', 'square(4)=16
result=91. f(99)=91. Output: 91.', 0, '2026-05-25', '2026-05-25'), (1, 6, 75, 5, 4, 'What is the output: int f(int x){return x?f(x>>1)*2+(x&1):0;} cout<<f(10);', 'f reconstructs value?', '10', '10', '5', '5', 'Compile error', 'Compile error', 'Undefined', 'Undefined', NULL, 'option_a', 'f(10): rebuilds bits: f(10)=f(5)*2+0=10. Output: 10.', 0, '2026-05-25', '2026-05-25'), (1, 6, 75, 5, 4, 'What is the output: int f(int a,int b){return b?f(b,a%b):a;} cout<<f(100,75);', 'GCD(100,75)?', '25', '25', '75', '75', 'Compile error', 'Compile error', 'Undefined', 'Undefined', NULL, 'option_a', 'GCD(100,75)=GCD(75,25)=GCD(25,0)=25. Output: 25.', 0, '2026-05-25', '2026-05-25'), (1, 6, 75, 5, 4, 'What is the output: auto f=[]<typename T>(T x){return x+x;}; cout<<f(5)<<f(string("ab"));', 'C++20 template lambda?', '10ab', '10ab', 'Compile error', 'Compile error', 'Undefined', 'Undefined', '10abab', '10abab', NULL, 'option_d', 'C++20 template lambda: f(5)=10
click to copy
What is the output: auto square=[](auto x){return x*x;}; cout<<square(4)<<square(1.5);
162.25
click to copy
What is the output: int f(int x){if(x>100) return x-10; return f(f(x+11));} cout<<f(99);
91
click to copy
What is the output: int f(int x){return x?f(x>>1)*2+(x&1):0;} cout<<f(10);
10
click to copy
What is the output: int f(int a,int b){return b?f(b,a%b):a;} cout<<f(100,75);
25
click to copy
What is the output: auto f=[]<typename T>(T x){return x+x;}; cout<<f(5)<<f(string("ab"));
10abab
click to copy

OOP Using C++ → Arrays 5

What is the output: int a[]={1,2,3,4,5}; cout<<a[0]+a[4];
6
click to copy
What is the output: int a[5]={1,2}; cout<<a[3];
0
click to copy
What is the output: int a[]={1,2,3}; cout<<sizeof(a);
12
click to copy
What is the output: int a[3]; fill(begin(a),end(a),7); cout<<a[1];
7
click to copy
What is the output: int a[]={5,4,3,2,1}; stable_sort(a,a+5); cout<<a[2];
3
click to copy