Skip to content
StudyFame

C Programming MCQs

Multiple-choice questions are common in placement tests, competitive exams and university internal tests. They check whether you know the exact rule, not just the general idea, so small details like integer division, operator precedence and string termination decide the answer.

Here are 30 C MCQs in six sets, covering the whole tutorial, with answers and short explanations after each set. Try a set, note your answers, then open the solutions. Aim for at least 25/30.

What You Will Learn

  • 30 MCQs from every part of C.
  • Short explanations for each answer.
  • Two programs that prove the trickiest answers.
  • Strategies to eliminate wrong options quickly.
  • Which topics to revise based on your score.

C Programming MCQs Explained

Strategy: (1) Read the code or question twice. (2) Eliminate options that break a basic rule (e.g. arrays starting at 1). (3) Check types and precedence. (4) If two options look right, look for the hidden detail: '\0', integer division, missing break, = vs ==. (5) If the code modifies a variable twice in one expression, pick "undefined behavior".

Memory trick: Treat each MCQ like spot the difference: the four options differ in one small detail, and that detail is the rule being tested. Find it before you calculate.

Set 1: Basics and Data Types

  1. Which of these is a valid identifier?

    A) 2total   B) total_2   C) total-2   D) int

  2. The size of char is always:

    A) 1 byte   B) 2 bytes   C) 4 bytes   D) Compiler dependent

  3. Which format specifier prints a double?

    A) %d   B) %c   C) %lf or %f   D) %s

  4. Which is not a C keyword?

    A) auto   B) volatile   C) main   D) register

  5. The range of an unsigned char is:

    A) −128 to 127   B) 0 to 255   C) 0 to 127   D) −255 to 255

Show answers: Set 1
  1. B: identifiers can't start with a digit, contain '-', or be keywords.
  2. A: sizeof(char) is 1 by definition of the C standard.
  3. C: printf uses %f for double (%lf also works); scanf needs %lf for double.
  4. C: main is a function name, not a keyword.
  5. B: 8 bits without a sign gives 0 to 255.

Set 2: Operators and Expressions

  1. Value of 10 + 4 * 2 - 6 / 3?

    A) 26   B) 16   C) 12   D) 10

  2. Value of 5 > 3 && 2 > 4 || 1?

    A) 0   B) 1   C) 2   D) Error

  3. Value of 17 % 5?

    A) 3   B) 2   C) 3.4   D) 12

  4. Which operator has the highest precedence?

    A) +   B) =   C) ()   D) &&

  5. Value of ~0 for a signed int (two's complement)?

    A) 0   B) 1   C) −1   D) 255

Show answers: Set 2
  1. B: 4*2 = 8 and 6/3 = 2 first: 10 + 8 − 2 = 16.
  2. B: && before ||: (1 && 0) || 1 = 0 || 1 = 1.
  3. B: 17 = 3 × 5 + 2.
  4. C: function call/brackets have the highest precedence.
  5. C: all bits become 1, which is −1 in two's complement.

Set 3: Control Flow and Loops

  1. How many times does for (i = 0; i < 10; i += 3) run?

    A) 3   B) 4   C) 10   D) 9

  2. The switch expression cannot be of type:

    A) int   B) char   C) float   D) enum

  3. Which statement skips the rest of the current iteration?

    A) break   B) exit   C) continue   D) return

  4. while (0) printf("hi"); prints "hi":

    A) Once   B) Never   C) Forever   D) Error

  5. Which loop is guaranteed to run at least once?

    A) for   B) while   C) do-while   D) None

Show answers: Set 3
  1. B: i = 0, 3, 6, 9 → 4 times.
  2. C: switch needs an integer type.
  3. C: continue.
  4. B: the condition is false from the start.
  5. C: do-while checks after the body.

Example 1: Proving Sets 2 and 3

#include <stdio.h>

