C Language MCQs Explained: A Worked Output Trace and Exam Traps

Learn to classify C questions, resolve types before values, follow side effects safely, and trace a complete pointer-and-array program to the output 11 3 18.

KnowledgeGate Team

Exam prep & CS education

Updated 29 Aug 20266 min read

A six-line C MCQ can still mix types, values, side effects, object identity and defined behaviour. Classify the question first, resolve types before values, and record each state change in order. One missed conversion or unsequenced side effect can turn a neat arithmetic answer into a wrong one.

C language MCQs: classify the question before calculating

Name the class first: declaration or diagnostic, type and conversion, output trace, or definedness. These ask, respectively, whether the source satisfies C's rules, what type an expression has, how ordered state changes unfold, or whether C promises a result.

Then use six scratch passes:

  1. List every object and its initial value.

  2. Mark the type of each expression.

  3. Add parentheses according to precedence.

  4. Apply the required conversions.

  5. Execute only sequenced side effects.

  6. Check array bounds, division, overflow and other definedness conditions.

Precedence groups an expression, but does not specify every operand's evaluation order. Strengthen the underlying syntax, type and data-structure foundations through the Coding & DSA courses.

C expressions and conversions: find the type before the value

For int a = 17, b = 5;, integer division makes a / b equal 3, while a % b is 2. A floating operand changes the calculation.

Expression

Effective operand types

Result

a / b

int, int

3

a % b

int, int

2

a / 5.0

double, double after conversion

3.4

double q = a / b

int, int on the right side

q = 3.0

double r = (double) a / b

double, double after conversion

r = 3.4

Assignment to double cannot restore a fraction after integer division produces 3. Label the right-side types first.

Starting with int x = 5;, int y = x++; gives y = 5, then x = 6. Next, int z = ++x; makes both x and z equal 7. Do not apply that reasoning to x++ + ++x; it is a definedness question, not arithmetic.

C control flow in the six-pass method: short-circuiting and loop boundaries

In int d = 0; if (d != 0 && 20 / d > 2) { ... }, the false left operand of && prevents evaluation of the right operand. The body is skipped without division by zero. Bitwise & evaluates both operands and cannot replace logical && here.

For int sum = 0; int i; for (i = 1; i <= 4; ++i) sum += i;, write the condition beside each pass:

i

Condition

New sum

1

1 <= 4, true

1

2

2 <= 4, true

3

3

3 <= 4, true

6

4

4 <= 4, true

10

5

5 <= 4, false

unchanged

The final state is sum = 10, i = 5. This habit exposes changes involving <, <=, increments and starting indices.

C arrays, pointers and function calls: track objects and aliases

For int data[4] = {3, 6, 9, 12};, valid indices are 0 through 3. In an applicable expression, data[1] and *(data + 1) select the object holding 6. The array can yield a pointer to its first element, but is not itself a modifiable pointer variable.

C parameters receive values. An int n receives a copied integer; an int *p receives a copied address. Changing n affects only the callee's object, while writing through *p can change the caller's object at that address. "Pass an address" is still value passing.

Use C Pointer Basics: 12 Solved MCQs on Dereferencing for dedicated pointer practice. Then extend the copied-value and copied-address distinction with Call by Value & Reference in C: 12 Solved MCQs.

C worked example: trace every value from call to output

Trace the following program from its function call to its output:

#include <stdio.h>

int adjust(int n, int *total) {
    n += 2;
    *total += n;
    return n * 2;
}

int main(void) {
    int data[4] = {3, 6, 9, 12};
    int total = 4;
    int result = adjust(data[1] - 1, &total);
    int index = total % 4;

    if (result > 10 && data[index] == 12) {
        result += data[index] / 3;
    }

    printf("%d %d %d\n", total, index, result);
    return 0;
}

First, data[1] - 1 = 6 - 1 = 5. The call creates local n = 5 and a local pointer to the caller's total. Then n += 2 makes n = 7, and *total += n changes the caller's total from 4 to 11.

The function returns n * 2 = 7 * 2 = 14, so result = 14. Next, index = total % 4 = 11 % 4 = 3. Both 14 > 10 and data[3] == 12 are true. Therefore data[3] / 3 = 12 / 3 = 4, and result becomes 14 + 4 = 18. The exact output is:

11 3 18

The pointer parameter is local to adjust, but dereferencing it reaches total in main. The call finishes before the index initializer, so % 4 uses 11, not 4.

For a self-check, change only data[1] from 6 to 7. The argument becomes 7 - 1 = 6, local n becomes 8, caller total becomes 4 + 8 = 12, and the return value is 8 * 2 = 16. Now index = 12 % 4 = 0. Since data[0] == 12 is false, the body is skipped. The exact output is 12 0 16.

Trace of the adjust() call showing total change 4 to 11, index 11 % 4 = 3, result 18, and the final output 11 3 18.

C undefined behaviour and diagnostic traps: do not invent an output

Separate three outcomes. A source issue such as a missing semicolon requires a diagnostic. Undefined behaviour means C supplies no answer. An implementation choice, such as whether plain char is signed, needs implementation details or an explicit assumption.

These examples have undefined behaviour:

  • int i = 1; int z = i++ + ++i; modifies i without the required sequencing.

  • int a[3] = {1, 2, 3}; printf("%d", a[3]); reads beyond the array.

  • Dividing by an integer variable whose value is zero is undefined.

  • Overflowing a signed int is undefined.

A compiler's accidental output is not the C answer. C guarantees sizeof(char) == 1, but not sizeof(int) == 4 or a particular pointer size. Use a supplied machine model; otherwise keep the answer symbolic or recognise the missing information.

How exams test C language MCQs: representative transformations

A representative C question may ask for defined output, a valid declaration or call, a value versus an address, a loop boundary, a conversion, or code with no portable output. Classify the form before calculating so that a definedness problem is never forced into a numeric answer.

Run four rapid checks:

  • int x = 7; x / 2 is integer division, so the result is 3.

  • For int a[3] = {2, 4, 6};, *(a + 1) selects 4.

  • With int p = 0, p && 10 / p is false without evaluating the division.

  • int i = 1; i++ + ++i has undefined behaviour, not a numeric answer.

An MCQ's answer choices are useful only after the semantic result is fixed. Compute the type, state changes and definedness first, then eliminate options that contradict that trace.

C language MCQs: the short version and next step

Use the method in order: classify, list objects, determine types, apply precedence, conversions and sequenced side effects, then reject undefined or assumption-dependent shortcuts. The key values are total = 11, index = 3, result = 18.

Spend 15 minutes: five rebuilding the trace, five solving the data[1] = 7 variant to get 12 0 16, and five classifying the rapid checks. For the foundation, continue with the C Language Course. To organise C inside wider CS study, use GATE Guidance by Sanchit Sir.