C - Language MCQs for Interviews

c language interview questions
c language mcqs
  • Loops
  • Goto Label
  • Break and Continue
  • Functions

Loops – in C Language:

1. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. while ()
5. printf("In while loop ");
6. printf("After loop\n");
7. }
a) In while loop after loop
b) After loop
c) Compile time error
d) Infinite loop
Answer: c
Explanation: None.

2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. do
5. printf("In while loop ");
6. while (0);
7. printf("After loop\n");
8. }
a) In while loop
b) 
 In while loop
 after loop
c) After loop
d) Infinite loop
Answer: b
Explanation: None.

3. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. do {
6. i++;
7. printf("In while loop\n");
8. } while (i < 3);
9. }
a) 
 In while loop
 In while loop
 In while loop
b) 
 In while loop
 In while loop
c) Depends on the compiler
d) Compile time error
Answer: a
Explanation: None

4. How many times i value is checked in the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. do {
6. i++;
7. printf("in while loop\n");
8. } while (i < 3);
9. }
a) 2
b) 3
c) 4
d) 1
Answer: b
Explanation: None

5. How many times i value is checked in the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. while (i < 3)
6. i++;
7. printf("In while loop\n");
8. }
a) 2
b) 3
c) 4
d) 1
Answer: c
Explanation: None.

6. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 2;
5. do
6. {
7. printf("Hi");
8. } while (i < 2)
9. }
a) Compile time error
b) Hi Hi
c) Hi
d) Varies
Answer: a
Explanation: None

7. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. while (++i)
6. {
7. printf("H");
8. }
9. }
a) H
b) H is printed infinite times
c) Compile time error
d) Varies
Answer: b
Explanation: None.

8. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. do
6. {
7. printf("Hello");
8. } while (i != 0);
9. }
a) Nothing
b) H is printed infinite times
c) Hello
d) Run time error
Answer: c
Explanation: None

9. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. char *str = "";
5. do
6. {
7. printf("hello");
8. } while (str);
9. }
a) Nothing
b) Run time error
c) Varies
d) Hello is printed infinite times
Answer: d
Explanation: None.

10. What will be the output of the following C code?
1.#include <stdio.h>
2.void main()
3.{
4. int i = 0;
5. while (i < 10)
6. {
7. i++;
8. printf("hi\n");
9. while (i < 8) 
10. {
11. i++;
12. printf("hello\n");
13. }
14. }
15.}
a) Hi is printed 8 times, hello 7 times and then
hi 2 times
b) Hi is printed 10 times, hello 7 times
c) Hi is printed once, hello 7 times
d) Hi is printed once, hello 7 times and then hi 
2 times
Answer: d
Explanation: None.

11. What is an example of iteration in C?
a) for
b) while
c) do-while
d) all of the mentioned
Answer: d
Explanation: None.

12. How many times while loop condition is tested in the following C code snippets, if i is initialized to 0 in both the cases?
1.while (i < n)
2. i++;
3. ————-
4. do
5. i++;
6. while (i <= n);
a) n, n
b) n, n+1
c) n+1, n
d) n+1, n+1
Answer: d
Explanation: None

13. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. while (i = 0)
6. printf("True\n");
7. printf("False\n");
8. }
a) True (infinite time)
b) True (1 time) False
c) False
d) Compiler dependent
Answer: c
Explanation: None.

14. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. while (i < 5, j < 10)
6. {
7. i++;
8. j++;
9. }
10. printf("%d, %d\n", i, j);
11. }
a) 5, 5
b) 5, 10
c) 10, 10
d) Syntax error
Answer: c
Explanation: None

15. Which loop is most suitable to first perform the operation and then test the condition?
a) for loop
b) while loop
c) do-while loop
d) none of the mentioned
Answer: c
Explanation: None

Break and Continue:

1. Which keyword can be used for coming out of recursion?
a) break
b) return
c) exit
d) both break and return
Answer: b
Explanation: None

2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int a = 0, i = 0, b;
5. for (i = 0;i < 5; i++)
6. {
7. a++;
8. continue;
9. }
10. }
a) 2
b) 3
c) 4
d) 5
Answer: d
Explanation: None

3. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int a = 0, i = 0, b;
5. for (i = 0;i < 5; i++)
6. {
7. a++;
8. if (i == 3)
9. break;
10. }
11. }
a) 1
b) 2
c) 3
d) 4
Answer: d
Explanation: None.

4. The keyword ‘break’ cannot be simply used within _________
a) do-while
b) if-else
c) for
d) while
Answer: b
Explanation: None.

5. Which keyword is used to come out of a loop only for that iteration?
a) break
b) continue
c) return
d) none of the mentioned
Answer: b
Explanation: None

6. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0, j = 0;
5. for (i = 0;i < 5; i++)
6. {
7. for (j = 0;j < 4; j++)
8. {
9. if (i > 1)
10. break;
11. }
12. printf("Hi \n");
13. }
14. }
a) Hi is printed 5 times
b) Hi is printed 9 times
c) Hi is printed 7 times
d) Hi is printed 4 times
Answer: a
Explanation: None

7. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. int j = 0;
6. for (i = 0;i < 5; i++)
7. {
8. for (j = 0;j < 4; j++)
9. {
10. if (i > 1)
11. continue;
12. printf("Hi \n");
13. }
14. }
15. }
a) Hi is printed 9 times
b) Hi is printed 8 times
c) Hi is printed 7 times
d) Hi is printed 6 times
Answer: b
Explanation: None

8. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. for (i = 0;i < 5; i++)
6. if (i < 4)
7. {
8. printf("Hello");
9. break;
10. }
11. }
a) Hello is printed 5 times
b) Hello is printed 4 times
c) Hello
d) Hello is printed 3 times
Answer: c
Explanation: None

9. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. if (i == 0)
6. {
7. printf("Hello");
8. continue;
9. }
10. }
a) Hello is printed infinite times
b) Hello
c) Varies
d) Compile time error
Answer: d
Explanation: None

10. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. if (i == 0)
6. {
7. printf("Hello");
8. break;
9. }
10. }
a) Hello is printed infinite times
b) Hello
c) Varies
d) Compile time error
Answer: d
Explanation: None.

11. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. do
6. {
7. i++;
8. if (i == 2)
9. continue;
10. printf("In while loop ");
11. } while (i < 2);
12. printf("%d\n", i);
13. }
a) In while loop 2
b) In while loop in while loop 3
c) In while loop 3
d) Infinite loop
Answer: a
Explanation: None. 

12. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. for (i; i < 2; i++){
6. for (j = 0; j < 3; j++){
7. printf("1\n");
8. break;
9. }
10. printf("2\n");
11. }
12. printf("after loop\n");
13. }
a)
 1
 2
 after loop
b)
 1
 after loop
c)
 1
 2
 1
 2
 after loop
d)
 1
 1
 2
 after loop
Answer: c
Explanation: None. 

13. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. while (i < 2)
6. {
7. if (i == 1)
8. break;
9. i++;
10. if (i == 1)
11. continue;
12. printf("In while loop\n");
13. }
14. printf("After loop\n");
15. }
a) 
 In while loop
 After loop
b) After loop
c) 
 In while loop
 In while loop
 After loop
d) In while loop
Answer: b
Explanation: None. 

14. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. char c = 'a';
6. while (i < 2){
7. i++;
8. switch (c) {
9. case 'a':
10. printf("%c ", c);
11. break;
12. break;
13. }
14. }
15. printf("after loop\n");
16. }
a) a after loop
b) a a after loop
c) after loop
d) None of the mentioned
Answer: b
Explanation: None. 

15. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. printf("before continue ");
5. continue;
6. printf("after continue\n");
7. }
a) Before continue after continue
b) Before continue
c) After continue
d) Compile time error
Answer: d
Explanation: None.

Goto & Labels

1. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d ", 1);
5. goto l1;
6. printf("%d ", 2);
7. l1:goto l2;
8. printf("%d ", 3);
9. l2:printf("%d ", 4);
10. }
a) 1 4
b) Compilation error
c) 1 2 4
d) 1 3 4
Answer: a
Explanation: None.

