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: for(int i=0; i<3; i++) cout << i << ' '; cout << i;
Compile error
click to copy
What is the output: int i=1; for(; i; i (1, 6, 74, 4, 4, 'What is the output: try { throw 42; } catch(double d) { cout<<'D'; } catch(int i) { cout<<'I'; }
I
click to copy
What is the output: try { throw 42; } catch(double d) { cout<<'D'; } catch(int i) { cout<<'I'; }
I
click to copy
What is the output: int x=5; for(int i=0;i<x;x (1, 6, 74, 4, 4, 'What is 'if constexpr' in C++17?
A compile-time conditional that discards untaken branch
click to copy
What is 'if constexpr' in C++17?
A compile-time conditional that discards untaken branch
click to copy
What is the output: int i=0; for(i=0;i<5;++i) if(i==3) goto end; end: cout<<i;
3
click to copy
What is the output: for(int i=0,j=10; i<j; i++,j (1, 6, 74, 4, 4, 'What is the output: int x=2; switch(x){ case 1+1: cout<<'A'; break; case 2: cout<<'B'; break; }
Compile error
click to copy
What is the output: int x=2; switch(x){ case 1+1: cout<<'A'; break; case 2: cout<<'B'; break; }
Compile error
click to copy
What is the output: int x=5; if(x) { int x=10; cout<<x; } cout<<x;
105
click to copy

OOP Using C++ → Functions 31

What is the output: int f(int x=1,int y=2){ return x+y; } cout<<f()<<f(3)<<f(3,4);
357
click to copy
What is the output: void f(int& x){ x=10; } int a=5; f(a); cout<<a;
10
click to copy
What is 'function overload resolution' in C++?
Choosing the best matching overload at compile time
click to copy
What is a lambda closure in C++?
An anonymous function object that can capture local variables
click to copy
What is the output: int f(){ static int x=0; return ++x; } cout<<f()<<f()<<f();
Unspecified
click to copy
What is 'tail call optimization'?
Reusing the caller's stack frame for a tail-recursive call
click to copy
What is the output: auto add=[](int a,int b){return a+b;}; cout<<add(3,4);
7
click to copy
What is the difference between pass-by-value and pass-by-reference?
Pass-by-value copies; pass-by-reference accesses original
click to copy
What is the output: int f(int n){ return n<=1?1:n*f(n-1); } cout<<f(5);
120
click to copy
What is 'SFINAE' in C++?
Substitution Failure Is Not An Error
click to copy
What is the output: void f(int x){ cout<<x; } void f(double x){ cout<<x; } f(1.0f);
1.0
click to copy
What is the output: int f(int n){ if(n==0) return 0; return f(n-1)+1; } cout<<f(5);
5
click to copy
What is a 'variadic template' in C++?
A template with variable number of type parameters
click to copy
What is the output: int f(int x){ return x*2; } int(*fp)(int)=f; cout<<fp(5);
10
click to copy
What is 'RVO' (Return Value Optimization)?
Optimization that avoids copying return value
click to copy
What is the output: int f(int& a, int b){ a=10; return a+b; } int x=5; cout<<f(x,x);
15
click to copy
What is the output: auto f=[](auto x){ return x*2; }; cout<<f(5)<<f(2.5);
105
click to copy
What happens when a function returns a reference to a local variable?
Undefined behavior (dangling reference)
click to copy
What is the output: int f(){ return 1; } int g(){ return 2; } cout<<f()+g();
3
click to copy
What is 'perfect forwarding' in C++?
Passing arguments preserving their value category (lvalue/rvalue)
click to copy
What is the output: void f(int x){ x=100; } int a=5; f(a); cout<<a;
5
click to copy
What is the output: int f(int n){ return n?n+f(n-1):0; } cout<<f(4);
10
click to copy
What is 'memoization' in the context of recursive functions?
Caching results of function calls
click to copy
What is the output: int x=10; auto f=[&](){ return ++x; }; cout<<f()<<f();
Unspecified
click to copy
What is 'noexcept' specifier in C++?
Guarantees function throws no exceptions
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: void f(int* p){ *p=20; } int a=10; f(&a); cout<<a;
20
click to copy
What is the output: int f(int n){ return n>0?f(n/2)+1:0; } cout<<f(8);
3
click to copy
What is 'function template argument deduction'?
Compiler deducing template args from function arguments
click to copy
What is the output: int f(int x){ return x; } double f(double x){ return x; } cout<<f(1);
1
click to copy
What is the output: auto f=[]()mutable{ static int x=0; return x++; }; cout<<f()<<f()<<f();
Unspecified
click to copy