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++ → Variables and Data Types 17

What is the output: int x=5; auto p=reinterpret_cast<char*>(&x); cout<<(int)*p;
5
click to copy
What is 'std::is_standard_layout'?
Type compatible with C struct layout
click to copy
What is the output: struct A{int x; double y;}; cout<<is_standard_layout_v<A>;
1
click to copy
What is 'std::has_unique_object_representations'?
True if type has unique bit pattern per value (no padding bits)
click to copy
What is the output: cout<<has_unique_object_representations_v<int><<has_unique_object_representations_v<float>;
10
click to copy
What is 'std::integer_sequence' usage pattern?
index_sequence used to unpack tuples in templates
click to copy
What is the output: using IS=index_sequence<0,1,2>; cout<<IS::size();
3
click to copy
What is 'std::bool_constant'?
Alias for integral_constant<bool,B>
click to copy
What is the output: cout<<is_same_v<bool_constant<true>,true_type>;
1
click to copy
What is 'std::conjunction' and 'std::disjunction'?
Short-circuit logical AND/OR on type traits
click to copy
What is the output: cout<<conjunction_v<true_type,true_type,false_type><<disjunction_v<false_type,true_type>;
01
click to copy
What is 'std::make_signed' and 'std::make_unsigned'?
Convert integer type to signed/unsigned equivalent
click to copy
What is the output: cout<<is_same_v<make_unsigned_t<int>,unsigned int>;
1
click to copy
What is 'std::conditional_t'?
Selects T or F based on bool condition at compile time
click to copy
What is the output: using T=conditional_t<(sizeof(int)>2),int,short>; cout<<sizeof(T);
4
click to copy
What is 'std::void_t'?
Maps any types to void; used for SFINAE detection
click to copy
What is the output: int x=-5; cout<<(x>>1);
Implementation-defined
click to copy

OOP Using C++ → Operators in C++ 23

What is the output: int x=5; cout<<(x<=5&&x>=5);
1
click to copy
What is the output: int x=7; cout<<(x&0xF0)>>4;
0
click to copy
What is the output: int a=5,b=3; cout<<(a>b)-(a<b);
1
click to copy
What is 'operator<=> auto' return?
Compiler deduces comparison category from member comparisons
click to copy
What is the output: int x=5; x=x>3?(x<10?x*2:x):x/2; cout<<x;
10
click to copy
What is the output: int x=5,y=3; int z=x>y?x-y:y-x; cout<<z;
2
click to copy
What is the output: int x=5; cout<<(x*2>>1);
5
click to copy
What is the output: int x=0b1111; x&=0b1010; cout<<x;
10
click to copy
What is the output: int x=3; cout<<(x|=x<<1);
7
click to copy
What is the output: int x=5,y=5; cout<<(x^=y,y^=x,x^=y);
5
click to copy
What is the output: int x=5; cout<<(~x+1);
-5
click to copy
What is the output: int x=10; cout<<(x&1?'O':'E')<<(x>>1);
E5
click to copy
What is the output: int a=5,b=10; a^=b^=a^=b; cout<<a<<b;
Compile error
click to copy
What is the output: int x=100; cout<<(x/=10/=1);
Compile error
click to copy
What is the output: bool a=true,b=false; a^=b; cout<<a;
1
click to copy
What is the output: int x=5; cout<<((x%2==0)?"even":"odd");
odd
click to copy
What is the output: int x=5; cout<<(x&&!x)<<(!x||x);
01
click to copy
What is the output: int x=7; cout<<(x&~(1<<2));
3
click to copy
What is the output: int x=3; cout<<(x|(1<<3));
11
click to copy
What is the output: int x=7; cout<<((x>>1)^(x>>2));
2
click to copy
What is the output: int x=5; cout<<(x*(x-1)>>1);
10
click to copy
What is the output: int x=255; cout<<(x^(x>>4));
240
click to copy
What is the output: int x=6; cout<<(x&-x);
2
click to copy