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 n; cin>>n; cout<<(n%15==0?"FizzBuzz":n%3==0?"Fizz":n%5==0?"Buzz":to_string(n)); with n=15:
FizzBuzz
click to copy
FizzBuzz for n=9 outputs:
Fizz
click to copy
FizzBuzz for n=10 outputs:
Buzz
click to copy
FizzBuzz for n=7 outputs:
7
click to copy
The output of: int n=4; int count=0; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j) count++; cout<<count;
12
click to copy
The output of: string s="aabbcc"; map<char,int> m; for(char c:s) m[c]++; for(auto [k,v]:m) if(v==1) cout<<k; if there were unique chars
No output (all appear twice)
click to copy
The output of: int arr[]={1,2,3,4,5}; cout<<*prev(end(arr));
5
click to copy
The output of: vector<int> v={1,2,3}; v.insert(v.end(),{4,5,6}); cout<<v.size();
6
click to copy
The output of: array<int,5> a={1,2,3,4,5}; cout<<a.back();
5
click to copy
The output of: array<int,5> a; a.fill(7); cout<<a[2];
7
click to copy
The output of: bitset<8> bs(170); cout<<bs;
10101010
click to copy
The output of: bitset<8> bs("10110100"); cout<<bs.count();
4
click to copy
bitset::flip() does:
Flips all bits (0 to 1 and 1 to 0)
click to copy
The output of: bitset<4> a("1010"), b("1100"); cout<<(a&b);
1000
click to copy
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(15,1,10);
10
click to copy
The output of: cout<<clamp(-5,1,10);
1
click to copy
The output of: cout<<clamp(7,1,10);
7
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