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 29

What is the output: void f(int **p,int v){**p=v;} int x=0; int *px=&x; f(&px,42); cout<<x;
42
click to copy
What is the output: auto up=make_unique<int[]>(3); up[0]=1;up[1]=2;up[2]=3; cout<<up[0]+up[2];
4
click to copy
What is the output: int x=10; auto sp=make_shared<int>(x); cout<<sp.use_count()<<*sp;
110
click to copy
What is the output: int a[]={1,2,3,4,5}; int *p=a; cout<<p[3];
4
click to copy
What is the output: int *p=nullptr; if(p) cout<<*p; else cout<<'N';
N
click to copy
What is the output: int a[5]={1,2,3,4,5}; cout<<*(a+0)+*(a+1)+*(a+2)+*(a+3)+*(a+4);
15
click to copy
What is the output: int x=5; const int* const p=&x; cout<<*p;
5
click to copy
What is the output: char str[]="hello"; char *p=str+4; cout<<*p;
o
click to copy
What is the output: int a[]={1,2,3}; int *p=a; p+=2; cout<<*p;
3
click to copy
What is the output: int x=5; auto wp=weak_ptr<int>{}; cout<<wp.expired();
1
click to copy
'What is the output: int a[]={5,4,3,2,1}; int *p=a,*q=a+4; while(p<q){swap(*p,*q);p++;q (1, 6, 77, 7, 4, 'What is the output: struct P{int x
4}; cout<<p->x+p->y; delete p;', 'struct pointer: p->x+p->y?', '7', '7', '12', '12', 'Compile error', 'Compile error', 'Undefined', 'Undefined', NULL, 'option_a', '3+4=7. Output: 7.', 0, '2026-05-25', '2026-05-25'), (1, 6, 77, 7, 4, 'What is the output: int a[]={10
click to copy
What is the output: struct P{int x,y;}; P* p=new P{3,4}; cout<<p->x+p->y; delete p;
7
click to copy
What is the output: int a[]={10,20,30}; int *const p=a; p[1]=200; cout<<a[1];
200
click to copy
What is the output: int x=5; unique_ptr<int> p=make_unique<int>(x); unique_ptr<int> q=move(p); cout<<(bool)p<<*q;
05
click to copy
What is the output: int a[]={1,2,3,4,5}; cout<<*(a+sizeof(a)/sizeof(*a)-1);
5
click to copy
What is the output: int x=5,y=10; int *p[2]={&x,&y}; *p[0]+=*p[1]; cout<<x;
15
click to copy
What is the output: auto sp=make_shared<vector<int>>(3,0); (*sp)[1]=5; cout<<(*sp)[1];
5
click to copy
What is the output: int a[]={3,1,4,1,5}; int *p=max_element(a,a+5); cout<<*p<<(p-a);
45
click to copy
What is the output: char s[]="Hello"; for(char *p=s;*p;p++) *p=toupper(*p); cout<<s;
HELLO
click to copy
What is the output: int x=42; int *p=&x; void *vp=p; int *p2=static_cast<int*>(vp); cout<<*p2;
42
click to copy
What is the output: int a[3]={1,2,3}; auto f=[](int *p,int n){int s=0;for(int i=0;i<n;i++) s+=p[i];return s;}; cout<<f(a,3);
6
click to copy
What is the output: int *p=new int[5]; for(int i=0;i<5;i++) p[i]=i*i; cout<<p[3]; delete[]p;
9
click to copy
What is the output: int x=5; shared_ptr<int> a,b; a=make_shared<int>(x); b=a; a.reset(); cout<<b.use_count()<<*b;
15
click to copy
What is the output: int a[]={1,2,3,4,5}; int *begin=a,*end=a+5; cout<<accumulate(begin,end,0);
15
click to copy
What is the output: int x=10; auto* p=new auto(x); cout<<*p<<' '; delete p; cout<<(p=nullptr)==nullptr;
10 1
click to copy
What is the output: int x=5; int *p=&x; cout<<reinterpret_cast<uintptr_t>(p)%4;
0
click to copy
What is the output: int a[]={1,2,3}; int *p=a; cout<<p[0]<<p[1]<<p[2];
123
click to copy
What is the output: int x=10; int &r=x; int *p=&r; ++(*p); cout<<r;
11
click to copy
What is the output: int a[]={2,4,6,8}; int *p=a+1; cout<<p[-1]<<p[0]<<p[1];
246
click to copy

OOP Using C++ → Classes and Objects 11

What is the output: class A{public:int x=0; void f(){x++;}}; A a1,a2; a1.f();a1.f(); a2.f(); cout<<a1.x<<a2.x;
21
click to copy
What is the output: class A{public:int x; A(int v):x(v){} int get()const{return x;} void set(int v){x=v;}}; A a(5); a.set(10); cout<<a.get();
10
click to copy
What is 'rule of zero'?
Don't define any special members; use smart pointers/containers
click to copy
What is the output: class A{public:static int n; A(){n++;} ~A(){n (1, 6, 78, 8, 4, 'What is the output: class A{int x=5; public: int f()const{return x;} void g(){x=10;}}; A a; cout<<a.f(); a.g(); cout<<a.f();', 'const and non-const member functions?', '510', '510', '55', '55', 'Compile error', 'Compile error', 'Undefined', 'Undefined', NULL, 'option_a', 'Initial f()=5; g() sets x=10; f()=10. Output: 510.', 0, '2026-05-25', '2026-05-25'), (1, 6, 78, 8, 4, 'What is 'conversion operator' vs constructor conversion?
Conv op: class->other type; constructor: other type->class
click to copy
What is the output: class A{int x=5; public: int f()const{return x;} void g(){x=10;}}; A a; cout<<a.f(); a.g(); cout<<a.f();
510
click to copy
What is 'conversion operator' vs constructor conversion?
Conv op: class->other type; constructor: other type->class
click to copy
What is the output: class A{public:int x; A(int v=0):x(v){}}; A a[3]; cout<<a[0].x<<a[1].x<<a[2].x;
000
click to copy
What is the output: class A{public:int x; A():x(0){} A(const A& o):x(o.x+1){}}; A a; A b=a; A c=b; cout<<a.x<<b.x<<c.x;
012
click to copy
What is the output: class A{public:int x=0; A& inc(){x++;return *this;}}; A a; cout<<a.inc().inc().inc().x;
3
click to copy
What is 'aggregate initialization' for class?
Class with no user-defined ctor, no private data: A a{1,2};
click to copy
What is the output: class A{public:int x,y; A(int a,int b):x(a),y(b){} int sum()const{return x+y;}}; A a(3,4); cout<<a.sum();
7
click to copy