100 Multiple Choice Questions In C Programming – Part 4

This collection of 100 Multiple Choice Questions and Answers (MCQs) In C Programming : Quizzes & Practice Tests with Answer focuses on “C Programming”.

1. What does != ?

A equals

B different

C less

D complement

The difference operator != Checks that a variable is different from a value. x!=3 Returns 1 if x is different from 3, else 0.



2. What is the problem when declaring the following variable?
float 4Room-Hall-Kitchen?;

A The variable name starts with an integer

B The special character “-”

C The special character “?”

D All the answers are true

The variable name must not start with an integer, and must not contain special character like “-, ?, …”.



3. What is the output of the following C program?
#include <stdio.h>

int main()
   int thisvariablename = 23;
   int ThisVariableName = 26;
   printf("%d", ThisVariableName);
   return 0;

A The program displays 23

B The program displays 26

C The program displays a runtime error

D The program will cause a compilation error due to the re-declaration

The variable names “thisvariablename” and “ThisVariableName” are different because C is case sensitive. The output is as follows:

$gcc prog4.c
$ a.out



4. After these operations, what will “res” be equal to?
int A = 4;
Res = 5 + A++;
Res += 2 + A;
Res -= 4 + (--A)
Res = Res + A++;

A 9

B 10

C 12

D 14

Increment/decrement a variable and at the same time assign its value to another variable. In this case we have to choose between prefix and postfix notation:

X = I++: first pass the value of I to X and then increment
X = I-- : first pass the value of I to X and then decrement
X = ++I : first increments and passes the incremented value to X
X = --I : decrement first and pass the decremented value to X

Example: Let’s suppose that the value of N is equal to 5:

Postfix increment:

X = N++;
Result: N=6 and X=5


Prefix increment:

X = ++N;
Result: N=6 and X=6



5. Which of these expressions should not be declared as a variable name?

A volatile

B export

C friend

D true

“volatile” is a keyword in C.



6. What is the output of the following C program?
#include <stdio.h>

int main()
   int a[4] = {1, 2, 3, 4};
   int i;
   for (i = 0; i < 4; i++)
        if ((char)a[i] == '4')
           printf("%d\n", a[i]);

A Compiler reports an error

B The program compiles and displays 4

C The program compiles and displays the ASCII value of 4

D The program compiles and displays FAIL 4 times

The ASCII value of 4 is 52, so the condition ((char)a[i] == '4') returns false. The output is as follows:

$gcc prog1.c
$ a.out



7. If the variable A = 0, what is the value of the variable B when the following code is executed?
if(A != 0) B=3; else B=0;

A B = 0

B B = 3

C Compilation error

D Will throw an exception

You are allowed to remove the curly braces { and } if you have only one statement after the condition.

For example:

	do something;
	do something else;

Can be written like this:


Or even like this:

if(condition) instructions; else instruction2;



8. How to make the variable A be a true boolean if B contains at least 1?

A A = B > 1

B A = B !=1

C A = B > 0

D A = B >= 0

If B contains 1 and A = B > 0. So the variable A will be true, because 1 > 0.

#include <stdio.h>

int main()
    int B = 1, A;
    A = B > 0;
    printf("%d", A);   // 1 <=> true
    return 0;



9. How many times do we get through the following loop?
int c = 10;

	printf("Hello World\n");
while(c < 10);

A 0

B 1

C 9

D 10

do…while… repeats a sequence of instructions as long as a condition is met. The group of instructions is executed at least one time.



10. The identifier ‘%i’ is also used for _____?

A char

B int

C float

D double

Both %d and %i can be used as format identifiers for integer variable.


mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *