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.

Data Structures and Algorithms → Introduction to DSA 40

The output of: format("{:x}", 255):
ff
click to copy
The output of: format("{:o}", 8):
10
click to copy
What is the output: string s=format("Hello, {}!", "World"); cout<<s;
Hello, World!
click to copy
The output of: auto r=views::iota(5); cout<<ranges::distance(r);
5
click to copy
The output of: vector<int> v={1,2,3,4,5}; auto sum=ranges::fold_left(v,0,plus<>{}); cout<<sum;
15
click to copy
Which C++ keyword marks a variable as thread-local storage?
thread_local
click to copy
The output of: constexpr int sq(int n){return n*n;} static_assert(sq(5)==25); cout<<"OK";
OK
click to copy
static_assert in C++ checks:
Compile-time assertion; program fails to compile if condition is false
click to copy
The output of: template<class T> void f(T&&x){cout<<is_lvalue_reference<T>::value;} int a=5; f(a); f(5);
10
click to copy
What is the output: int arr[3][3]={{1,2,3},{4,5,6},{7,8,9}}; cout<<arr[1][2];
6
click to copy
The output of: int** p; int a[2][2]={{1,2},{3,4}}; p=new int*[2]; for(int i=0;i<2;i++) p[i]=a[i]; cout<<p[1][0];
3
click to copy
The output of: char* s="Hello"; cout<<strlen(s);
5
click to copy
The output of: char a[]="Hello"; char b[]="World"; strcat(a,b); cout<<a;
HelloWorld
click to copy
The output of: char a[]="Hello"; char b[]="Hello"; cout<<strcmp(a,b);
0
click to copy
The output of: char a[]="Apple"; char b[]="Banana"; cout<<(strcmp(a,b)<0?"a<b":"a>=b");
a<b
click to copy
The output of: char s[]="Hello World"; char* p=strtok(s," "); cout<<p;
Hello
click to copy
memcpy vs memmove difference:
memmove handles overlapping source/dest; memcpy does not
click to copy
The output of: int arr[5]={1,2,3,4,5}; memset(arr,0,sizeof(arr)); cout<<arr[2];
0
click to copy
The output of: int a=1,b=2; memcpy(&a,&b,sizeof(int)); cout<<a;
2
click to copy
What is the output: printf("%d %d %d",1,2,3);
1 2 3
click to copy
What is the output: scanf("%d",&n) with input 42; printf("%d",n);
42
click to copy
What does perror("msg") do in C++?
Print msg + colon + system error message for errno
click to copy
The output of: FILE* f=tmpfile(); fprintf(f,"test"); rewind(f); char buf[10]; fscanf(f,"%s",buf); cout<<buf;
test
click to copy
What is the output: jmp_buf jb; if(!setjmp(jb)){cout<<"A"; longjmp(jb,1);} cout<<"B";
AB
click to copy
longjmp in C++ is:
Dangerous - does not call destructors (use C++ exceptions instead)
click to copy
The output of: int x=5; auto l=coroutine_not_shown; cout<<x; in non-coroutine context:
5
click to copy
Which C++20 concept checks if type T has operator<< for ostream?
Must define custom concept or use std::formattable
click to copy
The output of: for(int i=2;i<=20;i+=2) cout<<i<<" "; number of outputs:
10
click to copy
The output of: int n=1000; for(;n>1;n/=10) cout<<n%10; cout<<n;
001
click to copy
What is the output: int arr[]={10,20,30}; for(int &x:arr) x*=2; cout<<arr[1];
40
click to copy
The output of: string words[]={"hello","world","foo"}; sort(words,words+3); cout<<words[0];
foo
click to copy
The output of: vector<string> v={"c","a","b"}; sort(v.begin(),v.end()); cout<<v[0]<<v[2];
ac
click to copy
What is the output: auto it=max_element(begin("abcZ"),end("abcZ")-1); cout<<*it;
c
click to copy
The output of: int n=7; int sum=0; for(int i=2;i<=n/2;i++) if(n%i==0){sum=1; break;} cout<<(sum?"Composite":"Prime");
Prime
click to copy
The output of: int n=12; int sum=0; for(int i=2;i<=n/2;i++) if(n%i==0){sum=1; break;} cout<<(sum?"Composite":"Prime");
Composite
click to copy
What is the output: struct Pt{int x,y; Pt(int x,int y):x(x),y(y){} double dist(){return sqrt(x*x+y*y);}}; Pt p(4); cout<<p.dist();
5
click to copy
The output of: class Ctr{int n=0; public: void inc(){n++;} int get(){return n;} }; Ctr c; c.inc(); c.inc(); c.inc(); cout<<c.get();
3
click to copy
The output of: class Box{double l,w,h; public: Box(double a,double b,double c):l(a),w(b),h(c){} double vol(){return l*w*h;} }; Box b(3,4); cout<<b.vol();
24
click to copy
The output of: class Vec{int x,y; public: Vec(int a,int b):x(a),y(b){} Vec operator+(Vec v){return Vec(x+v.x,y+v.y);} void print(){cout<<x<<","<<y;} }; Vec a(2),b(4); (a+b).print();
4,6
click to copy
The output of: class A{public:int x; A(int x):x(x){}}; class B:public A{public:B(int x):A(x){}}; B b(42); cout<<b.x;
42
click to copy