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++ → Control Statements 9

What is the output: int s=0; for(int i=1;i<=10;i+=2) s+=i; cout<<s;
25
click to copy
What is the output: if constexpr(2+2==4) cout<<'T'; else cout<<'F';
T
click to copy
What is the output: int x=10; while(x>0) {x=(x%3==0)?x-3:x-1;} cout<<x;
0
click to copy
What is the output: for(int i=0;i<10;i++) if((i%2==0)&&(i%3==0)) cout<<i;
06
click to copy
What is the output: int x=5; switch(x%3){case 0:cout<<'Z';break; case 1:cout<<'O';break; case 2:cout<<'T';break;}
T
click to copy
'What is the output: int n=5,f=1; for(int i=n;i>1;i (1, 6, 74, 4, 4, 'What is the output: for(int i=1;i<=5;i++) if(i==3) continue; else cout<<i;', 'Print 1-5 skip 3?', '1245', '1245', '12345', '12345', 'Compile error', 'Compile error', 'Undefined', 'Undefined', NULL, 'option_a', 'i=3: continue (skip else). Others: print. Output: 1245.', 0, '2026-05-25', '2026-05-25'), (1, 6, 74, 4, 4, 'What is the output: int x=1; for(int i=0;i<5;i++) x*=(i+1); cout<<x;', 'Product 1*2*3*4*5?', '120', '120', '15', '15', 'Compile error', 'Compile error', 'Undefined', 'Undefined', NULL, 'option_a', '5!=120. Output: 120.', 0, '2026-05-25', '2026-05-25'), (1, 6, 74, 4, 4, 'What is the output: int x=0; for(int i=0;i<5;i++) if(i%3) x+=i; cout<<x;', 'Sum where i%3!=0?', '1 2 4', '1 2 4', '7', '7', 'Compile error', 'Compile error', 'Undefined', 'Undefined', NULL, 'option_b', 'i=1:1
i=4:4. Sum=1+2+4=7. Output: 7.', 0, '2026-05-25', '2026-05-25'), (1, 6, 75, 5, 4, 'What is the output: int f(int n){return n<=0?0:n+f(n-2);} cout<<f(5)+f(6);', 'f(5)=5+3+1=9
click to copy
What is the output: for(int i=1;i<=5;i++) if(i==3) continue; else cout<<i;
1245
click to copy
What is the output: int x=1; for(int i=0;i<5;i++) x*=(i+1); cout<<x;
120
click to copy
What is the output: int x=0; for(int i=0;i<5;i++) if(i%3) x+=i; cout<<x;
7
click to copy

OOP Using C++ → Functions 31

What is the output: int f(int n){return n<=0?0:n+f(n-2);} cout<<f(5)+f(6);
21
click to copy
What is the output: auto f=[](int x)->int{return x>1?x*f(x-1):1;}; cout<<f(4);
Compile error
click to copy
What is 'std::function' recursive pattern?
std::function<int(int)> f; f=[&f](int n){return n<=1?1:n*f(n-1);}
click to copy
What is the output: int f(int x){return x;} float f(float x){return x;} double f(double x){return x;} cout<<sizeof(f(1));
4
click to copy
What is the output: int f(int x,int y){return x*y;} int f(int x){return x*x;} cout<<f(4)<<f(3,4);
1612
click to copy
What is 'std::bind' placeholder _1?
First argument of the bound call forwarded to original position
click to copy
What is the output: template<typename F,typename T> T applyN(F f,T x,int n){return n?applyN(f,f(x),n-1):x;} cout<<applyN([](int x){return x*2;},1,5);
32
click to copy
What is the output: int f(int x){return x>0?f(x-1)+x:0;} int g(int y){return f(y)*2;} cout<<g(5);
30
click to copy
What is the output: auto f=[](auto self,int n,int acc)->int{return n?self(self,n-1,acc+n):acc;}; cout<<f(f,5,0);
15
click to copy
What is 'std::regular_invocable' concept?
Callable with args that also models equality_comparable on result
click to copy
What is the output: int sum=0; auto f=[&](auto self,int n)->void{if(n<=0)return;sum+=n;self(self,n-1);}; f(f,10); cout<<sum;
55
click to copy
What is the output: template<typename...Args> auto sumAll(Args...args){return (args+...);} cout<<sumAll(1,2,3,4,5);
15
click to copy
What is the output: int f(int x,int y=x){return x+y;}
Compile error
click to copy
What is the output: int f(int x){return x%2?f(x-1)+1:0;} cout<<f(7);
4
click to copy
What is the output: auto compose=[](auto f,auto g){return [=](auto x){return f(g(x));};}; auto fn=compose([](int x){return x+1;},[](int x){return x*2;}); cout<<fn(5);
11
click to copy
What is the output: int f(int x){return x<=1?x:f(x/2)+(f((x+1)/2))+(x%2-1)?0:0;} cout<<f(8);
8
click to copy
What is 'std::invoke_r' in C++23?
std::invoke with explicit return type conversion
click to copy
What is the output: int x=5; auto f=[x](int y){return x+y;}; auto g=f; cout<<g(3);
8
click to copy
What is the output: template<typename T> auto id(T&& x)->T&&{return forward<T>(x);} int a=5; cout<<id(a);
5
click to copy
What is the output: int f(int x){return x?f(x/2)*2+(x&1):0;} cout<<f(10);
10
click to copy
What is the output: auto fib=[]()->generator<int>{int a=0,b=1;for(;;){co_yield a;tie(a,b)=make_pair(b,a+b);}}; auto g=fib(); cout<<ranges::fold_left(g|views::take(8),0,plus<>{});
33
click to copy
What is the output: int f(int a,int b,int c){return (a>b?a:b)>c?(a>b?a:b):c;} cout<<f(3,7,5);
7
click to copy
What is 'std::execution::par_unseq'?
Parallel and vectorized algorithm execution
click to copy
What is the output: int f(int x){return x*(x+1)/2;} int g(int x){return f(x)-f(x/2);} cout<<g(10);
40
click to copy
What is the output: int f(int x,int n){return n?f(x,n-1)+x:0;} cout<<f(4,5);
20
click to copy
What is the output: int f(int x,int y){return x==0?y:f(x-1,y+1);} cout<<f(3,5);
8
click to copy
What is the output: template<auto N> struct Fact{static constexpr long long v=N*Fact<N-1>::v;}; template<> struct Fact<0>{static constexpr long long v=1;}; cout<<Fact<10>::v;
3628800
click to copy
What is the output: auto negate=[](auto f){return [=](auto...args){return !f(args...);};}; auto isEven=[](int x){return x%2==0;}; cout<<negate(isEven)(3);
1
click to copy
What is the output: int f(int x){return x%2?x:f(x/2);} cout<<f(12);
3
click to copy
What is the output: int f(int x){return x<10?f(x+1)+x:x;} cout<<f(5);
50
click to copy
What is the output: auto pipe=[](auto...fns){return [=](auto x){(...,(x=fns(x)));return x;};}; auto fn=pipe([](int x){return x+1;},[](int x){return x*2;},[](int x){return x-3;}); cout<<fn(5);
9
click to copy