2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d ", 1);
5. l1:l2:
6. printf("%d ", 2);
7. printf("%d\n", 3);
8. }
a) Compilation error
b) 1 2 3
c) 1 2
d) 1 3
Answer: b
Explanation: None.

3. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d ", 1);
5. goto l1;
6. printf("%d ", 2);
7. }
8. void foo()
9. {
10. l1 : printf("3 ", 3);
11. }
a) 1 2 3
b) 1 3
c) 1 3 2
d) Compilation error
Answer: d
Explanation: None.

4. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. while (i < 2)
6. {
7. l1 : i++;
8. while (j < 3)
9. {
10. printf("Loop\n");
11. goto l1;
12. }
13. }
14. }
a) Loop Loop
b) Compilation error
c) Loop Loop Loop Loop
d) Infinite Loop
Answer: d
Explanation: None.

5. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. while (l1: i < 2)
6. {
7. i++;
8. while (j < 3)
9. {
10. printf("loop\n");
11. goto l1;
12. }
13. }
14. }
a) loop loop
b) Compilation error
c) loop loop loop loop
d) Infinite loop
Answer: b
Explanation: None.

6. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. l1: while (i < 2)
6. {
7. i++;
8. while (j < 3)
9. {
10. printf("loop\n");
11. goto l1;
12. }
13. }
14. }
a) loop loop
b) compilation error
c) oop loop loop loop
d) infinite loop
Answer: a
Explanation: None.

7. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0;
5. if (i == 0)
6. {
7. goto label;
8. }
9. label: printf("Hello");
10. }
a) Nothing
b) Error
c) Infinite Hello
d) Hello
Answer: d
Explanation: None. 

8. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0, k;
5. if (i == 0)
6. goto label;
7. for (k = 0;k < 3; k++)
8. {
9. printf("hi\n");
10. label: k = printf("%03d", i);
11. }
12. }
a) 0
b) hi hi hi 0 0 0
c) 0 hi hi hi 0 0 0
d) 0 0 0
Answer: a
Explanation: None.

9. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 0, k;
5. label: printf("%d", i);
6. if (i == 0)
7. goto label;
8. }
a) 0
b) Infinite 0
c) Nothing
d) Error
Answer: b
Explanation: None

10. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int i = 5, k;
5. if (i == 0)
6. goto label;
7. label: printf("%d", i);
8. printf("Hey");
9. }
a) 5
b) Hey
c) 5 Hey
d) Nothing
Answer: c
Explanation: None.

11. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. l1: while (i < 2)
6. {
7. i++;
8. while (j < 3)
9. {
10. printf("loop\n");
11. goto l1;
12. }
13. }
14. }
a) loop loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
Answer: a
Explanation: None

12. goto can be used to jump from main() to within a function.
a) true
b) false
c) depends
d) varies
Answer: b
Explanation: None.

13. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d ", 1);
5. goto l1;
6. printf("%d ", 2);
7. l1:goto l2;
8. printf("%d ", 3);
9. l2:printf("%d ", 4);
10. }
a) 1 4
b) Compile time error
c) 1 2 4
d) 1 3 4
Answer: a
Explanation: None.

14. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d ", 1);
5. l1:l2:
6. printf("%d ", 2);
7. printf("%d\n", 3);
8. }
a) Compile time error
b) 1 2 3
c) 1 2
d) 1 3
Answer: b
Explanation: None.

15. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d ", 1);
5. goto l1;
6. printf("%d ", 2);
7. }
8. void foo()
9. {
10. l1: printf("3 ", 3);
11. }
a) 1 2 3
b) 1 3
c) 1 3 2
d) Compile time error
Answer: d
Explanation: None.

16. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. while (i < 2)
6. {
7. l1: i++;
8. while (j < 3)
9. {
10. printf("loop\n");
11. goto l1;
12. }
13. }
14. }
a) loop loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
Answer: d
Explanation: None.

17. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0, j = 0;
5. while (l1: i < 2)
6. {
7. i++;
8. while (j < 3)
9. {
10. printf("loop\n");
11. goto l1;
12. }
13. }
14. }
a) loop loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
Answer: b
Explanation: None.

Functions in C Language

1. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. void foo();
5. printf("1 ");
6. foo();
7. }
8. void foo()
9. {
10. printf("2 ");
11. }
a) 1 2
b) Compile time error
c) 1 2 1 2
d) Depends on the compiler
Answer: a
Explanation: None. 

2. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. void foo(), f();
5. f();
6. }
7. void foo()
8. {
9. printf("2 ");
10. }
11. void f()
12. {
13. printf("1 ");
14. foo();
15. }
a) Compile time error as foo is local to main
b) 1 2
c) 2 1
d) Compile time error due to declaration of 
functions inside main
Answer: b
Explanation: None. 

3. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. void foo();
5. void f()
6. {
7. foo();
8. }
9. f();
10. }
11. void foo()
12. {
13. printf("2 ");
14. }
a) 2 2
b) 2
c) Compile time error
d) Depends on the compiler
Answer: d
Explanation: 
Even though the answer is 2, this code will
compile fine only with gcc. GNU C supports
nesting of functions in C as a language extension
whereas standard C compiler doesn’t. 

4. What will be the output of the following C code?
1. #include <stdio.h>
2. void foo();
3. int main()
4. {
5. void foo();
6. foo();
7. return 0;
8. }
9. void foo()
10. {
11. printf("2 ");
12. }
a) Compile time error
b) 2
c) Depends on the compiler
d) Depends on the standard
Answer: b
Explanation: None.

5. What will be the output of the following C code?
1. #include <stdio.h>
2. void foo();
3. int main()
4. {
5. void foo(int);
6. foo(1);
7. return 0;
8. }
9. void foo(int i)
10. {
11. printf("2 ");
12. }
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
Answer: a
Explanation: None.

6. What will be the output of the following C code?
1. #include <stdio.h>
2. void foo();
3. int main()
4. {
5. void foo(int);
6. foo();
7. return 0;
8. }
9. void foo()
10. {
11. printf("2 ");
12. }
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
Answer: b
Explanation: None.

7. What will be the output of the following C code?
1. #include <stdio.h>
2. void m()
3. {
4. printf("hi");
5. }
6. void main()
7. {
8. m();
9. }
a) hi
b) Run time error
c) Nothing
d) Varies
Answer: a
Explanation: None.

8. What will be the output of the following C code?
1. #include <stdio.h>
2. void m();
3. void n()
4. {
5. m();
6. }
7. void main()
8. {
9. void m()
10. {
11. printf("hi");
12. }
13. }
a) hi
b) Compile time error
c) Nothing
d) Varies
Answer: b
Explanation: None.

9. Functions can return enumeration constants in C?
a) true
b) false
c) depends on the compiler
d) depends on the standard
Answer: a
Explanation: None.

10. What will be the output of the following C code?
1. #include <stdio.h>
2. enum m{JAN, FEB, MAR};
3. enum m foo();
4. int main()
5. {
6. enum m i = foo();
7. printf("%d\n", i);
8. }
9. int foo()
10. {
11. return JAN;
12. }
a) Compile time error
b) 0
c) Depends on the compiler
d) Depends on the standard
Answer: a
Explanation: None.

11. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. m();
5. void m()
6. {
7. printf("hi");
8. }
9. }
a) hi
b) Compile time error
c) Nothing
d) Varies
Answer: b
Explanation: None.

12. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. m();
5. }
6. void m()
7. {
8. printf("hi");
9. m();
10. }
a) Compile time error
b) hi
c) Infinite hi
d) Nothing
Answer: c
Explanation: None.

13. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. static int x = 3;
5. x++;
6. if (x <= 5)
7. {
8. printf("hi");
9. main();
10. }
11. }
a) Run time error
b) hi
c) Infinite hi
d) hi hi
Answer: d
Explanation: None.

14. Which of the following is the correct format for the declaration of function?
a) return-type function-name(argument type);
b) return-type function-name(argument type){}
c) return-type (argument type)function-name;
d) all of the mentioned
Answer: a
Explanation: None.

15. Which of the following function declaration is illegal?
a) int 1bhk(int);
b) int 1bhk(int a);
c) int 2bhk(int*, int []);
d) all of the mentioned
Answer: d
Explanation: None.

👉 also, read this TCS Ninja Aptitude Questions and Answers