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++ → Introduction to C++ 1

What is the output: optional<int> o=5; cout<<o.value_or(0)<<(!o?0:*o);
55
click to copy

OOP Using C++ → Variables and Data Types 34

What is the output: int x=5; auto& r=x; const auto& cr=x; cout<<r<<cr;
55
click to copy
What is the output: volatile int x=5; cout<<x;
5
click to copy
What is the output: const int x=5; auto y=x; y=10; cout<<x<<y;
510
click to copy
What is the output: int x=5; decltype(auto) r=x; r=10; cout<<x;
10
click to copy
What is the output: int x=5,y=10; auto [a,b]=make_pair(x,y); a=99; cout<<x<<b;
510
click to copy
What is the output: int x=5; int& r=x; auto y=r; y=99; cout<<x;
5
click to copy
What is the output: char c='A'; int x=c; cout<<x;
65
click to copy
What is the output: bool b=false; int x=b+b+b; cout<<x;
0
click to copy
What is the output: int x=INT_MAX-1; x+=2; cout<<x;
Undefined behavior
click to copy
What is the output: unsigned x=1; cout<<(x-2);
4294967295
click to copy
What is the output: int x=5; auto* p=&x; auto q=p; cout<<*q;
5
click to copy
What is the output: int x=5; const int& r=x+1; cout<<r;
6
click to copy
What is the output: int x=42; void* p=&x; cout<<*static_cast<int*>(p);
42
click to copy
What is the output: double d=1.23456789; cout<<fixed<<setprecision(4)<<d;
1.2346
click to copy
What is the output: float f=1.0f/3.0f; cout<<(f==1.0f/3.0f);
1
click to copy
What is the output: int x=5; cout<<typeid(x+0.0).name();
d
click to copy
What is the output: int a=5,b=3; cout<<max(a,b)<<min(a,b)<<(a/b);
531
click to copy
What is the output: int x=10; int y=x; x=20; cout<<y;
10
click to copy
What is the output: auto x=1+2u; cout<<sizeof(x);
4
click to copy
What is the output: enum E{A=1,B=2,C=4}; cout<<(A|B|C);
7
click to copy
What is the output: int x=5; cout<<sizeof(x==5);
1
click to copy
What is the output: wchar_t w=L'A'; cout<<(wchar_t)(w+1);
B
click to copy
What is the output: int x=0; cout<<(x++==0)<<(x++==1)<<(x++==2);
111
click to copy
What is the output: long double ld=1.0L/3.0L; cout<<(ld>1.0/3.0);
1
click to copy
What is the output: int x=5; cout<<(x,x+1,x+2);
7
click to copy
What is the output: char s[6]="hello"; cout<<strlen(s);
5
click to copy
What is the output: int x=100; cout<<(x/=3)<<x;
3333
click to copy
What is the output: double x=2.5; int y=x; double z=y; cout<<(x==z);
0
click to copy
What is the output: int x=5; cout<<(+x)<<(-x)<<(~x)<<(!x);
5-5-60
click to copy
What is the output: int x=15; cout<<hex<<x<<' '<<oct<<x<<' '<<dec<<x;
f 17 15
click to copy
What is the output: string s="12345"; int x=stoi(s); cout<<x*2;
24690
click to copy
What is the output: int x=5; int* p=nullptr; p=&x; cout<<(p?*p:-1);
5
click to copy
What is the output: auto x=5; auto y=5.0; cout<<(x==y);
1
click to copy
What is the output: int x=5; int y=x++; int z=++x; cout<<x<<y<<z;
776
click to copy

OOP Using C++ → Operators in C++ 5

What is the output: int x=5,y=3; cout<<(x>y)<<(x<y)<<(x>=y)<<(x<=y)<<(x==y)<<(x!=y);
101001
click to copy
What is the output: int x=5; x=x>3?x+1:x-1; x=x>5?x*2:x+3; cout<<x;
9
click to copy
What is the output: int a=10,b=3; cout<<(a/b*b+a%b);
10
click to copy
What is the output: int x=5; cout<<(x<<2)+(x>>2);
21
click to copy
What is the output: int x=0b11111111; cout<<(x&0x55)+(x&0xAA);
255
click to copy