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 1

What is the output: int f(int x){if(x<0)return f(-x); return x<10?x:f(x%10)+f(x/10);} cout<<f(-123);
6
click to copy

OOP Using C++ → Arrays 37

What is the output: int a[]={1,2,3,4,5}; auto sum=accumulate(begin(a),end(a),0); cout<<sum;
15
click to copy
What is the output: int a[]={3,1,4,1,5,9}; sort(begin(a),end(a)); cout<<a[2]<<a[5];
49
click to copy
What is the output: vector<int> v={1,2,3,4,5}; auto it=v.begin()+2; v.insert(it,10); cout<<v[2]<<v[3];
103
click to copy
What is the output: int a[]={1,2,3,4,5}; int s=0; for(auto p=a;p!=a+5;++p) s+=*p; cout<<s;
15
click to copy
What is the output: vector<int> v={5,3,8,1,9,2,7}; sort(v.begin(),v.end()); cout<<v[3];
5
click to copy
What is the output: int a[5]={1,2,3,4,5}; rotate(a,a+1,a+5); cout<<a[0]<<a[4];
21
click to copy
What is the output: int a[]={1,2,3,4,5}; reverse(a,a+5); cout<<a[0]<<a[2]<<a[4];
531
click to copy
What is the output: vector<int> v={1,1,2,2,3,3,4}; cout<<unique(v.begin(),v.end())-v.begin();
4
click to copy
What is the output: int a[]={1,2,3,4,5}; int b[5]; copy_n(rbegin(a),5,b); cout<<b[0];
5
click to copy
What is the output: int a[]={1,2,3,4,5}; cout<<*min_element(a,a+5)+*max_element(a,a+5);
6
click to copy
What is the output: vector<int> v={3,1,4,1,5,9,2,6}; sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); cout<<v.size();
6
click to copy
What is the output: int a[]={1,2,3,4,5}; cout<<accumulate(a,a+5,1,multiplies<int>());
120
click to copy
What is the output: int a[]={1,2,3}; int b[]={4,5,6}; cout<<inner_product(a,a+3,b,0);
32
click to copy
What is the output: array<int,5> a={5,4,3,2,1}; sort(a.begin(),a.end()); cout<<a[0]<<a[4];
15
click to copy
What is the output: int a[]={1,2,3,4,5}; cout<<count_if(a,a+5,[](int x){return x*x>10;});
3
click to copy
What is the output: int a[]={2,4,6,8,10}; auto it=lower_bound(a,a+5,7); cout<<*it;
8
click to copy
What is the output: vector<int> v={1,2,3,4,5}; v.resize(3); cout<<v.size()<<v.back();
33
click to copy
What is the output: int a[]={1,2,3,4,5}; partial_sort(a,a+3,a+5,greater<int>()); cout<<a[0]<<a[1]<<a[2];
543
click to copy
What is the output: vector<int> v(10); iota(v.begin(),v.end(),1); cout<<v[0]<<v[9];
19
click to copy
What is the output: int a[]={1,2,3,4,5}; replace_if(a,a+5,[](int x){return x%2==0;},0); for(int x:a) cout<<x;
10304
click to copy
What is the output: int a[]={1,2,3,4,5}; int n=remove_if(a,a+5,[](int x){return x%2==0;})-a; cout<<n;
3
click to copy
What is the output: int a[]={5,3,8,1,4}; make_heap(a,a+5); cout<<a[0];
8
click to copy
What is the output: int a[]={1,2,3,4,5}; for_each_n(a,3,[](int& x){x*=2;}); cout<<a[0]<<a[1]<<a[2]<<a[3];
2 4 6 4
click to copy
What is the output: vector<int> v={1,2,3}; auto w=v; reverse(w.begin(),w.end()); cout<<(v==w);
0
click to copy
What is the output: int a[]={1,2,3,4,5}; cout<<*(max_element(a,a+5)-1);
4
click to copy
What is the output: int a[10]={0}; fill_n(begin(a),5,1); cout<<count(begin(a),end(a),1)<<count(begin(a),end(a),0);
50
click to copy
What is the output: vector<int> v={1,2,3,4,5}; v.erase(v.begin(),v.begin()+2); cout<<v[0]<<v.size();
33
click to copy
What is the output: int a[]={1,2,3,4,5}; cout<<reduce(begin(a),end(a));
15
click to copy
What is the output: int a[5]={0}; transform(a,a+5,a,[n=1](int)mutable{return n++;});for(int x:a) cout<<x;
12345
click to copy
What is 'std::views::as_rvalue' (C++23)?
Creates a view that moves elements instead of copying
click to copy
What is the output: array<int,5> a; iota(a.begin(),a.end(),1); cout<<ranges::fold_left(a,0,plus<>{});
15
click to copy
What is the output: int a[]={1,2,3,4,5}; cout<<accumulate(rbegin(a),rend(a),0);
15
click to copy
What is the output: vector<int> v={2,4,6,8,10}; transform(v.begin(),v.end(),v.begin(),[](int x){return x/2;}); cout<<v[0]<<v[4];
15
click to copy
What is the output: int a[]={3,1,4,1,5}; bool r=is_partitioned(a,a+5,[](int x){return x>2;}); cout<<r;
0
click to copy
What is the output: int a[]={5,3,1,4,2}; sort(a,a+5); cout<<binary_search(a,a+5,3);
1
click to copy
What is the output: int a[]={1,2,3,4,5}; cout<<*(find_if(a,a+5,[](int x){return x>3;}))+1;
5
click to copy
What is the output: int a[]={1,2,3,4,5}; cout<<equal_range(a,a+5,3).second-equal_range(a,a+5,3).first;
1
click to copy

OOP Using C++ → Pointers 2

What is the output: int a[]={1,2,3,4,5}; int *p=&a[2]; cout<<p[-2]<<p[2];
15
click to copy
What is the output: int x=5; auto* p=new auto(x*2); cout<<*p; delete p;
10
click to copy