C Programming Interview Questions for Freshers: The 40 Asked in Vivas and Placement Drives

Prepare 40 common C questions with short interview-safe answers, then learn how to dry-run pointer mutation on a whiteboard.

KnowledgeGate Team

Exam prep & CS education

Updated 22 Jul 20266 min read

Freshers memorise definitions, then freeze when an interviewer says, "Dry-run this" or "What does this print?" C sits close to memory, so a strong answer explains what exists, where it lives, and when it changes.

The same 40 keep coming back in two rooms. A college viva examiner points at your own lab program and asks what one line does; a placement-drive panel hands you an unfamiliar snippet and times the reply. Neither is satisfied by a definition.

How C interviews are scored, not just recalled

Interviewers use pointers, memory, and undefined behaviour to test runtime reasoning. They may accept a definition, then change one line and ask for the effect. A viva examiner usually stays inside code you wrote, so the follow-ups land on your own array indexing and your own malloc calls. A drive panel works from a fixed snippet list and marks the predicted output, so a clean rule stated quickly beats a long derivation.

Identify each object's type and lifetime, draw the cells, apply the statement, then state the output. If C does not define an outcome, say undefined behaviour instead of guessing. C is one subject in a longer technical round; Technical interview prep: OS, DBMS, CN and OOP questions freshers face covers the rest of that list.

Pointers and memory: the core 10

  1. What does a pointer hold? An address of an object or function of a compatible type, or a null pointer value that points to no object.

  2. What is a pointer to pointer? A pointer whose target is another pointer, such as int **pp; *pp is an int * and **pp is an int.

  3. What does pointer arithmetic do? Adding one to int *p advances by one int, provided the result stays within the same array object or one past it.

  4. What is array-to-pointer decay? In most expressions, an array name converts to a pointer to its first element; important exceptions include operands of sizeof and unary &.

  5. How do arr and &arr differ? They commonly have the same numeric address, but arr decays to a pointer to the first element while &arr points to the entire array and steps by the whole array size.

  6. Dangling pointer vs wild pointer? A dangling pointer refers to an object whose lifetime has ended; a wild pointer is uninitialised and holds an indeterminate value.

  7. What is a null pointer? A pointer value guaranteed not to compare equal to the address of any object or function; dereferencing it is undefined behaviour.

  8. What is void *? A generic object-pointer type that can hold an object address; convert it to an appropriate typed pointer before dereferencing.

  9. What is a function pointer? A pointer that stores a function address and can call a function with the matching signature, often used for callbacks.

  10. const int *p vs int * const p? The first prevents changing the pointed value through p; the second prevents making p point somewhere else.

Pointers in C for GATE adds memory diagrams.

Worked example: pass-by-pointer mutation

This is the smallest complete program that separates a value from an address:

#include <stdio.h>

void inc(int *p) {
    (*p)++;
}

int main() {
    int a = 5;
    inc(&a);
    printf("%d\n", a);
    return 0;
}

Trace it in memory:

  1. a lives in main's stack frame, say at address 0x7ffe1004, holding 5.

  2. inc(&a) passes that address; inside inc, p holds 0x7ffe1004.

  3. (*p)++ reads the cell reached through p and writes 6 to 0x7ffe1004.

  4. Back in main, a is now 6; the output is 6.

If inc took int p by value, a would stay 5 because only a copy would change. Here, the value copied into p is a's address.

Two stack frames: main's a holds 5 then 6, while inc's pointer p holds a's address, so the program prints 6.

Storage, memory layout and lifetime: the core 10

  1. Stack vs heap? Automatic local objects usually have block lifetime and are commonly stack-backed; dynamically allocated objects remain until free and come from managed dynamic storage.

  2. What does malloc do? It allocates an uninitialised byte block and returns void *, or a null pointer on failure.

  3. How do calloc and realloc differ? calloc allocates an array and zero-initialises its bytes; realloc changes an existing allocation and may move it.

  4. Why call free? It ends the lifetime of allocated storage; using that pointer to access the freed object afterwards is invalid.

  5. What is a memory leak? Allocated memory becomes unreachable without being freed, so the program can no longer release or reuse it deliberately.

  6. What is a static local's lifetime? It exists for the entire program and retains its value between calls, although its name remains block-scoped.

  7. static vs extern at file scope? static gives internal linkage; extern declares a name whose definition can have external linkage elsewhere.

  8. What causes a segmentation fault? Common causes include invalid dereferences, writing read-only storage, out-of-bounds access, and stack exhaustion; C does not guarantee that particular signal.

  9. sizeof array vs pointer? In the array's defining scope, sizeof arr is the whole array size; after decay or in a function parameter, sizeof p is only the pointer size.

  10. Can you modify a string literal or read an uninitialised automatic variable? No safe result is defined: modifying a literal is undefined behaviour, and reading an indeterminate automatic value can also be undefined behaviour.

Language semantics that trip people: the core 10

  1. i++ vs ++i? Both increment i; postfix yields the old value while prefix yields the new value.

  2. What does i = i++ do? It has undefined behaviour in C because modifications of i are unsequenced; never offer a numeric answer.

  3. How does integer division work? With integer operands, the fractional part is discarded towards zero, so 7 / 2 is 3.

  4. What happens in character arithmetic? A char is promoted to an integer type before arithmetic, so 'A' + 1 can be printed as 'B' with %c on ordinary C implementations.

  5. What is implicit type promotion? Narrow integer types commonly promote to int or unsigned int, and mixed arithmetic then follows the usual conversions.

  6. #define vs const? A macro is token substitution with no C type; a const object has a type, scope, and storage semantics.

  7. What is the macro argument trap? Write #define SQR(x) ((x) * (x)); missing parentheses breaks expressions, and passing i++ still causes multiple evaluation.

  8. Struct vs union size? A struct provides storage for every member plus padding; a union provides shared storage large and aligned enough for its largest-demanding member.

  9. Name two useful bit tricks. XOR can swap two distinct integer objects without a temporary, and positive n is a power of two when (n & (n - 1)) == 0.

  10. Switch fallthrough, break, and continue? A case falls through without break; break exits the switch or loop, while continue starts the next loop iteration.

Output and dry-run rapid fire: the remaining 10

#

Snippet

Interview-safe answer

1

int a=5; printf("%d", a++);

Prints 5; afterwards a is 6.

2

int a=5; printf("%d", ++a);

Increments first and prints 6.

3

printf("%d", 7/2);

Prints 3 because both operands are integers.

4

char c='A'; printf("%c", c+2);

Prints C on the ASCII-based character set you can assume in an interview.

5

int a[4]; printf("%zu", sizeof a/sizeof a[0]);

Prints 4 in the array's scope.

6

int s=0; for(int i=0;i<5;i++) s+=i;

Ends with s = 0+1+2+3+4 = 10.

7

switch(1){case 1:printf("A"); case 2:printf("B");}

Prints AB because case 1 falls through.

8

static int x; printf("%d", ++x); on two calls

Prints 1 then 2; static storage starts at zero and persists.

9

int i=1; printf("%d", i++ + ++i);

Undefined behaviour due to unsequenced modifications of i.

10

int *p=NULL; printf("%d", *p);

Undefined behaviour; there is no valid output to predict.

How to answer under pressure: the short version

Reason about memory aloud, distinguish values from addresses, and name undefined behaviour. When C defines no outcome, saying so is the answer, and an interviewer hears that as the stronger one.

Next, work the concept and MCQ sets in the C Programming course. Over 1,200 C Programming practice questions are available there for follow-up work. For the rest of the drive, combine that work with the Mera Placement Hoga Anushasan bundle or browse the Placement Preparation catalogue.