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++ → Operators in C++ 27

What is the output: int x=5; cout<<(x*x+2*x+1);
36
click to copy
What is the output: int x=5; cout<<(x-1)*(x+1)<<' '<<x*x-1;
24 24
click to copy
What is the output: bool a=1>0, b=2>3; cout<<(a&&b)<<(a||b)<<(a^b);
101
click to copy
What is the output: int x=7; cout<<(x&0x1)<<(x&0x2)<<(x&0x4);
124
click to copy
What is the output: int x=5; cout<<((x%2==0)?"even":"odd")<<x;
odd5
click to copy
What is the output: int x=10; x+=x; x-=5; x*=2; cout<<x;
30
click to copy
What is the output: int x=5; int y=(x>0)+(x>1)+(x>2)+(x>3)+(x>4)+(x>5);
5
click to copy
What is the output: int a=3,b=4; cout<<(a*a+b*b)<<' '<<(a+b)*(a+b);
25 49
click to copy
What is the output: cout<<(1<<0|1<<1|1<<2|1<<3);
15
click to copy
What is the output: int x=255; cout<<(x&0xF)<<((x>>4)&0xF);
1515
click to copy
What is the output: int x=5,y=10; cout<<(x<y?x:y)<<' '<<(x>y?x:y);
5 10
click to copy
What is the output: int a=5; cout<<(a&=3)<<a;
11
click to copy
What is the output: int x=2; for(int i=0;i<4;i++) x=x<<1|1; cout<<x;
31
click to copy
What is the output: int x=5; cout<<(x|(x<<4));
85
click to copy
What is the output: int x=5; cout<<(x^(x^0));
5
click to copy
What is the output: int x=5; cout<<(x^0)<<(x^x)<<(x^(~0));
50-6
click to copy
What is the output: int x=5; cout<<(x&&2)<<(x&2)<<(x||0)<<(x|0);
1015
click to copy
'What is the output: int a=5,b=3; int c=a>b?a (1, 6, 73, 3, 4, 'What is the output: int x=5; cout<<(x>>0)<<(x>>1)<<(x>>2)<<(x>>3);', 'Right shift 0
2
click to copy
What is the output: int x=5; cout<<(x>>0)<<(x>>1)<<(x>>2)<<(x>>3);
5321
click to copy
What is the output: cout<<(sizeof(int)*8-1);
31
click to copy
What is the output: int x=5; cout<<(x>0)-(x<0)+(x==0);
1
click to copy
What is the output: int x=10; x=x/2+x%2; cout<<x;
5
click to copy
What is the output: int x=7; cout<<(x/(x&-x));
7
click to copy
What is the output: int x=5; cout<<(x*2)<<' '<<(x<<1)<<' '<<(x+x);
10 10 10
click to copy
What is the output: int a=4,b=6; cout<<((a+b)/2)<<' '<<((a+b)>>1);
5 5
click to copy
What is the output: int x=5; cout<<(-1*x)<<(~x+1);
-5-5
click to copy
What is the output: int x=5; bool odd=x&1,pos=x>0; cout<<(odd&&pos?"odd+": odd?"odd": pos?"pos":"neither");
odd+
click to copy

OOP Using C++ → Control Statements 13

What is the output: for(int i=1;i<=10;i++) if(i%2==0&&i%3==0) cout<<i;
6
click to copy
What is the output: int x=1; while(x<1024) x<<=1; cout<<x;
1024
click to copy
What is the output: int x=100; while(x>1){if(x%2==0)x/=2;else x=x*3+1;} cout<<x;
1
click to copy
What is the output: int s=0; for(int i=1;i<=10;i++) s+=(i%2==0?i:-i); cout<<s;
-5
click to copy
What is the output: for(int i=0;i<5;i++) {int t=i*i; if(t>10) break; cout<<t;}
014
click to copy
What is the output: int n=7,r=1; for(int i=2;i<=n;i+=2) r*=i; cout<<r;
48
click to copy
What is the output: int x=10; do{x/=2;}while(x>2); cout<<x;
2
click to copy
What is the output: int cnt=0; for(int i=1;i<=50;i++) if(i%3==0||i%7==0) cnt++; cout<<cnt;
20
click to copy
What is the output: string s=""; for(char c='a';c<='e';c++) s+=c; cout<<s;
abcde
click to copy
What is the output: int x=5; switch(x){case 5: cout<<'A'; [[fallthrough]]; case 6: cout<<'B'; break; default: cout<<'C';}
AB
click to copy
What is the output: for(int i=1;i<=5;i++) for(int j=i;j<=5;j++) if(i*j>12) {cout<<i<<j; goto end;} end:;
34
click to copy
What is the output: for(int i=2;i<10;i++) if(i%2!=0&&i%3!=0) cout<<i;
57
click to copy
What is the output: int x=1; for(int i=0;i<5;i++) x+=x; cout<<x;
32
click to copy