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++ → Control Statements 36

What is the output: int x=0; for(int i=0;i<5;i++) x+=i*2+1; cout<<x;
25
click to copy
What is the output: int x=8; while(x>0){if(x%3==0){cout<<x;break;} x (1, 6, 74, 4, 4, 'What is the output: for(int i=1;i<=5;i++) if(i!=3) cout<<i;', 'Print 1-5 except 3?', '1245', '1245', '12345', '12345', 'Compile error', 'Compile error', 'Undefined', 'Undefined', NULL, 'option_a', 'Skip i=3. Output: 1245.', 0, '2026-05-25', '2026-05-25'), (1, 6, 74, 4, 4, 'What is the output: int x=5; switch(x){ case 1: case 2: case 3: case 4: case 5: cout<<'A';}
A
click to copy
What is the output: for(int i=1;i<=5;i++) if(i!=3) cout<<i;
1245
click to copy
What is the output: int x=5; switch(x){ case 1: case 2: case 3: case 4: case 5: cout<<'A';}
A
click to copy
What is the output: int s=0; for(int i=1;i<=100;i++) if(i%2!=0) s++; cout<<s;
50
click to copy
What is the output: for(int i=2;i<10;i++) if(i%2==0&&i%3==0) cout<<i;
6
click to copy
What is the output: for(int i=0;i<5;i++) cout<<(i%2?'-':'+');
+-+-+
click to copy
What is the output: int x=100; int c=0; while(x>0){x/=2;c++;} cout<<c;
7
click to copy
What is the output: for(auto c:'A','B','C') cout<<c;
Compile error
click to copy
What is the output: int x=0; while(++x<5) cout<<x;
1234
click to copy
What is the output: int x=4; switch(x>>1){case 0:cout<<'Z';break;case 1:cout<<'O';break;case 2:cout<<'T';break;}
T
click to copy
What is the output: int s=0; for(int i=1;i<=10;i++) s^=i; cout<<s;
11
click to copy
What is the output: int x=0; for(int i=0;i<4;i++) for(int j=0;j<4;j++) if(i+j==3) x++; cout<<x;
4
click to copy
What is the output: for(int i=1;i<=5;i++) cout<<(i*(i+1)/2);
13610 15
click to copy
What is the output: int n=6; bool isPrime=n>1; for(int i=2;i*i<=n;i++) if(n%i==0){isPrime=false;break;} cout<<isPrime;
0
click to copy
What is the output: for(int i=0,j=10;i<5;i++,j-=2) cout<<i+j;
1098765
click to copy
What is the output: int x=1; for(int i=0;i<10;i++) x=(x%10)*2; cout<<x;
2
click to copy
What is the output: int x=0; for(int i=1;i<=5;i++) x+=(i%2?i:-i); cout<<x;
3
click to copy
What is the output: for(int i=0;i<5;i++) {if(i==2) goto skip; cout<<i;} skip:;
01
click to copy
What is the output: int x=5; cout<<(x==5?x==4?'A':'B':'C');
B
click to copy
What is the output: for(int i=1;i<=4;i++) for(int j=1;j<=4;j++) if(i*j==6) cout<<i<<j;
2 3
click to copy
What is the output: int x=7; if(x%2){if(x%3) cout<<'B'; else cout<<'C';} else cout<<'D';
B
click to copy
What is the output: for(int i=0;i<5;i++) cout<<(1<<i);
124816
click to copy
What is the output: int x=5; switch(x){ case 5: { int y=10; cout<<y; break; } }
10
click to copy
What is the output: int x=0; for(int i=0;i<4;i++) x|=1<<i; cout<<x;
15
click to copy
What is the output: for(int i=0;i<3;i++) { int x=i*i; cout<<x; }
014
click to copy
What is the output: for(int i=100;i>0;i/=10) cout<<i%10;
001
click to copy
What is the output: int n=0; for(int i=2;i<20;i++){bool ok=true;for(int j=2;j*j<=i;j++) if(i%j==0){ok=false;break;} if(ok)n++;} cout<<n;
8
click to copy
'What is the output: int x=10; while(x>0){if(x%4==0) {cout<<x; break;} x (1, 6, 74, 4, 4, 'What is the output: for(int i=0;i<5;i++) cout<<i%3;', 'i%3 for 0-4?', '01201', '01201', '01234', '01234', 'Compile error', 'Compile error', 'Undefined', 'Undefined', NULL, 'option_a', '0%3=0
2%3=2
click to copy
What is the output: for(int i=0;i<5;i++) cout<<i%3;
01201
click to copy
What is the output: int g=0; for(int i=1;i<=5;i++) for(int j=1;j<=5;j++) if(__gcd(i,j)==1) g++; cout<<g;
16
click to copy
What is the output: int x=1; for(int i=0;i<8;i++){if(x>100)break; x*=2;} cout<<x;
128
click to copy
What is the output: for(int i=0;i<3;i++) {for(int j=0;j<3;j++) {if(j==2) continue; cout<<i*3+j;}}
013467
click to copy
What is the output: int n=5; int a[5]={0}; for(int i=0;i<n;i++) a[i]=i+1; int s=0; for(int x:a) s+=x; cout<<s;
15
click to copy
What is the output: int x=5,y=0; while(x>0){y=y*10+x%10;x/=10;} cout<<y;
5
click to copy
What is the output: int x=123,y=0; while(x>0){y=y*10+x%10;x/=10;} cout<<y;
321
click to copy

OOP Using C++ → Functions 4

What is the output: int f(int x){return x>0?x+f(x-1):0;} cout<<f(4);
10
click to copy
What is the output: int f(int a,int b){return a>b?f(a-b,b):a==b?0:f(a,b-a);} cout<<f(12,8);
4
click to copy
What is 'std::function<void()>'?
Callable storing any void() function, lambda, or functor
click to copy
What is the output: auto f=[](int x)->bool{return x%2==0;}; cout<<f(4)<<f(3);
10
click to copy