Explore topic-wise MCQs in C Programming.

This section includes 117 Mcqs, each offering curated multiple-choice questions to sharpen your C Programming knowledge and support exam preparation. Choose a topic below to get started.

51.

Select output for the following set of code:

A. 1 2 3 4 5 6 7 8 9
B. 25
C. 1
D. Run time error
Answer» E.
52.

Which of the code should be added to get the following output?

A. for (i = 0;i <= 4; i++){for(j = 4;j <= i; j–)console.WriteLine(“*”);console.WriteLine(“\n”);}
B. for (i = 0;i <= 4; i++)
C. for (i = 0;i <= 4; i++){for (j = i;j <= 4; j++)console.WriteLine(“*”);console.WriteLine(“\n”);}
D. for ( i = 0;i <= 4; i++){for (j = 0;j <= i; j++)console.WriteLine(“*”);console.WriteLine(“\n”);}
Answer» D. for ( i = 0;i <= 4; i++){for (j = 0;j <= i; j++)console.WriteLine(“*”);console.WriteLine(“\n”);}
53.

Select the output for the following set of code.

A. 3 Idiots
B. Ghazini
C. Race
D. Krishh
Answer» D. Krishh
54.

Select output for the following set of code :

A. 1 3 1
B. 2 3 4
C. 5 3 4
D. Compile time error.
Answer» B. 2 3 4
55.

Select the output for the following code :

A. amish
B. ANKIT
C. harsh
D. Compile time error
Answer» E.
56.

Select the output for the following set of Code:

A. Compile time error
B. case A|case a
C. case B|case b
D. case D|case d
Answer» E.
57.

Select output for the following code:

A. 23
B. 15
C. Compile time error
D. 12
Answer» D. 12
58.

Which of the following is not infinite loop?

A. for( ;’0′; )
B. for( ;’0′; )
C. for( ;’1′; )
D. for( ;’1′; )
Answer» B. for( ;’0′; )
59.

Which of the following statements are correct?1. A switch statement can act on numerical as well as Boolean types.2. A switch statement can act on characters, strings and enumerations types.3. We cannot declare variables within a case statement if it is not enclosed by { }.4. The foreach statement is used to iterate through the collection to get the desired information and should be used to change the contents of the collection to avoid unpredictable side effects.5. All of the expressions of the for statement are not optional.

A. 1, 2
B. 2, 3
C. 3, 5
D. 4, 5
Answer» B. 2, 3
60.

Which statement is correct among the mentioned statements?1. The for loop works faster than a while loop2. for( ; ; )implements an infinite loop

A. Only 1 is correct
B. Only 2 is correct
C. Both 1 and 2 are correct
D. Both 1 and 2 are incorrect
Answer» C. Both 1 and 2 are correct
61.

Which of the following can be used to terminate a while loop and transfer control outside the loop?1. exit while2. continue3. exit statement4. break5. goto

A. 1, 3
B. 2, 4
C. 3, 5
D. 4, 5
Answer» E.
62.

The keyword 'break' cannot be simply used within _________

A. do-while
B. if-else
C. for
D. while
Answer» C. for
63.

Which keyword can be used for coming out of recursion?

A. break
B. return
C. exit
D. both break and return
Answer» C. exit
64.

Which datatype can accept switch statement?

A. int
B. char
C. long
D. all of the mentioned
Answer» E.
65.

The C code 'for(;;)' represents an infinite loop. It can be terminated by ___________

A. break
B. exit(0)
C. abort()
D. terminate
Answer» B. exit(0)
66.

Which for loop has range of similar indexes of 'i' used in for (i = 0;i < n; i++)?

A. for (i = n; i>0; i–)
B. for (i = n; i >= 0; i–)
C. for (i = n-1; i>0; i–)
D. for (i = n-1; i>-1; i–)
Answer» E.
67.

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» D. none of the mentioned
68.

What will be the output of the program? #include int main() { int x, y, z; x=y=z=1; z = ++x || ++y && ++z; printf("x=%d, y=%d, z=%d\n", x, y, z); return 0; }

A. x=2, y=1, z=1
B. x=2, y=2, z=1
C. x=2, y=2, z=2
D. x=1, y=2, z=1
Answer» B. x=2, y=2, z=1
69.

Point out the error, if any in the while loop. #include int main() { void fun(); int i = 1; while(i <= 5) { printf("%d\n", i); if(i>2) goto here; } return 0; } void fun() { here: printf("It works"); }

A. No Error: prints "It works"
B. Error: fun() cannot be accessed
C. Error: goto cannot takeover control to other function
D. No error
Answer» D. No error
70.

What will be the output of the program? #include int main() { int a=0, b=1, c=3; *((a) ? &b : &a) = a ? b : c; printf("%d, %d, %d\n", a, b, c); return 0; }

