Guides

C Programming Interview Questions and Answers

Common C programming interview questions with concise, correct answers — pointers, malloc/free, structs, storage classes, and undefined behavior.

Practical guideInformational10 min read
C Programming Interview Questions and Answers

Put this into action

Turn this guide into better conversations with Articuler

Use this guide as the research layer, then turn the next step into a live networking workflow: search by intent, prep for the conversation, and send outreach that is built for replies.

Try the Articuler workflow

If you are prepping for a systems, embedded, or firmware role, the C programming interview questions you'll face cluster around a handful of topics: pointers, manual memory management, how arrays and pointers differ, structs and unions, storage classes, the preprocessor, and the many ways undefined behavior can bite you. This guide groups the most common C interview questions by theme and gives a short, technically correct answer to each, with code snippets where they clarify the point. Use it to spot the gaps in your mental model before an interviewer does.

C is a compiled, statically typed, procedural language created by Dennis Ritchie at Bell Labs in the early 1970s, and it remains dominant in operating system kernels, device drivers, and embedded systems (Wikipedia)). Interviewers lean on it because it exposes memory directly — there is no garbage collector to hide your mistakes — so answering these C language interview questions well demonstrates that you understand what the machine is actually doing.

Table of contents

Pointers and memory addresses

Pointers are the topic interviewers probe first, because everything else in C builds on them.

What is a pointer? A pointer is a variable whose value is the memory address of another object. You dereference it with * to read or write the object it points at, and take an address with &. C gives you low-level access to memory through pointers (Wikipedia)).

What is a null pointer, and how is it different from an uninitialized pointer? A null pointer is guaranteed not to point at any object; you compare against it with p == NULL. An uninitialized pointer holds an indeterminate value — dereferencing either one is a bug, but the null case is at least detectable.

What is a void pointer? void * is a generic pointer that can hold the address of any object type. It has no associated type, so you cannot dereference it directly; you cast it back to a concrete type first. This is exactly why malloc returns void *.

What does pointer-to-pointer mean? A int **pp holds the address of an int *. It shows up when a function needs to modify the caller's pointer (for example, an allocator that sets an output pointer) or when working with arrays of strings.

int x = 42;
int *p = &x;      // p holds the address of x
int **pp = &p;    // pp holds the address of p
printf("%d\n", **pp);  // prints 42

Dynamic memory management: malloc, calloc, realloc, free

Manual memory management is the single richest source of C programming interview questions and answers, because it is where real programs break.

What does malloc do, and does it initialize memory? malloc(n) allocates n bytes on the heap and returns a void * to the block, or NULL on failure. The memory is uninitialized — it contains garbage, so you must not read it before writing (Wikipedia).

How is calloc different from malloc? calloc(count, size) allocates count * size bytes and zero-initializes every byte, whereas malloc leaves the memory uninitialized. Prefer calloc when you need a clean, zeroed block.

What does realloc do? realloc(ptr, newsize) resizes a previously allocated block. If it cannot grow the block in place, it allocates a new region, copies the existing contents, frees the old block, and returns a possibly different address. Always assign the result to a temporary — if you write p = realloc(p, n) and it returns NULL, you leak the original block.

FunctionArgumentsInitializes memory?Typical use
malloctotal bytesNo (garbage)Fast allocation you'll fully overwrite
calloccount, element sizeYes (all zero)Arrays and structs needing a clean slate
reallocpointer, new sizePreserves old, new bytes garbageGrowing or shrinking an existing block
freepointerN/AReturn a block to the heap exactly once

What is a memory leak? Allocated heap memory that is never freed and whose last pointer is lost. The program can no longer reach or release it, so usage grows until it exhausts memory.

int *buf = malloc(n * sizeof *buf);
if (buf == NULL) { /* handle allocation failure */ return -1; }
/* ...use buf... */
free(buf);
buf = NULL;   // avoid a dangling pointer

Always check the return of malloc/calloc before dereferencing — a NULL you fail to check turns into a segmentation fault. For the algorithmic side of the loop, our coding interview questions guide covers the data-structure problems that pair with these memory questions.

Arrays vs pointers

"Are arrays and pointers the same thing?" is a classic trap. The answer is no — they behave alike in many expressions but are genuinely different.

An array name in most expressions *decays* to a pointer to its first element (Wikipedia)). That is why you can pass an array to a function that takes a pointer. But the array itself is a distinct object: sizeof(arr) gives the total size of the array in bytes, while sizeof(ptr) gives the size of a pointer (typically 8 bytes on a 64-bit machine).

int arr[10];
int *ptr = arr;          // decay: ptr points to arr[0]
sizeof(arr);             // 40  (10 * sizeof(int))
sizeof(ptr);             // 8   (size of a pointer)

Other differences worth stating: an array name is not an lvalue you can reassign (arr = something; is illegal), whereas a pointer variable can be reassigned freely. And &arr has type "pointer to array of 10 int", not "pointer to pointer". Interviewers love this because getting it right shows you understand the type system rather than pattern-matching syntax.

Structs, unions, and storage classes

