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++ → Arrays 30

What is the output: int a[]={1,2,3}; int *p=a; cout<<*(p+2);
3
click to copy
What is the output: int a[3][2]={{1,2},{3,4},{5,6}}; cout<<a[1][1];
4
click to copy
What is the size of: int arr[10]; cout<<sizeof(arr);
40
click to copy
What is the output: int a[5]={1}; cout<<a[4];
0
click to copy
What is the output: int a[]={1,2,3}; cout<<sizeof(a)/sizeof(a[0]);
3
click to copy
What is the output: char s[]="hello"; cout<<sizeof(s);
6
click to copy
What is the output: int a[3]={1,2,3}; cout<<a[3];
Undefined behavior
click to copy
What is the output: int a[]={5,4,3,2,1}; sort(a,a+5); cout<<a[0];
1
click to copy
What is the output: int a[2][3]={0}; cout<<a[0][0]<<a[1][2];
00
click to copy
What is the output: int a[]={1,2,3}; int *p=a+1; cout<<p[-1];
1
click to copy
What is the output: int a[]={0,1,2,3,4}; cout<<*(a+3);
3
click to copy
What is the output: int a[5]; cout<<a[0];
Undefined behavior
click to copy
What is VLA (Variable Length Array) in C++?
Not part of C++ standard (only C99)
click to copy
What is the output: int a[]={1,2,3,4,5}; cout<<a[a[1]];
3
click to copy
What is the output: int a[]={1,2,3}; auto [x,y,z]=a; cout<<y;
2
click to copy
What is the difference between array name and pointer?
Array name is const pointer; pointer is a variable
click to copy
What is the output: int a[3]={1,2,3}; cout<<&a+1-&a;
1
click to copy
What is the output: int a[][2]={{1,2},{3,4}}; cout<<*(*a+1);
2
click to copy
What is the output: int a[5]={1,2,3,4,5}; cout<<a[5];
Undefined behavior
click to copy
What is the output: int a[]={1,2,3}; cout<<end(a)-begin(a);
3
click to copy
What happens when you pass an array to a function?
Array decays to pointer
click to copy
What is the output: int a[3]={1,2,3}; cout<<*a<<*(a+1)<<*(a+2);
123
click to copy
What is std::array vs raw array in C++?
std::array knows its size, doesn't decay to pointer
click to copy
What is the output: int a[]={10,20,30}; for(int& x:a) x*=2; cout<<a[1];
40
click to copy
What is the output: int a[3]; fill(a,a+3,5); cout<<a[2];
5
click to copy
What is the output: int a[]={3,1,4,1,5}; cout<<*max_element(a,a+5);
5
click to copy
What is 'array decay' in C++?
Array converted to pointer when used in most contexts
click to copy
What is the output: int a[5]; cout<<sizeof(a)<<' '<<sizeof(a+0);
20 8
click to copy
What is the output: int a[]={1,2,3,4,5}; int s=0; for(int x:a) s+=x; cout<<s;
15
click to copy
What is the output: int a[3]={1,2,3}; reverse(a,a+3); cout<<a[0]<<a[1]<<a[2];
321
click to copy

OOP Using C++ → Pointers 10

What is the output: int x=10; int *p=&x; *p=20; cout<<x;
20
click to copy
What is a 'dangling pointer'?
Pointer to freed/destroyed memory
click to copy
What is the output: int a=1,b=2; int *p=&a; p=&b; *p=10; cout<<a<<b;
1 10
click to copy
What is the output: int x=5; int *p=nullptr; cout<<(p==nullptr);
1
click to copy
What is 'pointer arithmetic' in C++?
Adding integers to pointers to navigate arrays
click to copy
What is the output: int a[]={1,2,3,4,5}; int *p=a+2; cout<<p[-1]<<p[0]<<p[1];
234
click to copy
What is the output: void* p=(void*)42; cout<<(int)(size_t)p;
42
click to copy
What is a 'smart pointer' in C++?
A pointer with automatic memory management
click to copy
What is the output: int x=10; const int *p=&x; *p=20; cout<<x;
Compile error
click to copy
What is the output: int x=5,y=10; int *p=&x; swap(p,&y); cout<<x<<y;
Compile error
click to copy