int main(void)
{
    int i, count = 0;

    printf("10 + 4 * 2 - 6 / 3 = %d\n", 10 + 4 * 2 - 6 / 3);
    printf("5 > 3 && 2 > 4 || 1 = %d\n", 5 > 3 && 2 > 4 || 1);
    printf("~0 = %d\n", ~0);

    for (i = 0; i < 10; i += 3)
        count++;
    printf("loop ran %d times\n", count);
    return 0;
}

Output

10 + 4 * 2 - 6 / 3 = 16
5 > 3 && 2 > 4 || 1 = 1
~0 = -1
loop ran 4 times

Code Explanation

  1. The first line confirms that * and / are evaluated before + and −.
  2. The second line confirms that && is evaluated before ||.
  3. ~0 flips all bits of 0, giving −1 on two's complement machines (all common computers).
  4. The counter proves the loop runs for i = 0, 3, 6 and 9.

Set 4: Arrays, Strings and Functions

  1. For int a[5];, the valid indexes are:

    A) 1 to 5   B) 0 to 5   C) 0 to 4   D) 1 to 4

  2. sizeof("Hello") is:

    A) 5   B) 6   C) 4   D) 8

  3. strcmp("apple", "banana") returns:

    A) 0   B) A positive value   C) A negative value   D) 1 always

  4. By default, arguments in C are passed:

    A) By reference   B) By value   C) By name   D) By pointer always

  5. A function that calls itself is:

    A) Inline   B) Recursive   C) Static   D) Variadic

Show answers: Set 4
  1. C: indexes start at 0, so the last is 4.
  2. B: 5 letters plus the hidden '\0'.
  3. C: "apple" comes before "banana" alphabetically.
  4. B: C always passes copies; passing a pointer copies the address.
  5. B: recursive.

Set 5: Pointers, Structures and Memory

  1. If int x = 5, *p = &x;, what is *p + 1?

    A) Address + 1   B) 6   C) 5   D) Error

  2. Which operator accesses a member through a structure pointer?

    A) .   B) ->   C) ::   D) &

  3. Which function allocates memory initialised to zero?

    A) malloc   B) calloc   C) realloc   D) alloc

  4. For union u { int i; char c[8]; }; (4-byte int), sizeof(union u) is:

    A) 12   B) 8   C) 4   D) 1

  5. Using memory after freeing it creates a:

    A) NULL pointer   B) Void pointer   C) Dangling pointer   D) Function pointer

Show answers: Set 5
  1. B: *p is 5, plus 1 is 6.
  2. B: ->.
  3. B: calloc.
  4. B: a union is as big as its largest member (8 bytes here).
  5. C: dangling pointer.

Set 6: Files, Preprocessor and Advanced

  1. Which mode opens a file for reading and writing without erasing it?

    A) "w+"   B) "r+"   C) "a"   D) "w"

  2. fopen returns what when it fails?

    A) 0 bytes   B) NULL   C) EOF   D) −1

  3. Macros are expanded by the:

    A) Compiler   B) Linker   C) Preprocessor   D) Loader

  4. In int main(int argc, char *argv[]), argv[0] is:

    A) The first argument   B) The program name   C) NULL   D) argc

  5. Which header declares va_list?

    A) stdlib.h   B) stdarg.h   C) stdio.h   D) varargs.h only

Show answers: Set 6
  1. B: "r+" keeps the content; "w+" erases it.
  2. B: NULL.
  3. C: the preprocessor.
  4. B: the program name.
  5. B: stdarg.h.

Example 2: Proving Sets 4 and 5

#include <stdio.h>
#include <string.h>

union u
{
    int i;
    char c[8];
};

int main(void)
{
    int x = 5, *p = &x;

    printf("sizeof(\"Hello\") = %zu\n", sizeof("Hello"));
    printf("strcmp(\"apple\", \"banana\") is %s\n",
           strcmp("apple", "banana") < 0 ? "negative" : "not negative");
    printf("*p + 1 = %d\n", *p + 1);
    printf("sizeof(union u) = %zu\n", sizeof(union u));
    return 0;
}

