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=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
C++ placement new syntax:
new(ptr) T(args);
click to copy
What is the output: int* arr=new int[5]{1,2,3,4,5}; cout<<arr[2]; delete[] arr;
3
click to copy
The output of: auto ptr=make_unique<int[]>(5); ptr[2]=42; cout<<ptr[2];
42
click to copy
The output of: auto sp=make_shared<int>(10); auto sp2=sp; *sp=20; cout<<*sp2;
20
click to copy
The output of: auto sp=make_shared<int>(5); weak_ptr<int> wp=sp; sp.reset(); cout<<wp.expired();
1
click to copy
What is the output: auto sp=make_shared<int>(42); cout<<sp.use_count();
1
click to copy
The output of: auto sp=make_shared<int>(42); auto sp2=sp; cout<<sp.use_count();
2
click to copy
The output of: thread t1([]{cout<<"A";}); thread t2([]{cout<<"B";}); t1.join(); t2.join(); output is:
AB or BA (non-deterministic)
click to copy
What is the output: atomic<int> x=0; thread t1([&]{for(int i=0;i<1000;i++)x++;}); thread t2([&]{for(int i=0;i<1000;i++)x++;}); t1.join(); t2.join(); cout<<x;
2000
click to copy
Without atomic, same code above would give:
Undefined behavior (race condition on non-atomic x)
click to copy
std::mutex::lock() blocks until:
Mutex is acquired (other thread releases it)
click to copy
std::try_lock() differs from lock() in:
try_lock returns immediately (true if acquired, false if not)
click to copy
The output of: mutex m; int x=0; thread t([&]{lock_guard<mutex> lg(m); x=42;}); t.join(); cout<<x;
42
click to copy
Condition variable wait(lock, predicate) returns when:
Predicate returns true (spurious wakeups handled)
click to copy
std::call_once guarantees:
Function called exactly once across all threads
click to copy
What is the output: promise<int> p; future<int> f=p.get_future(); thread t([&p]{p.set_value(42);}); t.join(); cout<<f.get();
42
click to copy
The output of: auto f=async(launch::async,[]{return 42;}); cout<<f.get();
42
click to copy
The output of: packaged_task<int()> pt([](){return 99;}); auto f=pt.get_future(); pt(); cout<<f.get();
99
click to copy
What is the output: int x=5; auto f=[x=x*2]{return x;}; cout<<f();
10
click to copy
Init captures in C++14 lambda [y=expr]:
Capture and initialize new variable y with expr
click to copy
The output of: auto f=[i=0]()mutable{return i++;}; cout<<f()<<f()<<f();
012
click to copy
What is the output: vector<int> v(10); iota(v.begin(),v.end(),1); auto sum=reduce(execution::par,v.begin(),v.end()); cout<<sum;
55
click to copy
The output of: auto v=views::iota(1,6)|views::filter([](int x){return x%2!=0;}) |views::transform([](int x){return x*x;}); for(auto x:v)cout<<x<<" ";
1 9 25
click to copy
The output of: namespace A{int x=1;} namespace B{int x=2;} cout<<A::x<<B::x;
12
click to copy
The output of: namespace A{void f(){cout<<"A";}} namespace B{void f(){cout<<"B";}} using namespace A; f();
A
click to copy