🔴 Advanced  ·  Lesson 48

C Interview Questions

How C interviews work

C interviews usually mix three things: concept questions ("what is the difference between..."), pointer and memory puzzles, and small coding problems to write on paper or a screen. This lesson collects the questions that come up again and again, with short, clear answers you can actually remember.

For deeper coverage of any topic, follow the linked lessons — this page is a revision hub.

Concept questions and answers

QuestionShort answer
Array vs pointer?Array is a fixed block; pointer holds a reassignable address. See arrays and pointers.
Structure vs union?Struct gives each member its own memory; union shares one. See structure vs union.
What is a storage class?It sets a variable's lifetime and visibility (auto, static, extern, register). See storage classes.
Call by value vs reference?Value copies the data; reference passes an address so changes stick. See call by value/reference.

Pointer and memory questions

  • What is a NULL pointer? A pointer that points to nothing, written as NULL. Always check before dereferencing.
  • What is a dangling pointer? A pointer to memory that was already freed. Set pointers to NULL after free.
  • malloc vs calloc? malloc leaves memory uninitialised; calloc zeroes it. See dynamic memory.
  • What is a memory leak? Allocated memory never freed, so usage grows until the program ends.
💡 Interviewers love pointers

Be ready to draw boxes and arrows. Explaining a pointer with a quick memory diagram impresses more than reciting a definition.

Common coding problems

These small programs come up constantly. Make sure you can write each from memory:

Example: palindrome check
int isPalindrome(char s[]) {
    int i = 0, j = 0;
    while (s[j] != '\0') j++;      // find length
    j--;
    while (i < j)
        if (s[i++] != s[j--]) return 0;  // mismatch
    return 1;                       // all matched
}

Preparation tips

  • Practise writing code by hand — many interviews are on paper or a whiteboard.
  • Explain your thinking out loud as you code; interviewers score reasoning.
  • Know the why, not just the definition — be ready for "why does that happen?"
  • Revise pointers, memory and strings most; they appear in almost every C interview.
🏋️ Practice

Pick five questions above and answer each out loud in your own words, then write the coding ones from a blank editor without looking. That mirrors real interview pressure.

Summary

  • C interviews mix concept questions, pointer/memory puzzles and coding problems.
  • Master array vs pointer, struct vs union, storage classes and call by value/reference.
  • Be fluent with NULL and dangling pointers, malloc vs calloc, and memory leaks.
  • Practise classic programs (reverse, palindrome, linked list) by hand.
  • Explain your reasoning aloud and focus revision on pointers, memory and strings.

Frequently Asked Questions

What is the difference between an array and a pointer in C?
An array is a fixed block of contiguous elements, and its name refers to that whole block; a pointer is a variable that holds an address and can be reassigned. An array name gives the address of its first element but cannot be changed, while a pointer can point to different places over time.
What is the difference between malloc and calloc?
Both allocate memory on the heap. malloc takes one size argument and leaves the memory uninitialised, while calloc takes a count and a size, allocates that many elements, and sets every byte to zero. Use calloc when you need the memory cleared to start.
What is a dangling pointer?
A dangling pointer is a pointer that still holds the address of memory that has already been freed or gone out of scope. Using it leads to undefined behaviour. You avoid it by setting a pointer to NULL right after freeing what it pointed to.
What is the difference between structure and union in C?
A structure gives each member its own memory, so all members can hold values at once and its size is the total of all members. A union shares one block of memory among all members, so only one is valid at a time and its size is that of the largest member.
What is the use of the static keyword in C?
Inside a function, static makes a local variable keep its value between calls instead of being recreated each time. At file level, static limits a variable or function to that file, hiding it from other files. Both uses are common interview topics.
← Back to C Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।