Fresher c programming interview questions
This article covers all the c interview questions on the operator on various patter for a fresher interview in MNC’s
What is the output of the following code?
#include<stdio.h> main() { int x; x = -3 + 4 * 5 - 6; printf("\n%d", x); x = 3 + 4 % 5 - 6; printf("\n%d", x); x = -3 * 4 % -6 / 5; printf("\n%d", x); x = (7 + 6) % 5 / 2; printf("\n%d", x); return 0; }
What is the output of the following code?
#include<stdio.h> void main() { int a, b, c; printf("2 + 3 = % d", 2 + 3); a = 2 + 3 * 2 + 3; b = 2 * 3 + 2 * 3; c = (2 + 3) * (2 + 3); printf("\n % d % d % d", a, b, c); }
What is the output of the following code?
#include<stdio.h> void main() { int a, b, c, d, e; a = 47 % 5; b = -47 % 5; c = -47 % -5; d = 47 % -5; e = 2 % 5; printf("\n % d % d % d % d % d", a, b, c, d, e); }
What is the output of the following code?
#include<stdio.h> void main() { int a, b, c, d, e; float j, k, l, m, n; a = 5 / 2; j = 5 / 2; b = 5.0 / 2; k = 5.0 / 2; c = 5 / 2.0; l = 5 / 2.0; d = 2 / 5; m = 2 / 5; e = 2.0 / 5; n = 2.0 / 5; printf("\n % d % d % d % d % d", a, b, c, d, e); }
What is the output of the following code?
#include<stdio.h> void main() { int x, y, z; x = 2 > 5 <= 0; y = 2 > 3 <= 1; z = 3 > 2 > 1 > 0; printf(" %d %d %d", x, y, z); x = -1 <= 1 >= 2 <= 1; y = 2 >= 2 <= 3 >= 4 <= 0; z = 5 >= 8 <= 3 >= 0; printf("\n %d %d %d", x, y, z); x = 6 < 8 >= 1 <= 0 > -1; y = 8 >= 6 <= 2 >= 5 <= -1; printf("\n %d %d", x, y); }
What is the output of the following code?
#include<stdio.h> void main() { int x, y, z; x = 5 != 1 == 0; y = 5 != 5 == 0; z = 5 != 2 == 1; printf("\n %d %d %d", x, y, z); x = 2 >= 5 != 2 <= 8; y = 8 > 5 != 2 >= 8; z = 8 >= 8 != 8 <= 1; printf("\n % d % d % d", x, y, z); }
What is the output of the following code?
#include<stdio.h> int main() { int a, b, c; a = 3 > 2 && 5 <= 8; b = 3 > (2 && 5) <= 8; c = 3 < (2 && 5 >= 8); printf(" %d %d %d", a, b, c); a = 5 > 2 != 0 || 2 != 2; b = 5 < (2 != 0) || 2 == 2 != 1; c = (5 == 5) != 0 || 2 != 5; printf("\n %d %d %d", a, b, c); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a, b, c; a = !(2 > 5) && !6 != 0; b = !(2 <= 2) || !(!(6 != 0)); c = 2 != !2 && 0 == !2 > 0; printf("\n %d %d %d", a, b, c); a = (!-1) < 0 || !0 > 0; b = !(5 <= 0) && !(5 != !5 <= 0); c = 2 != 1 >= !8 != 1 || (!7 != 5 != !2); printf("\n %d %d %d", a, b, c); }
What is the output of the following code?
#include<stdio.h> int main() { int a, b, c; a = printf("Welcome balututorial.com"); b = scanf("%d %d", & c); //Entered values are 20 30 printf("\n %d %d %d", a, b, c); return 0; }
c interview questions
What is the output of the following code?
#include<stdio.h> int main() { int a, b, c; b = c = 100; printf("\n % d % d % d", a, b, c); a = printf("Welcome balututorial.com % d", printf("Hello Balu")); a = printf("\n % d % d % d % d", scanf(" % d % d", b, & c), a, b, c); printf("\n % d % d % d", a, b, c); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a; a = printf("\nThree") + printf("\nfour") * printf("\nfive") - printf("\nsix"); printf(" % d", a); return 0; }
What is the output of the following code?
#include<stdio.h> #define PRINTX printf("\n%d", x) int main() { int x = 2, y, z; x *= 3 + 2; PRINTX; x *= y = z = 4; PRINTX; x = y == z; PRINTX; x == (y = z); PRINTX; return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int x, y, z; x = 10 > 5 ? 8 <= 10 ? 14 != 0 ? 10 : 20 : 30 : 5 ? 40 : 50; y = 2 > 5 ? 2 != 2 ? 10 : 20 : !5 >= 0 ? 5 != !8 ? !10 ? 30 : 40 : 50 : 60; z = 2 != !2 ? 12 > 5 && 5 < 10 ? !5 ? 10 : 20 : 30 : !5 > 0 ? 40 : 50; printf(" %d %d %d", a, b, c); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a; a = 10; a * 10; printf("\n%d %d %d", a, a * 10, a); a += 20; printf("\n %d %d %d", a, a = 50, a); a++ * a++; printf("\n %d %d %d", ++a, a++, a); a = 100; printf("\n %d %d %d", a++, ++a, a++); printf("\n %d", ++a); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a, b; a = b = 10; a = a++ + ++b; b = b++ + ++a; printf("\n %d %d", a, b); a = b = 50; a = b-- + --a; b = a-- + --b; printf("\n %d %d", a, b); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a, b; a = 2; b = ++a * ++a * ++a; printf("\n %d %d", a, b); a = 1; b = a++ * ++a * ++a; printf("\n %d %d", a, b); a = 1; b = a++ * a++ * a++; printf("\n %d %d", a, b); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a = 2; printf(" %d"++a * ++a * ++a); a = 1; printf(" %d", a++ * ++a * ++a); a = 1; printf(" %d", a++ * a++ * a++); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a = 1, b; b = a, ++a, ++a; printf("\n %d %d", a, b); a = 1; b = a++, ++a, ++a; printf("\n %d %d", a, b); a = 1; b = ++a, ++a, ++a; printf("\n %d %d", a, b); a = 1; b = (++a, ++a, ++a); printf("\n %d %d", a, b); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a, b, c, d; a = b = c = 1; d = ++a || ++b || ++c; printf("\n %d %d %d %d", a, b, c); a = b = c = 1; d = --a || ++b || ++c; printf("\n %d %d %d %d", a, b, c, d); a = b = c = 1; d = --a || --b || ++c; printf("\n %d %d %d %d", a, b, c, d); a = b = c = 1; d = --a || --b || --c; printf("\n %d %d %d %d", a, b, c, d); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a, b, c, d; a = b = c = 1; d = ++a && ++b && ++c; printf("\n %d %d %d %d", a, b, c); a = b = c = 1; d = a-- && ++b && ++c; printf("\n %d %d %d %d", a, b, c, d); a = b = c = 1; d = a-- && b-- && ++c; printf("\n %d %d %d %d", a, b, c, d); a = b = c = 1; d = a-- && b-- && c--; printf("\n %d %d %d %d", a, b, c, d); a = b = c = 1; d = --a && ++b && ++c; printf("\n %d %d %d %d", a, b, c, d); a = b = c = 1; d = a-- && --b && ++c; printf("\n %d %d %d %d", a, b, c, d); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a, b, c, d; a = b = c = d = 1; d = ++a && ++b || ++c; printf("\n %d %d %d %d", a, b, c, d); a = b = c = 1; d = ++a && --b || ++c; printf("\n %d %d %d %d", a, b, c, d); a = b = c = 1; d = --a && ++b || --c; printf("\n %d %d %d %d", a, b, c, d); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a, b, c, d; a = b = c = d = 1; d = ++a || ++b && ++c; printf("\n %d %d %d %d", a, b, c, d); a = b = c = 0; d = a++ || b++ && ++c; printf("\n %d %d %d %d", a, b, c, d); a = b = c = 0; d = a++ || --b && c++; printf("\n %d %d %d %d", a, b, c, d); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a; printf("hai") || printf("bye"); a = printf("\nHello") || printf("bye"); printf("\na = %d", a); a = printf("") || printf("bye"); printf("\na = %d", a); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int x, y, z; x = 5; y = 6; z = 7; z == x <= y; printf("\n%d", z); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a; a = (1, 2, 3, 4, 5); printf("\n a = %d", a); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a; a = 1, 2, 3, 4, 5; printf("\n a = %d", a); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int a, x = 5; a = (x++, ++x, --x); printf("\n a = %d", a); printf("\n x = %d", x); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int x; x = printf("hai") == printf("bye!") && printf("hello"); printf("\n x = %d", x); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { int x = 5; x == 5 ? x < 5 ? printf("one") : printf("two") : printf("three"); return 0; }
What is the output of the following code?
#include<stdio.h> int main() { printf("%d", 0 != 0 ? printf("true") : printf("false")); return 0; }