Placement Prep

Conceptual C MCQs for Placement Interviews

Five essential C programming MCQs on pointers, static variables, struct sizing, and token counting, with step-by-step traces for placement tests.

By FACE Prep Team 5 min read
c-programming placement-prep pointers technical-interview static-variables data-structures

Conceptual C programming questions test whether a candidate can trace undefined behavior, reason through memory layout, and apply the rules of the language precisely. Syntax recall alone does not clear that bar.

Why Conceptual Questions Appear in Every C Round

Placement tests at service and product companies use conceptual MCQs to differentiate between candidates who have used C and candidates who understand it. The questions below appear, often verbatim, in AMCAT technical sections, TCS iON Gateway (NQT), and campus recruitment rounds for Tier-2 and Tier-3 college students at Cognizant, Wipro, and Infosys. GATE CS draws on the same categories: pointer mechanics, static variable scope, struct and union sizing, and token analysis.

Five questions cover the patterns that recur most often. Each answer includes a step-by-step trace so the reasoning is reproducible on test day, not just memorised.

Pointer Validity and Memory Allocation

Question 1: Which Functions Have Pointer Problems?

Consider three versions of the same function:

/* P1 */
int *g(void) {
    int x = 10;
    return (&x);
}

/* P2 */
int *g(void) {
    int *px;
    *px = 10;
    return px;
}

/* P3 */
int *g(void) {
    int *px;
    px = (int *)malloc(sizeof(int));
    *px = 10;
    return px;
}

Which functions are likely to cause pointer problems?

  • (a) Only P3

  • (b) Only P1 and P3

  • (c) Only P1 and P2

  • (d) P1, P2, and P3

  • Answer: (c) — Only P1 and P2.

  • P1: x is a local variable allocated on the stack. When g returns, x goes out of scope and the stack frame is reclaimed. Returning &x gives the caller a dangling pointer. Any dereference of that address afterward is undefined behavior per the C language rules on pointer validity.

  • P2: px is declared but never assigned to a valid address. It holds whatever garbage value was in that stack slot. Writing *px = 10 stores the integer at an unknown memory location, which is undefined behavior. The program may crash immediately or silently corrupt other data.

  • P3: malloc(sizeof(int)) allocates memory from the heap. Heap memory persists beyond the function’s lifetime until explicitly freed with free(). Returning px gives the caller a valid, usable pointer. P3 is the only safe version.

Question 2: What Does struct node *s[10] Declare?

struct node {
    int i;
    float j;
};
struct node *s[10];
  • (a) An array where each element is a pointer to a struct node.

  • (b) A structure of two fields, each a pointer to an array of 10 elements.

  • (c) A structure of three fields: integer, float, and a 10-element array.

  • (d) An array where each element is a struct node directly.

  • Answer: (a).

  • s[10] declares an array of 10 elements.

  • The * before s makes each element a pointer to struct node, not a struct node itself.

  • The declaration stores addresses. If you want the structs themselves, the declaration would be struct node s[10] (no asterisk).

  • Reading declarations outward from the identifier: s is an array of 10 things; each thing is a pointer; each pointer points to a struct node.

Static Variables and Accumulated State

Question 3: What Is the Value of j After Execution?

int incr(int i) {
    static int count = 0;
    count = count + i;
    return (count);
}

int main() {
    int i, j;
    for (i = 0; i <= 4; i++)
        j = incr(i);
}
  • (a) 10

  • (b) 4

  • (c) 6

  • (d) 7

  • Answer: (a) — j ends at 10.

  • A static local variable is initialized once (at program start, not on each call) and retains its value between calls.

  • Iteration trace:

    • incr(0): count = 0 + 0 = 0
    • incr(1): count = 0 + 1 = 1
    • incr(2): count = 1 + 2 = 3
    • incr(3): count = 3 + 3 = 6
    • incr(4): count = 6 + 4 = 10
  • j receives the return value of the last call: 10.

  • The loop condition is i <= 4, not i < 4. The iteration runs five times (i = 0, 1, 2, 3, 4). Candidates who stop the trace at incr(3) and choose answer (c) — 6 — have misread the boundary condition.

Memory Layout: Struct Containing a Union

Question 4: Total Memory for a Struct with a Union

struct {
    short s[5];
    union {
        float y;
        long z;
    } u;
} t;