What is the difference between a struct and a union? A struct stores all its members in separate, contiguous storage, so its size is at least the sum of its members (plus padding for alignment). A union overlays all members in the *same* storage, so its size is that of its largest member, and only one member holds a valid value at a time. Unions are used for memory-tight code and tagged variants.

struct Point { int x; int y; };   // holds x AND y (>= 8 bytes)
union Value  { int i; float f; }; // holds i OR f (4 bytes)

What is structure padding? The compiler inserts unused bytes between members so each member sits on its natural alignment boundary. This is why sizeof a struct can exceed the sum of member sizes.

What are the storage classes in C? Storage-class specifiers set two independent properties — storage duration (lifetime) and linkage (visibility across translation units), per cppreference:

SpecifierStorage duration / lifetimeLinkage
autoAutomatic — lives for the enclosing block (the default for locals)None
registerAutomatic, plus a hint to keep the value in a CPU registerNone
static (file scope)Static — the whole program run, initialized once before mainInternal (this file only)
static (block scope)Static — persists between calls, but scoped to the functionNone
externStatic — refers to an object defined in another translation unitExternal (whole program)

A common follow-up: a block-scope static local keeps its value across function calls but is invisible outside the function — handy for counters and lazy initialization.

What does the preprocessor do? It runs before compilation, handling #include (textual file insertion), #define (macros and constants), and conditional compilation (#ifdef, #ifndef). A frequent question is why macros need parentheses: #define SQ(x) ((x)*(x)) guards against precedence surprises when the macro is expanded into a larger expression. If your interview spans multiple languages, compare notes with our C# interview questions, where a managed runtime changes these answers entirely.

Undefined behavior and common gotchas

Undefined behavior (UB) is C's most dangerous feature and a favorite interview topic. When a program triggers UB, the standard imposes no requirements at all — it may crash, produce wrong results, or appear to work by luck.

What is a dangling pointer? A pointer that still holds the address of memory that has been freed (or of a local that has gone out of scope). Using the value of a pointer after the object it points to is deallocated by free or realloc is undefined behavior (SEI CERT MEM30-C). Freed memory often isn't reclaimed immediately, so a dangling access can *appear* to work — which makes the bug maddening to reproduce.

What is a double free? Calling free twice on the same pointer. It corrupts the allocator's bookkeeping and is undefined behavior. The standard defense is to set the pointer to NULL right after freeing, because free(NULL) is a guaranteed no-op.

Other common gotchas interviewers ask about:

  • Buffer overflow / out-of-bounds access: reading or writing past the end of an array is UB.
  • Signed integer overflow: overflowing a signed integer is UB (unsigned overflow, by contrast, wraps and is well-defined).
  • Returning a pointer to a local: the local's storage ends when the function returns, so the returned pointer immediately dangles.
  • Reading uninitialized memory: an uninitialized variable or a fresh malloc block holds indeterminate values.

The broad lesson to convey: C trusts you to uphold the rules the standard cannot check, and much of good C is defensive discipline — checking allocation results, nulling freed pointers, and never assuming garbage memory is zero. The Wikipedia entry on undefined behavior is a good primer if you want the formal framing. For behavioral and role-specific rounds that follow the technical screen, see our engineering interview questions guide.

Next step

Use Articuler to act on what you just read

Start with one concrete goal: investor intros, sales prospects, event meetings, hiring-manager outreach, or expert conversations. Articuler turns that goal into people, prep, and messages.

Start networking with intent

FAQ

What are the most common C programming interview questions?

The most frequent C interview questions cover pointers (including null, void, and double pointers), the difference between malloc and calloc, how arrays decay to pointers, struct versus union, the storage classes (auto, register, static, extern), and undefined behavior such as dangling pointers and double frees. Being able to give a crisp two-sentence answer to each — with a small code example — is what interviewers look for.

How do I prepare for a C language interview for an embedded role?

Beyond the core language, embedded interviews add bit manipulation, volatile and memory-mapped I/O, fixed-width integer types from <stdint.h>, endianness, and constraints of running without a heap. Practice explaining *why* an answer is correct, not just reciting it, and be ready to reason about memory layout and alignment on the target hardware.

Is knowing pointers enough to pass a C interview?

Pointers are necessary but not sufficient. Strong candidates also handle manual memory management cleanly (allocate, use, free exactly once), articulate what undefined behavior means, and understand how the compiler and preprocessor shape the final program. Interviewers use these C language interview questions to separate people who memorized syntax from those who understand the machine.

What's the difference between C and C++ interview questions?

C interview questions focus on manual memory management, pointers, and a small procedural feature set. C++ adds classes, RAII, templates, and the standard library — so C++ questions often assume the memory pitfalls are managed for you by destructors and smart pointers, whereas C interviews test whether you can manage them by hand correctly.

Nailing the technical answers gets you through the screen. What often decides the offer between two strong C candidates is rapport — and that starts with knowing who's actually interviewing you. Articuler searches across 980M+ profiles to find the real hiring manager or engineer behind a role and builds a Playbook on their background and what they care about, so you walk into the conversation prepared for *that* team, not a generic panel. It's the difference between answering questions and having a conversation.

Keep reading

More from Guides

Resources