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 3

What is the output: auto flip=[](auto f){return [=](auto a,auto b){return f(b,a);};}; auto sub=[](int a,int b){return a-b;}; cout<<flip(sub)(3,10);
7
click to copy
What is the output: int f(int n,int base){return n==0?0:n%base+f(n/base,base);} cout<<f(255,16);
15
click to copy
What is the output: auto f=[](auto& v,int l,int r)->void{if(l<r){int m=(l+r)/2;f(v,l,m);f(v,m+1,r);inplace_merge(v.begin()+l,v.begin()+m+1,v.begin()+r+1);}}; vector<int>v={5,3,8,1,4};f(v,0,4);for(int x:v)cout<<x;
13458
click to copy

OOP Using C++ → Arrays 33

What is the output: int a[]={1,2,3,4,5}; int s=0; for(int i=0;i<5;i+=2) s+=a[i]; cout<<s;
9
click to copy
What is the output: int a[]={3,1,4,1,5,9,2,6,5}; sort(a,a+9); cout<<a[4];
5
click to copy
What is the output: int a[]={1,2,3,4,5}; int *p=begin(a),*q=end(a)-1; cout<<*p+*q;
6
click to copy
What is the output: vector<int> v={1,2,3,4,5}; for(auto it=v.rbegin();it!=v.rend();++it) cout<<*it;
54321
click to copy
What is the output: int a[3][3]={{9,8,7},{6,5,4},{3,2,1}}; int s=0; for(int i=0;i<3;i++) s+=a[i][2-i]; cout<<s;
15
click to copy
What is the output: int a[]={2,3,5,7,11,13}; cout<<*upper_bound(a,a+6,7);
11
click to copy
What is the output: vector<int> v={5,3,8,1,9}; auto m=max_element(v.begin(),v.end()); *m=0; cout<<v[2];
8
click to copy
What is the output: int a[]={1,2,3,4,5}; cout<<accumulate(a,a+5,1,[](int p,int x){return p*x;});
120
click to copy
What is the output: string words[]={"","hello","","world",""}; int c=count_if(begin(words),end(words),[](const string&s){return !s.empty();});cout<<c;
2
click to copy
What is the output: int a[]={10,20,30,40,50}; transform(a,a+5,a,[](int x){return x/10;}); cout<<a[0]<<a[4];
15
click to copy
What is the output: int a[]={1,3,5,7,9}; cout<<*lower_bound(a,a+5,5);
5
click to copy
What is the output: int a[10]={0}; generate(a,a+10,[n=0]()mutable{return n+=2;}); cout<<a[4];
10
click to copy
What is the output: vector<int> a={1,2,3},b={4,5,6},c; merge(a.begin(),a.end(),b.begin(),b.end(),back_inserter(c)); cout<<c[3];
4
click to copy
What is the output: int a[]={5,4,3,2,1}; int b[5]; partial_sort_copy(a,a+5,b,b+5); cout<<b[0]<<b[4];
15
click to copy
What is the output: int a[]={1,2,3,4,5}; int* it=remove(a,a+5,3); cout<<distance(a,it);
4
click to copy
What is the output: int a[5]; fill_n(a,5,3); cout<<inner_product(a,a+5,a,0);
45
click to copy
What is the output: vector<pair<int,string>> v={{3,"c"},{1,"a"},{2,"b"}}; sort(v.begin(),v.end()); cout<<v[0].second<<v[2].second;
ac
click to copy
What is the output: int a[]={1,2,3,4,5}; cout<<is_sorted(a,a+5,greater<int>());
0
click to copy
What is the output: array<int,5> a; iota(a.begin(),a.end(),2); cout<<a[0]<<a[4];
26
click to copy
What is the output: int a[]={1,2,3,4,5}; copy_if(a,a+5,ostream_iterator<int>(cout,' '),[](int x){return x*x>8;});
3 4 5
click to copy
What is the output: int a[]={0,1,0,1,1,0}; cout<<count(a,a+6,1);
3
click to copy
What is the output: int a[]={1,2,3,4,5}; int b[]={5,4,3,2,1}; cout<<equal(a,a+5,b);
0
click to copy
What is the output: vector<int> v={1,2,3,4,5}; v.assign(3,9); cout<<v.size()<<v[0];
39
click to copy
What is the output: int a[]={2,4,8,16,32}; cout<<adjacent_find(a,a+5,[](int x,int y){return y!=x*2;})-a;
5
click to copy
What is the output: int a[]={1,2,3,4,5}; int s=transform_reduce(a,a+5,0,plus<>(),[](int x){return x%2;});cout<<s;
2
click to copy
What is the output: vector<int> v={1,2,3,4,5}; stable_partition(v.begin(),v.end(),[](int x){return x%2==0;}); cout<<v[0]<<v[4];
25
click to copy
What is the output: int a[]={3,3,3,3,3}; cout<<*min_element(a,a+5)<<*max_element(a,a+5);
33
click to copy
What is the output: vector<int> v={1,2,3,4,5}; rotate(v.begin(),v.end()-1,v.end()); cout<<v[0]<<v[4];
51
click to copy
What is the output: int a[]={5,4,3,2,1}; make_heap(begin(a),end(a),greater<int>()); cout<<a[0];
1
click to copy
What is the output: int a[]={1,2,3,4,5}; next_permutation(a,a+5); next_permutation(a,a+5); cout<<a[3]<<a[4];
45
click to copy
What is the output: vector<int> v={1,2,2,3,3,3}; map<int,int>freq; for(int x:v) freq[x]++; cout<<freq[3];
3
click to copy
What is the output: int a[]={1,2,3,4,5}; auto r=ranges::max_element(a); cout<<*r;
5
click to copy
What is the output: vector<int> v={1,2,3,4,5}; cout<<ranges::fold_left(v,1,multiplies<>{});
120
click to copy

OOP Using C++ → Pointers 4

What is the output: int a[]={1,2,3,4,5}; int *p=a+2,*q=a; cout<<p-q<<*(q+p-a-2);
23
click to copy
What is the output: int x=5; int *p=&x; auto f=[p]()->int{return *p*2;}; cout<<f();
10
click to copy
What is the output: int a[]={1,2,3}; cout<<(*(a+0)+*(a+1)+*(a+2));
6
click to copy
What is the output: int x=5; int *p=&x; *p+=*p; cout<<x;
10
click to copy