Output

sizeof("Hello") = 6
strcmp("apple", "banana") is negative
*p + 1 = 6
sizeof(union u) = 8
  • A string literal's size includes the terminating '\0'.
  • strcmp's exact negative value can differ between systems; only its sign matters.
  • The union's size equals its largest member, the 8-byte array.

Important Points to Remember

  • Precedence: () > unary > * / % > + − > relational > && > || > =.
  • Strings take one extra byte for '\0'.
  • Arrays index from 0 to n − 1.
  • C passes arguments by value only.
  • union size = largest member; struct size ≥ sum of members.
  • Scoring: 26–30 excellent; 20–25 revise the weak set; below 20 revise the full module.

Common Mistakes Beginners Make

TrapCommon wrong answerRight answer
sizeof("Hi")23
Last index of int a[10]109
Is main a keyword?YesNo
"w+" keeps old content?YesNo, it erases the file
C supports call by reference directly?YesNo; it simulates it with pointers (passed by value)

MCQ Practice Questions

  1. What is sizeof(int) * 2 on a system with 4-byte int?
  2. What does printf("%d", 'A' + 1); print?
  3. How many times does for (i = 5; i > 0; i -= 2) run?
  4. What is strlen("C\0Program")?
  5. What is (int) 3.99?
Show answers
  1. 8.
  2. 66.
  3. 3 times (i = 5, 3, 1).
  4. 1: strlen stops at the first '\0'.
  5. 3: casting to int truncates toward zero.

Coding Exercise

Write a tiny MCQ checker: given the answer key "BCABD" and a student's answers "BCDBD", print each question's result and the score out of 5.

Show solution
#include <stdio.h>

int main(void)
{
    const char key[] = "BCABD", given[] = "BCDBD";
    int i, score = 0;

    for (i = 0; key[i] != '\0'; i++)
    {
        int ok = key[i] == given[i];
        score += ok;
        printf("Q%d: %c %s\n", i + 1, given[i], ok ? "correct" : "wrong");
    }
    printf("Score: %d/5\n", score);
    return 0;
}
Q1: B correct
Q2: C correct
Q3: D wrong
Q4: B correct
Q5: D correct
Score: 4/5

Quick Quiz: Mixed C MCQs

  1. printf("%d", 3 + 5 / 2); prints:

    A) 4   B) 5   C) 5.5   D) 4.0

  2. Which is the correct way to declare a pointer to int?

    A) int p*;   B) int *p;   C) *int p;   D) pointer int p;

  3. Which header declares malloc?

    A) malloc.h only   B) stdlib.h   C) memory.h   D) stdio.h

  4. A structure variable s accesses member age as:

    A) s->age   B) s.age   C) s:age   D) s[age]

  5. EOF is defined in:

    A) stdio.h   B) stdlib.h   C) string.h   D) ctype.h

Show answers
  1. B: 5 / 2 = 2, so 3 + 2 = 5.
  2. B: int *p;
  3. B: stdlib.h.
  4. B: s.age.
  5. A: stdio.h.

Quick Revision for Exams and Interviews

Read this before your test. The highlighted words are the answer.

Must-remember facts

sizeof(char)Always 1
Array indexes0 to n − 1
String sizeLength + 1 ('\0')
&& vs ||&& first
switch typeInteger only
union sizeLargest member
"r+" vs "w+"Keeps vs erases

Frequently asked questions

How do I prepare for C MCQ tests?
Revise exact rules (precedence, sizes, '\0', integer division) and practise timed sets of MCQs.
Is main a keyword in C?
No. main is a function name; keywords are words like int, return and while.
Does C support call by reference?
Not directly: C passes everything by value, but passing a pointer lets a function change the original.

Remember

  • Each MCQ is spot the difference: find the one detail.
  • Below 20/30? Revise that set's module.

Next Topic

Next lesson: C Cheat Sheet. Finish with a one-page cheat sheet of the whole C language for quick revision.