fresher c programming interview questions
This post covers basics interview questions on control flow statements including loops, switch statements along with datatype.
- What is the output of the following code?
#include<stdio.h> int main() { while (printf("%c", 65)) return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { while (printf("%c", 65)) {} return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { int i = 1; while (i++ <= 1) while (i++ <= 2); printf("%d", a); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { short i = 1; while (i-- <= 1) while (i-- <= 0); printf("% d", i); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { short i = 1; while (++i >= 1); printf("%d", i); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { short i = 1; while (i-- < 32767); printf("%d", i); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { short i = 32767; while (i--); printf("%d", i); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { short i = -1; while (i--); printf("%d", i); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { while () printf("Hello Balu"); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { while ("hai"); printf("hello"); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { while (printf("Hai"), printf("")) printf("hello"); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { int a; a = 0; while (a++ <= 5) printf("%d ", a); printf("%d ", a + 10); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { int a, b; a = b = 1; while (a) { a = b++ <= 3; printf("%d %d\n", a, b); } printf("%d %d\n", a + 10, b + 10); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { int a, b; a = b = 13; while (a) { a = b-- >= 10; printf("%d %d\n", a, b); } printf("%d %d\n", a + 10, b + 10); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { int a; a = 100; do while (a++ > 10); printf("% d", a); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { int a; a = 10; do while (a++ < 10); while (a++ <= 11); printf(" % d", a); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { for (;;) printf("hello"); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { int a, b; for (a = b = 0; a; printf("\n%d %d", a, b)) a = b++ <= 3; printf("\n%d %d", a + 10, b + 10); return 0; }
- What is the output of the following code?
#include<stdio.h> void main() { int i; for (i = 1; i++ <= 3; i++); i++; printf(" % d", i); }
- What is the output of the following code?
#include<stdio.h> void main() { int i; for (i = 1; i++ <= 1; i++) for (i++; i++ <= 6; i++) i++; printf("%d", i); }
- What is the output of the following code?
#include<stdio.h> void main() { int x = 10, y = 20; while (x-- >= 8 || y-- >= 18) printf("\n %d %d", x, y); printf(" %d %d", x + 10, y + 10); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { int a = 0; do printf("balututorial.com"); while (a); printf("C Balu"); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { int i = 0; for (; i;) printf("\nFor Loop Body"); printf("\nOutside Loop "); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { for (; 0;) printf("\nFor Loop Body"); printf("\nOutside Loop "); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { int i = 0; while (i) printf("\nWhile Loop"); printf("\nOut Side While"); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { while (0) printf("\nWhile Loop"); printf("\nOutside While"); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { int i = 0; do printf("\nDoWhile Loop"); while (i); printf("\nOutside Do while"); return 0; }
- What is the output of the following code?
#include<stdio.h> int main() { do printf("\nDoWhile Loop"); while (0); printf("\nOutside Do While"); return 0; }
- What is the output of the following code?
#include<stdio.h> void main() { int a; a = 10; while (a >= 1) { printf("%d ", a); if (a < 5) break; a++; } printf("%d ", a + 10); }
- What is the output of the following code?
#include<stdio.h> void main() { int a = 1; while (a <= 10); { printf("%d ", a--); if (a < 5) break; } printf("%d ", a + 10); }
- What is the output of the following code?
#include<stdio.h> void main() { int a = 10; while (a >= 1) { a--; if (a > 4 && a < 7) continue; printf("%d ", a); } printf("%d ", a + 10); }
- What is the output of the following code?
#include<stdio.h> void main() { int a = 1; while (a <= 10) { printf(" %d", a); if (a > 5 && a < 8) continue; a++; } printf("%d ", a + 10); }
- What is the output of the following code?
#include<stdio.h> void main() { int a = 10; while (a <= 100); { a++; if (a > 50 && a < 80) continue; printf(" % d", a); } printf("%d ", a + 10); }
- What is the output of the following code?
#include<stdio.h> int main() { int i; for (; scanf("%d", & i); printf("%d", i)) //Entered Value is 10 return 0; }
- How many times the loop will get executed?
int i; for (i = 0; i = 10; i++) printf("Hi");
- What is the output of the following code?
#include<stdio.h> void main() { printf("1"); goto XYZ; printf("2"); XYZ: printf("3"); }
- What is the output of the following code?
#include<stdio.h> int main() { int a = 3; L1: printf("%d", a); a--; if (a > 1) goto L1; return 0; }
- What is the output of the following code?
#include<stdio.h> main() { L1: int a = 3; printf("%d", a); a--; if (a > 1) goto L1; return 0; }
- What is the output of the following code?
#include<stdio.h> void main() { int a = 2; switch (a); { case 1: printf("A"); case 2: printf("B"); case 3: printf("C"); break; default: printf("E"); } }
- What is the output of the following code?
#include<stdio.h> void main() { int a = 2; switch (a) { case 1: printf("A"); case 2: printf("B"); continue; case 3: printf("C"); break; default: printf("E"); } }
- What is the output of the following code?
#include<stdio.h> void main() { int a = 2; switch (a) { case4: printf("A"); break; case3: printf("B"); case2: printf("C"); case1: printf("D"); break; default: printf("E"); } }
- What is the output of the following code?
#include <stdio.h> void main() { int i = 0; switch (printf("Hi"), printf("")) { case 1: printf("%d", i); break; case 2: printf("%d", ++i); break; } }