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++ → Templates 21

What is 'template template parameter'?
Parameter that is itself a template
click to copy
What is the output: template<int N> struct Fib{static const int v=Fib<N-1>::v+Fib<N-2>::v;}; template<> struct Fib<0>{static const int v=0;}; template<> struct Fib<1>{static const int v=1;}; cout<<Fib<7>::v;
13
click to copy
What is 'concept' constraint in C++20?
template<std::integral T> — constrains T to integral types
click to copy
What is the output: template<typename T> class A{public: static int c; A(){c++;}}; template<typename T> int A<T>::c=0; A<int> a,b; A<double> d; cout<<A<int>::c<<A<double>::c;
21
click to copy
What is 'parameter pack expansion'?
Using ... to expand variadic template parameters
click to copy
What is the output: template<typename T> T max(T a,T b){return a>b?a:b;} cout<<max<double>(3,4.5);
4.5
click to copy
What is 'template metaprogramming'?
Computations performed at compile time using templates
click to copy
What is the output: template<bool B,typename T=void> struct enable_if{}; template<typename T> struct enable_if<true,T>{typedef T type;}; enable_if<true,int>::type x=5; cout<<x;
5
click to copy
What is 'fold expression' in C++17?
Applying binary operator over parameter pack
click to copy
What is the output: template<typename... Args> int sum(Args... args){return (args+...);} cout<<sum(1,2,3,4,5);
15
click to copy
What is 'type trait' in C++?
Compile-time type information query
click to copy
What is the output: cout<<is_same<int,int>::value<<is_same<int,float>::value;
10
click to copy
What is 'CRTP' and static polymorphism?
Base<Derived> pattern enabling compile-time polymorphism
click to copy
What is the output: template<typename T> struct TypeName{static const char* name(){return "unknown";}}; template<> struct TypeName<int>{static const char* name(){return "int";}}; cout<<TypeName<int>::name()<<TypeName<double>::name();
intunknown
click to copy
What is the output: template<typename T,int N> struct Array{T data[N]; int size(){return N;}}; Array<int,5> a; cout<<a.size();
5
click to copy
What is 'class template' vs 'function template'?
Class template: parameterized class; function template: parameterized function
click to copy
What is the output: template<typename T> auto wrap(T t){return [t](){return t;};} auto f=wrap(42); cout<<f();
42
click to copy
What is 'deduction guide' in C++17?
Explicit rules for class template argument deduction
click to copy
What is the output: template<typename T> constexpr T pi=T(3.1415926535); cout<<pi<int><<' '<<pi<double>;
3 3.14159
click to copy
What is the output: template<typename T> void f(T&&){cout<<'R';} template<typename T> void f(const T&){cout<<'L';} int x=5; f(x); f(5);
LR
click to copy
What is 'explicit instantiation' of templates?
Forcing compiler to instantiate specific template specialization
click to copy

OOP Using C++ → Introduction to C++ 19

What is the output: cout<<(1<<3)+(1<<2)+(1<<0);
13
click to copy
What is 'alignment' in C++?
Memory address constraint for a type
click to copy
What is the output: int x=5; cout<<(x>0)+(x>3)+(x>4)+(x>5);
3
click to copy
What does 'explicit' keyword prevent?
Implicit single-argument constructor conversion
click to copy
What is the output: int x=0xFF; cout<<(x>>4)&0xF;
15
click to copy
What is 'std::byte' vs unsigned char?
byte has no arithmetic; only bitwise ops; expresses intent
click to copy
What is the output: bool b; cout<<b;
Undefined behavior
click to copy
What is 'structured binding' for pair?
auto [first,second]=pair; decomposes into named vars
click to copy
What is the output: int x=7; cout<<(x&(x+1));
0
click to copy
What is 'std::endl' vs '\\n'?
endl flushes buffer; \\n does not
click to copy
What is the output: int x=10; while(x) {x>>=1;} cout<<x;
0
click to copy
What is 'extern' keyword for variables?
Declares variable defined elsewhere (no storage allocated)
click to copy
What is the output: int x=5; cout<<(x|(x<<1));
15
click to copy
What is 'address sanitizer'?
Runtime tool detecting memory errors (OOB, use-after-free)
click to copy
What is the output: for(int i=1;i<6;i++) cout<<(i*i-1)/(i+1)+1;
12345
click to copy
What is the output: int x=0; auto f=[&]{x=42;}; f(); cout<<x;
42
click to copy
What is 'std::as_const'?
Returns const reference to argument
click to copy
What is the output: int x=5; cout<<(-(-x));
5
click to copy
What is 'undefined behavior sanitizer'?
Runtime tool detecting UB (signed overflow, null deref, etc.)
click to copy