A. 0, 1, 3
B. 1, 2, 3
C. 3, 1, 3
D. 1, 3, 1
Answer» D. 1, 3, 1
71.

Which of the following sentences are correct about a for loop in a C program? 1: for loop works faster than a while loop. 2: All things that can be done using a for loop can also be done using a while loop. 3: for(;;); implements an infinite loop. 4: for loop can be used if we want statements in a loop get executed at least once.

A. 1
B. 1, 2
C. 2, 3
D. 2, 3, 4
Answer» E.
72.

What will be the output of the program? #include int main() { int i=4; switch(i) { default: printf("This is default\n"); case 1: printf("This is case 1\n"); break; case 2: printf("This is case 2\n"); break; case 3: printf("This is case 3\n"); } return 0; }

A. This is default This is case 1
B. This is case 3 This is default
C. This is case 1 This is case 3
D. This is default
Answer» B. This is case 3 This is default
73.

What will be the output of the program? #include int main() { float a = 0.7; if(0.7 > a) printf("Hi\n"); else printf("Hello\n"); return 0; }

A. Hi
B. Hello
C. Hi Hello
D. None of above
Answer» B. Hello
74.

What will be the output of the program? #include int main() { int i = 5; while(i-- >= 0) printf("%d,", i); i = 5; printf("\n"); while(i-- >= 0) printf("%i,", i); while(i-- >= 0) printf("%d,", i); return 0; }

A. 4, 3, 2, 1, 0, -14, 3, 2, 1, 0, -1
B. 5, 4, 3, 2, 1, 05, 4, 3, 2, 1, 0
C. Error
D. 5, 4, 3, 2, 1, 05, 4, 3, 2, 1, 05, 4, 3, 2, 1, 0
Answer» B. 5, 4, 3, 2, 1, 05, 4, 3, 2, 1, 0
75.

What will be the output of the program? #include int main() { int i = 1; switch(i) { printf("Hello\n"); case 1: printf("Hi\n"); break; case 2: printf("\nBye\n"); break; } return 0; }

A. HelloHi
B. HelloBye
C. Hi
D. Bye
Answer» D. Bye
76.

What will be the output of the program? #include int main() { int x=1, y=1; for(; y; printf("%d %d\n", x, y)) { y = x++ <= 5; } printf("\n"); return 0; }

A. 2 13 14 15 16 17 0
B. 2 13 14 15 16 1
C. 2 13 14 15 1
D. 2 23 34 45 5
Answer» B. 2 13 14 15 16 1
77.

Which of the following sentences are correct about a switch loop in a C program? 1: switch is useful when we wish to check the value of variable against a particular set of values. 2: switch is useful when we wish to check whether a value falls in different ranges. 3: Compiler implements a jump table for cases used in switch. 4: It is not necessary to use a break in every switch statement.

A. 1,2
B. 1,3,4
C. 2,4
D. 2
Answer» C. 2,4
78.

What will be the output of the program? #include int main() { unsigned int i = 65536; /* Assume 2 byte integer*/ while(i != 0) printf("%d",++i); printf("\n"); return 0; }

A. Infinite loop
B. 0 1 2 ... 65535
C. 0 1 2 ... 32767 - 32766 -32765 -1 0
D. No output
Answer» E.
79.

What will be the output of the program? #include int main() { char ch; if(ch = printf("")) printf("It matters\n"); else printf("It doesn't matters\n"); return 0; }

A. It matters
B. It doesn't matters
C. matters
D. No output
Answer» C. matters
80.

What will be the output of the program? #include int main() { char j=1; while(j < 5) { printf("%d, ", j); j = j+1; } printf("\n"); return 0; }

A. 1 2 3 ... 127
B. 1 2 3 ... 255
C. 1 2 3 ... 127 128 0 1 2 3 ... infinite times
D. 1, 2, 3, 4
Answer» E.
81.

Which of the following statements are correct about the below program? #include int main() { int n = 0, y = 1; y == 1 ? n=0 : n=1; if(n) printf("Yes\n"); else printf("No\n"); return 0; }

A. Error: Declaration terminated incorrectly
B. Error: Syntax error
C. Error: Lvalue required
D. None of above
Answer» D. None of above
82.

What will be the output of the program? #include int main() { int a = 300, b, c; if(a >= 400) b = 300; c = 200; printf("%d, %d, %d\n", a, b, c); return 0; }

A. 300, 300, 200
B. Garbage, 300, 200
C. 300, Garbage, 200
D. 300, 300, Garbage
Answer» D. 300, 300, Garbage
83.

Point out the error, if any in the program. #include int main() { int i = 1; switch(i) { case 1: printf("Case1"); break; case 1*2+4: printf("Case2"); break; } return 0; }

A. Error: in case 1*2+4 statement
B. Error: No default specified
C. Error: in switch statement
D. No Error
Answer» E.
84.