Assume: short = 2 bytes, float = 4 bytes, long = 8 bytes. What is the total memory for t, ignoring alignment?

  • (a) 22 bytes

  • (b) 14 bytes

  • (c) 18 bytes

  • (d) 10 bytes

  • Answer: (c) — 18 bytes.

  • Step-by-step calculation:

    • short s[5]: 5 × 2 = 10 bytes.
    • Union u: a union allocates space for its largest member only. float y = 4 bytes; long z = 8 bytes. Union size = 8 bytes. Both members occupy the same memory region — only one is valid at a time.
    • Total: 10 + 8 = 18 bytes, ignoring padding.
  • The cppreference reference on struct and union layout explains that union members overlap in memory from a common starting address.

  • The most common wrong answer is 22 (option a), which treats float and long as separate fields adding up to 12 bytes in the union. That reflects struct thinking, not union thinking.

Language Mechanics: Token Counting

Question 5: How Many Tokens Are in This Statement?

printf("i = %d, &i = %x", i, &i);
  • (a) 3

  • (b) 26

  • (c) 10

  • (d) 21

  • Answer: (c) — 10 tokens.

  • C defines six token categories: keywords, identifiers, constants, string literals, operators, and punctuators.

  • Token breakdown:

    • printf — identifier
    • ( — punctuator
    • "i = %d, &i = %x" — string literal (the entire string counts as one token, regardless of its internal content)
    • , — punctuator
    • i — identifier
    • , — punctuator
    • & — address-of operator
    • i — identifier
    • ) — punctuator
    • ; — punctuator
  • The wrong answer 26 counts each character inside the string literal separately. Tokenization operates on the source text before string contents are processed, so the entire double-quoted sequence is one unit.

  • The wrong answer 3 treats the whole statement as function-name, argument-list, and terminator.

How These Questions Appear in Placement Rounds

These five categories are not arbitrary. Pointer validity, static variable tracing, and struct sizing appear in AMCAT technical sections and the C aptitude portion of TCS NQT. Token counting appears in compiler-theory MCQs common in GATE CS and campus rounds at Tier-2 colleges across Tamil Nadu, Andhra Pradesh, and Maharashtra.

For the 31 programs that appear most often across technical placement rounds, FACE Prep’s C programming interview questions list traces each one with output. For broader conceptual coverage including undefined behavior, sizeof traps, and switch fall-through, the conceptual C question guide covers eight patterns with C11 standard citations.

The count in Q3 traces through 0, 1, 3, 6, and 10 across five calls. That step-by-step state-tracing habit transfers when reasoning about how an LLM maintains context across a conversation, since both require asking “what is the current state, and what does this input do to it?” at each step. TinkerLLM at ₹299 is a structured sandbox for applying that habit to hands-on LLM exercises, no prior AI background required.

Primary sources

Frequently asked questions

Which of P1, P2, and P3 causes pointer problems and why?

P1 returns the address of a local variable that goes out of scope when the function returns — the pointer is left dangling. P2 writes to an uninitialized pointer, which points to an unknown memory location, causing undefined behavior. P3 correctly uses malloc to allocate heap memory that persists after the function returns.

Why does the static counter reach 10 after the for loop?

A static local variable retains its value between function calls. The loop runs incr(0) through incr(4). Each call adds i to count: 0+0=0, 0+1=1, 1+2=3, 3+3=6, 6+4=10. The variable j receives the return value of the last call, which is 10.

How do you calculate the size of a struct that contains a union?

Calculate the array portion first: short s[5] = 5 times 2 = 10 bytes. Then take the union's size as the maximum of its members: max(float=4, long=8) = 8 bytes. Add both: 10 + 8 = 18 bytes, ignoring alignment padding. The most common mistake is adding float and long separately (4+8=12), which misunderstands that union members share memory.

What counts as a token in C?

C tokens fall into six categories: keywords, identifiers, constants, string literals, operators, and punctuators. In the printf statement, the entire string literal counts as a single token regardless of its length. The 10 tokens are: printf, open parenthesis, the string literal, comma, i, comma, ampersand, i, close parenthesis, semicolon.

What does the declaration struct node *s[10] mean in C?

It declares an array of 10 elements where each element is a pointer to a struct node. The array stores addresses of node structures, not the structures themselves. This is the standard way to hold references to a set of records in C, often used as the backbone of simple linked-list arrays or lookup tables.

Build AI projects

A self-paced playground for building with LLMs.

TinkerLLM is FACE Prep's sister property. A guided environment for shipping real LLM applications, the kind of project that earns a paragraph on your resume, not a line.

Try TinkerLLM (₹299 launch)
Free AI Roadmap PDF