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.

Data Structures and Algorithms → Introduction to DSA 40

The output of: int x=5; auto l=coroutine_not_shown; cout<<x; in non-coroutine context:
5
click to copy
Which C++20 concept checks if type T has operator<< for ostream?
Must define custom concept or use std::formattable
click to copy
The output of: for(int i=2;i<=20;i+=2) cout<<i<<" "; number of outputs:
10
click to copy
The output of: int n=1000; for(;n>1;n/=10) cout<<n%10; cout<<n;
001
click to copy
What is the output: int arr[]={10,20,30}; for(int &x:arr) x*=2; cout<<arr[1];
40
click to copy
The output of: string words[]={"hello","world","foo"}; sort(words,words+3); cout<<words[0];
foo
click to copy
The output of: vector<string> v={"c","a","b"}; sort(v.begin(),v.end()); cout<<v[0]<<v[2];
ac
click to copy
What is the output: auto it=max_element(begin("abcZ"),end("abcZ")-1); cout<<*it;
c
click to copy
The output of: int n=7; int sum=0; for(int i=2;i<=n/2;i++) if(n%i==0){sum=1; break;} cout<<(sum?"Composite":"Prime");
Prime
click to copy
The output of: int n=12; int sum=0; for(int i=2;i<=n/2;i++) if(n%i==0){sum=1; break;} cout<<(sum?"Composite":"Prime");
Composite
click to copy
What is the output: struct Pt{int x,y; Pt(int x,int y):x(x),y(y){} double dist(){return sqrt(x*x+y*y);}}; Pt p(3,4); cout<<p.dist();
5
click to copy
The output of: class Ctr{int n=0; public: void inc(){n++;} int get(){return n;} }; Ctr c; c.inc(); c.inc(); c.inc(); cout<<c.get();
3
click to copy
The output of: class Box{double l,w,h; public: Box(double a,double b,double c):l(a),w(b),h(c){} double vol(){return l*w*h;} }; Box b(2,3,4); cout<<b.vol();
24
click to copy
The output of: class Vec{int x,y; public: Vec(int a,int b):x(a),y(b){} Vec operator+(Vec v){return Vec(x+v.x,y+v.y);} void print(){cout<<x<<","<<y;} }; Vec a(1,2),b(3,4); (a+b).print();
4,6
click to copy
The output of: class A{public:int x; A(int x):x(x){}}; class B:public A{public:B(int x):A(x){}}; B b(42); cout<<b.x;
42
click to copy
The output of: class A{public:virtual int f(){return 1;}}; class B:public A{public:int f()override{return 2;}}; class C:public B{public:int f()override{return 3;}}; A*p=new C; cout<<p->f();
3
click to copy
The output of: class A{public:int f(){return 1;} virtual int g(){return 10;}}; class B:public A{public:int f(){return 2;} int g()override{return 20;}}; A*p=new B; cout<<p->f()<<p->g();
1 20
click to copy
The output of: template<class T> T min3(T a,T b,T c){return a<b?(a<c?a:c):(b<c?b:c);} cout<<min3(3,1,2);
1
click to copy
The output of: vector<int> v={5,2,8,1,9}; auto comp=[](int a,int b){return a>b;}; sort(v.begin(),v.end(),comp); cout<<v[0];
9
click to copy
The output of: map<int,string> m={{1,"one"},{2,"two"},{3,"three"}}; for(auto &[k,v]:m) cout<<v[0]; (first char of each value)
ott
click to copy
The output of: auto v=vector{3,1,4,1,5,9,2,6}; ranges::sort(v); cout<<v[0]<<v[7];
19
click to copy
The output of: auto r=views::iota(1)|views::take(5); for(auto x:r)cout<<x;
12345
click to copy
The output of: int n=100; auto isprime=[](int n){for(int i=2;i*i<=n;i++) if(n%i==0)return false; return n>1;}; auto primes=views::iota(2)|views::filter(isprime)|views::take(5); cout<<ranges::distance(primes);
5
click to copy
The output of: expected<int,string> e=42; cout<<e.value();
42
click to copy
The output of: expected<int,string> e=unexpected("error"); cout<<e.has_value();
0
click to copy
What is the output: int x=5; auto f=[x=move(x)](){return x;}; cout<<f()<<x;
50
click to copy
The output of: string s1="Hello"; string s2=move(s1); cout<<s1.size()<<s2.size();
0 5
click to copy
The output of: vector<int> v1={1,2,3}; vector<int> v2=move(v1); cout<<v1.size()<<v2.size();
0 3
click to copy
The output of: unique_ptr<int> p=make_unique<int>(42); unique_ptr<int> q=move(p); cout<<(p?"has":"null")<<(q?"has":"null");
nullhas
click to copy
The output of: shared_ptr<int> sp=make_shared<int>(10); { shared_ptr<int> sp2=sp; cout<<sp.use_count(); } cout<<sp.use_count();
2 1
click to copy
What is the output: int x=5; decltype(x) y=10; cout<<y;
10
click to copy
The output of: auto f(int x,int y)->int{return x+y;} cout<<f(3,4);
7
click to copy
The output of: int x=10; int y=[&]{return x*2;}(); cout<<y;
20
click to copy
The output of: constexpr auto factorial=[](auto self,int n)->int{return n<=1?1:n*self(self,n-1);}; cout<<factorial(factorial,6);
720
click to copy
The output of: struct A{int x; auto getX(){return x;}}; A a{42}; cout<<a.getX();
42
click to copy
The output of: int arr[]={1,2,3,4,5}; span<int> s(arr,3); cout<<s[2];
3
click to copy
The output of: span<int> s={1,2,3,4,5}; cout<<s.front()<<" "<<s.back();
1 5
click to copy
The output of: array<int,5> a={5,3,1,4,2}; sort(a.begin(),a.end()); cout<<a[0]<<a[4];
15
click to copy
The output of: map<int,int> m={{1,1},{2,4},{3,9}}; auto it=m.lower_bound(2); cout<<it->first<<it->second;
24
click to copy
The output of: set<int> s={1,3,5,7,9}; auto it=s.upper_bound(5); cout<<*it;
7
click to copy