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: bitset<4> a("1010"), b("1100"); cout<<(a|b);
1110
click to copy
The output of: bitset<4> a("1010"), b("1100"); cout<<(a^b);
0110
click to copy
What is the output: bitset<8> bs(42); cout<<bs.to_string();
00101010
click to copy
The output of: cout<<bitset<8>(0xFF);
11111111
click to copy
The output of: vector<int> v(5); generate(v.begin(),v.end(),[n=0]()mutable{return n++;} ); cout<<v[3];
3
click to copy
The output of: int x=0; function<int(int)> f=[&](int n){return n<=0?x:(x+=n,f(n-1));}; cout<<f(5);
15
click to copy
What is the output: struct A{int x; A(int x):x(x){} A(A&&a):x(move(a.x)){cout<<"M";} }; A a(1); A b(move(a));
M printed
click to copy
What is the output: int x=10; auto f=[=]()mutable->int&{return x;}; f()=20; cout<<x;
10
click to copy
The output of: int x=10; auto f=[&x]()->int&{return x;}; f()=20; cout<<x;
20
click to copy
The output of: class C{public:int operator()(int x){return x*x;} }; C sq; cout<<sq(5)<<sq(sq(2));
2516
click to copy
What is the output: auto curry=[](int a){return [a](int b){return a+b;};};cout<<curry(3)(4);
7
click to copy
What is currying in functional programming?
Transforming multi-argument function into sequence of single-argument functions
click to copy
The output of: vector<int> v={1,2,3,4,5}; auto it=partition(v.begin(),v.end(),[](int x){return x%2==0;}); cout<<distance(v.begin(),it);
2
click to copy
The output of: vector<int> v={1,2,3,4,5}; rotate(v.begin(),v.begin()+3,v.end()); for(auto x:v)cout<<x;
45123
click to copy
The output of: int arr[]={3,1,4,1,5}; cout<<*max_element(arr,arr+5)<<" "<<*min_element(arr,arr+5);
5 1
click to copy
The output of: int a=5,b=3; cout<<max({a,b,a+b,a*b,a-b});
15
click to copy
The output of: cout<<clamp(1,10);
10
click to copy
The output of: cout<<clamp(-5,1,10);
1
click to copy
The output of: int a=3,b=5; cout<<(a<b?a:b)<<" "<<(a>b?a:b);
3 5
click to copy
What is the output: int n=10; int bits=0; while(n){bits+=(n&1); n>>=1;} cout<<bits;
2
click to copy
What is the output: cout<<(17>>1)<<" "<<(17<<1);
8 34
click to copy
The output of: int x=5; cout<<(x&-x);
1
click to copy
What does x&-x compute?
Lowest set bit of x
click to copy
What is the output: cout<<(__builtin_ctz(12));
2
click to copy
__builtin_ctz computes:
Count trailing zero bits
click to copy
The output of: int n=256; cout<<__builtin_ctz(n);
8
click to copy
What is the output: auto [mn,mx]=minmax({5,3,8,1,9,2}); cout<<mn<<" "<<mx;
1 9
click to copy
The output of: vector<int> v={2,3,5,7,11}; cout<<v.end()[-1];
11
click to copy
The output of: string s="abcde"; cout<<s.substr(s.size()-3);
cde
click to copy
The output of: string s="Hello, World!"; cout<<s.rfind("l");
10
click to copy
The output of: int arr[]={1,2,3,4,5}; partial_sort(arr,arr+3,arr+5); cout<<arr[0]<<arr[1]<<arr[2];
123
click to copy
The output of: int arr[]={5,1,4,2,8}; nth_element(arr,arr+2,arr+5); cout<<arr[2];
4
click to copy
The output of: vector<int> v={1,2,3,4,5}; auto res=adjacent_find(v.begin(),v.end(),[](int a,int b){return b==a+2;}); cout<<*res;
1
click to copy
The output of: vector<int> v={1,2,3,2,1}; cout<<is_palindrome_check; //if(v==vector<int>(v.rbegin(),v.rend())) cout<<"Yes"; else cout<<"No";
Yes
click to copy
The output of: int arr[5]={1,2,3,4,5}; reverse(arr,arr+5); cout<<arr[0]<<arr[4];
51
click to copy
What is the output: vector<int> v={3,1,4,1,5,9,2,6}; sort(v.begin(),v.end()); cout<<*(lower_bound(v.begin(),v.end(),5));
5
click to copy
The output of: int a=5,b=10; if(a>b) swap(a,b); cout<<a<<" "<<b;
5 10
click to copy
The output of: vector<int> v={1,2,3,4,5}; transform(v.begin(),v.end(),v.begin(),[](int x){return x*x;}); cout<<v[4];
25
click to copy
The output of: int arr[5]={10,20,30,40,50}; auto [mn,mx]=minmax_element(arr,arr+5); cout<<*mn<<" "<<*mx;
10 50
click to copy
The output of: vector<int> v={1,2,3,4,5}; cout<<reduce(v.begin(),v.end(),1,multiplies<int>());
120
click to copy