What will be the output of the program? #include int main() { int i=3; switch(i) { case 1: printf("Hello\n"); case 2: printf("Hi\n"); case 3: continue; default: printf("Bye\n"); } return 0; }

A. Error: Misplaced continue
B. Bye
C. No output
D. Hello Hi
Answer» B. Bye
85.

Point out the error, if any in the program. #include int main() { int a = 10, b; a >=5 ? b=100: b=200; printf("%d\n", b); return 0; }

A. 100
B. 200
C. Error: L value required for b
D. Garbage value
Answer» D. Garbage value
86.

By default, the data type of a constant without a decimal point is int, whereas the one with a decimal point is a double.

A. Yes
B. No
Answer» B. No
87.

What will be the output of the program? #include int main() { int k, num = 30; k = (num < 10) ? 100 : 200; printf("%d\n", num); return 0; }

A. 200
B. 30
C. 100
D. 500
Answer» C. 100
88.

What will be the output of the program? #include int main() { unsigned int i = 65535; /* Assume 2 byte integer*/ while(i++ != 0) printf("%d",++i); printf("\n"); return 0; }

A. Infinite loop
B. 0 1 2 ... 65535
C. 0 1 2 ... 32767 - 32766 -32765 -1 0
D. No output
Answer» B. 0 1 2 ... 65535
89.

What will be the output of the program? #include int main() { int x = 3; float y = 3.0; if(x == y) printf("x and y are equal"); else printf("x and y are not equal"); return 0; }

A. x and y are equal
B. x and y are not equal
C. Unpredictable
D. No output
Answer» B. x and y are not equal
90.

Point out the error, if any in the program. #include int main() { int i = 1; switch(i) { printf("This is c program."); case 1: printf("Case1"); break; case 2: printf("Case2"); break; } return 0; }

A. Error: No default specified
B. Error: Invalid printf statement after switch statement
C. No Error and prints "Case1"
D. None of above
Answer» D. None of above
91.

What will be the output of the program, if a short int is 2 bytes wide? #include int main() { short int i = 0; for(i<=5 && i>=-1; ++i; i>0) printf("%u,", i); return 0; }

A. 1 ... 65535
B. Expression syntax error
C. No output
D. 0, 1, 2, 3, 4, 5
Answer» B. Expression syntax error
92.

We want to test whether a value lies in the range 2 to 4 or 5 to 7. Can we do this using a switch?

A. Yes
B. No
Answer» B. No
93.

Which of the following statements are correct about the below program? #include int main() { int i = 0; i++; if(i <= 5) { printf("IndiaBIX\n"); exit(0); main(); } return 0; }

A. The program prints 'IndiaBIX' 5 times
B. The program prints 'IndiaBIX' one time
C. The call to main() after exit() doesn't materialize.
D. The compiler reports an error since main() cannot call itself.
Answer» C. The call to main() after exit() doesn't materialize.
94.

If scanf() is used to store a value in a char variable then along with the value a carriage return(\r) also gets stored it.

A. 1
B.
Answer» C.
95.

Which of the following statements are correct about the below program? #include int main() { int i = 10, j = 15; if(i % 2 = j % 3) printf("IndiaBIX\n"); return 0; }

A. Error: Expression syntax
B. Error: Lvalue required
C. Error: Rvalue required
D. The Code runs successfully
Answer» C. Error: Rvalue required
96.

Can we use a switch statement to switch on strings?

A. Yes
B. No
Answer» C.
97.

What will be the output of the program? #include int main() { int a = 500, b = 100, c; if(!a >= 400) b = 300; c = 200; printf("b = %d c = %d\n", b, c); return 0; }

A. b = 300 c = 200
B. b = 100 c = garbage
C. b = 300 c = garbage
D. b = 100 c = 200
Answer» E.
98.

Which of the following statements are correct about the program? #include int main() { int x = 30, y = 40; if(x == y) printf("x is equal to y\n"); else if(x > y) printf("x is greater than y\n"); else if(x < y) printf("x is less than y\n") return 0; }

A. Error: Statement missing
B. Error: Expression syntax
C. Error: Lvalue required
D. Error: Rvalue required
Answer» B. Error: Expression syntax
99.

Point out the error, if any in the program. #include int main() { int a = 10; switch(a) { } printf("This is c program."); return 0; }

A. Error: No case statement specified
B. Error: No default specified
C. No Error
D. Error: infinite loop occurs
Answer» D. Error: infinite loop occurs
100.

Which of the following statements are correct about an if-else statements in a C-program? 1: Every if-else statement can be replaced by an equivalent statements using   ?: operators 2: Nested if-else statements are allowed. 3: Multiple statements in an if block are allowed. 4: Multiple statements in an else block are allowed.

A. 1 and 2
B. 2 and 3
C. 1, 2 and 4
D. 2, 3, 4
Answer» E.