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++ → Pointers 20

What is 'double pointer' in C++?
Pointer to a pointer
click to copy
What is the output: int arr[]={1,2,3}; int *p=arr; cout<<p++<<' '<<*p;
Undefined
click to copy
What is the output: int x=10; int &r=x; int *p=&r; *p=20; cout<<x;
20
click to copy
What is 'placement new' in C++?
Constructs object at specified memory address
click to copy
What is the output: int x=5; int *p=&x; cout<<**&p;
5
click to copy
What does 'delete[]' do vs 'delete'?
delete[] frees array, delete frees single object
click to copy
What is the output: int* p=new int(42); cout<<*p; delete p; cout<<*p;
42 then UB
click to copy
What is 'wild pointer'?
Uninitialized pointer
click to copy
What is the output: int a=1,b=2; int *p=&a,*q=&b; *p=*q; cout<<a<<b;
22
click to copy
What is the output: int x=5; int *p=&x; p=nullptr; cout<<(p?*p:0);
0
click to copy
What is std::unique_ptr?
Exclusive ownership smart pointer (non-copyable)
click to copy
What is the output: int a[]={10,20,30}; int *p=a; cout<<*(p++);
10
click to copy
What is 'pointer to function' in C++?
A variable storing address of a function
click to copy
What is the output: int f(){return 42;} int (*p)()=f; cout<<p();
42
click to copy
What is the output: int x=10; void *p=&x; cout<<*(int*)p;
10
click to copy
What is the output: int a[]={1,2,3,4,5}; int *p=a+5; cout<<*(p-1);
5
click to copy
What is shared_ptr reference count?
Number of shared_ptrs owning the object
click to copy
What is the output: int x=5; auto p=make_unique<int>(x); *p=10; cout<<x;
5
click to copy
What is 'aliasing' in the context of pointers?
Two pointers pointing to the same memory
click to copy
What is the output: int* p=new int[5]{1,2,3,4,5}; cout<<p[4]; delete[] p;
5
click to copy

OOP Using C++ → Classes and Objects 20

What is the output: class A{public: int x=5;}; A a; cout<<a.x;
5
click to copy
What is the output: class A{int x; public: A(int v):x(v){} int get(){return x;}}; A a(10); cout<<a.get();
10
click to copy
What is 'this' pointer?
Pointer to current object instance
click to copy
What is the output: class A{public: static int x; int y;}; int A::x=5; A a; a.y=10; cout<<A::x<<a.y;
510
click to copy
What is a 'friend function'?
Function with access to private/protected members
click to copy
What is the output: class A{public: int x; A(int v):x(v){} A(const A& a):x(a.x+1){}}; A a(5); A b=a; cout<<b.x;
6
click to copy
What is 'object slicing' in C++?
Derived object assigned to base: derived part lost
click to copy
What is the output: class A{public: int x=0; void f(){x++;}}; A a,b; a.f(); cout<<a.x<<b.x;
10
click to copy
What is 'operator overloading'?
Defining operator behavior for user-defined types
click to copy
What is the output: class A{public: A(){cout<<'C';} ~A(){cout<<'D';}}; {A a;}
CD
click to copy
What is a 'copy constructor'?
Constructor taking const reference to same class
click to copy
What is 'Rule of Three' in C++?
If you define destructor/copy-ctor/copy-assign, define all three
click to copy
What is the output: class A{public: int x; A():x(0){} A(int v):x(v){}}; A a; cout<<a.x;
0
click to copy
What is 'mutable' keyword for class members?
Allows member to be modified even in const member functions
click to copy
What is the output: class A{public: operator int(){return 42;}}; A a; cout<<(int)a;
42
click to copy
What is 'aggregate initialization'?
Initializing aggregate types with brace-enclosed list
click to copy
What is the output: class A{public: int x=10; int f() const {return x;}}; const A a; cout<<a.f();
10
click to copy
What is 'explicit' constructor?
Prevents implicit conversion of constructor argument
click to copy
What is the output: class A{public: static void f(){cout<<'S';} void g(){cout<<'G';}}; A::f(); A a; a.g();
SG
click to copy
What is the output: class A{public: int x; A(int v=0):x(v){}}; A a=5; cout<<a.x;
5
click to copy