C interview questions on control flow statements
This post covers basics interview questions on control flow statements
- What is the output of the following program?
#include<stdio.h> int main() { if(1) printf("hello"); printf("bye"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if(!10>!-5) printf("Hello"); else printf("Welcome"); }
- What is the output of the following program?
#include<stdio.h> int main() { int a=10; if(a++>10) printf("Welcome%d",++a); else printf("Hello%d",++a); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int a=10; if(!(--a)) printf("Welcome%d",--a); else printf("Hello%d",--a); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { short a=32768; if(a++>1) printf("Hello%d",++a); else printf("Welcome%d",++a); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int x=10,y; if(x=20) y=30; printf("x=%d y=%d",x,y); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int a=1; if(~a) printf("Welcome%d",a); else printf("Hello%d",~a); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int a=2,b=3; if(a&b) printf("Welcome%d",a&b); else printf(“Hello%d”,a&b); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int a=10; if(++a>10) printf("Welcome%d",a); else printf("Hello%d",a); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int x,y; if(++x||++y) printf("x=%d y=%d",x,y); else printf("x=%d y=%d",x,y); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int x,y; x=y=1; if(--x||++y) printf("x=%d y=%d",x,y); else printf("x=%d y=%d",x,y); return 0; }
- What is the output of the following program?
#include < stdio.h > int main() { int x, y; x = y = 1; if (--x || y--) printf("x=%d y=%d", x, y); else printf("x=%d y=%d", x, y); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int x; if (x = 0, 1, 2, 3) printf("Hello % d", x); else printf("Welcome % d", x); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int x; if (x = (0, 1, 2, 3)) printf("Hello % d", x); else printf("Welcome % d", x); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int x, y; x = y = 0; if (++x && y++) printf("x=%d y=%d", x, y); else printf("x=%d y=%d", x, y); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int x, y; x = y = 1; if (++x && ++y) printf("x=%d y=%d", x, y); else printf("x=%d y=%d", x, y); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if (-1) printf("Balu"); printf("Tutorial.com"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if (0) printf("Balututoril.com"); printf("C & C++"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if (0); printf("BaluTutorial.com"); printf("Balu"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if () printf("Java"); printf(".Net"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if (~(!8 >= !0)) printf("hello"); else printf("bye"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if (!(-1 & ~0)) printf("hello"); else printf("bye"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if (~0) printf("Oracle"); else printf("SQL Server"); retur 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if (23); printf("C++"); else printf("VC++"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if (23) printf("Balu"); else; printf("Tutorial.com"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { else printf("hello"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int a; if (a = printf("hello")) printf("Balu % d", a); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int i; i = 10 >> 4; switch (i) case 0: printf("hai"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { switch (1) case 0: printf("hai"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { float f = 3.2; switch (f) { case 1: printf(“1”); break; case 3.2: printf(“2”); break; } return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int i; i = 0X11; switch (i) { case 2: printf("Two"); break; case 17: printf("Hello"); break; case 011: printf("Hai"); } return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { switch (1) { default: printf("hai"); break; case 0: printf("bye"); } return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int a = 'b'; switch (a) { case 'a': printf("a"); break; case 'b': printf("b"); } return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { char a = 'b'; switch (a) { case 'a': printf("a"); break; case 'b': printf("b"); } return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int a = 9; switch (a) { case 9: printf("hai"); case 010: printf("bye"); } return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int a = 9; switch (a) { case 9: printf("hai"); case 010: printf("bye"); } return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int a = 10; switch (a) { case 0XA: printf("hai"); case 011: printf("bye"); } return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if ("true") printf("true"); else printf("false"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if ("false") printf("true"); else printf("false"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if (0xAbc1) printf("true"); else printf("false"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { float a = 0.7; if (a == 0.7) printf("true"); else printf("false"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { if (printf("%c", 59)) {} return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { int i = 8; float f = 8.0; if (i == f) printf("welcome"); else printf("Hello"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { float f = 8.3; if (f == 8.3) printf("welcome"); else printf("Hello"); return 0; }
- What is the output of the following program?
#include<stdio.h> int main() { float f = 8.3; if (f == 8.3) printf("welcome"); else printf("Hello"); return 0; }