C Programming Interview Questions

C Interview Questions and Answers

June 20th, 2026
4541
15:00 Minutes

C programming interviews are designed to test not only a candidate’s knowledge of syntax but also their understanding of programming concepts such as memory management, pointers, data structures and problem solving ability.

From my experience of both taking interviews as a candidate and conducting interviews as an interviewer, I have seen that strong candidates are those who can clearly explain concepts, write clean code and think logically through real world scenarios. C remains a foundational language in computer science, so interview questions often focus on fundamentals like pointers, memory allocation, structures and program behavior.

In this blog, I have compiled the most commonly asked C programming interview questions for freshers, intermediate developers and experienced professionals with practical scenario based questions.

Test Your C Programms with Online C Compiler

C Programming Interview Questions for Freshers

The following are some questions that will test your basic knowledge on C Programming:

1. What is the C Language?

C is a general purpose programming language used to write computer programs. Developed by Dennis Ritchie in the early 1970s at Bell Labs. It is widely used as it is fast, powerful and efficient. Many operating systems and software programs are written in C.

2. Why is C called a mid-level programming language?

C is called a mid level programming language because it has features of both low level and high level languages. It can work closely with hardware like low level languages and is also easy to write and understand like high level languages.

3. What is a token?

The individual elements of a program are known as Tokens. The following 6 types of tokens are available in C:

  • Constants
  • Special Characters

For example:

int a = 10;

In this, the tokens are: int, a, =, 10, ;

4. What is the difference between a declaration and initialization of a variable in C?

In C programming, variables store data values. A variable must first be declared to specify its name and data type. Initialization assigns an initial value to the variable when it is created.

Parameters Declaration Initialization
Definition Declaration means specifying the name and data type of a variable. Initialization means assigning an initial value to a variable when it is created.
Purpose It tells the compiler to reserve memory for the variable. It gives the variable a starting value to work with in the program.
Value Assignment In declaration, the variable does not necessarily have a value. In initialization, the variable is given a value immediately.
Syntax Example int a; int a = 10;
Usage Used when you only want to declare the variable first and assign a value later. Used when you want the variable to start with a specific value at the time of declaration.

5. Why doesn’t C support function overloading

C does not support function overloading because it identifies functions only by their names, not by their parameter lists. This means that in C, every function name must be unique within a scope.

6. What is a built-in function in C?

A built-in function is a predefined function already available in C libraries. These functions help perform common tasks so programmers do not need to write them from scratch.

7. What is a Preprocessor?

c-preprocessor

A preprocessor is a software program that processes a source file before sending it to be compiled. Inclusion of header files, macro expansions, conditional compilation and line control are all possible with the preprocessor.

8. What are keywords in C?

Keywords are reserved words in C that have a special meaning and cannot be used as variable names.

For example:

  • int
  • float
  • return
  • if
  • while
  • for

The original C language defined 32 keywords.

9. What are storage classes in C?

Storage classes define the scope, lifetime and visibility of variables in a program.

10. What is recursion in C?

Recursion is a process where a function calls itself to solve a problem. It is usually used for problems that can be broken into smaller parts.

For example:

#include 

int factorial(int n){
    if(n==0)
        return 1;
    else
        return n * factorial(n-1);
}

int main(){
    int num;

    printf("Enter a number: ");
    scanf("%d", &num);

    printf("Factorial = %d", factorial(num));

    return 0;
}

recursion in c

Code Explanation:

  • main() is the starting point of the program.
  • User enters a number.
  • factorial(num) calls the recursive function

Read Also: Java Tutorial for Beginners

Intermediate C Programming Interview Questions

Following intermediate questions helps a recruiter to check if the candidates are ready to work independently and handle moderately complex tasks:

1. What is a dangling pointer in C?

Dangling pointer is a pointer that points to a memory location that has already been freed or deleted. Accessing this pointer can lead to undefined behavior such as crashes or unexpected results.

Example:

#include 
#include 

int main() {
    int *ptr = (int*)malloc(sizeof(int));
    *ptr = 10;

    free(ptr);   // memory freed
    // ptr is now a dangling pointer

    printf("%d", *ptr); // undefined behavior
    return 0;
}

dangling pointer in c

2. Write a program to reverse a string using pointers.

In C programming, pointers are variables that store the memory address of another variable. Using pointers, we can directly manipulate data in memory.

Reversing a string using pointers means we swap characters from the beginning and the end of the string using pointer variables instead of array indexing. This approach demonstrates how pointers move through memory and modify values efficiently.

Program:

#include 

int main() {
    char str[] = "Hello";
    char *start = str;
    char *end = str;
    char temp;

    while(*end != '\0')
        end++;
    end--;

    while(start < end) {
        temp = *start;
        *start = *end;
        *end = temp;

        start++;
        end--;
    }

    printf("Reversed string: %s", str);
    return 0;
}

reversing a string using pointers in c

3. What is pointer arithmetic?

Pointer arithmetic refers to operations performed on pointers such as incrementing, decrementing, adding, or subtracting integers.

When a pointer is incremented, it moves to the next memory location of its data type size.

Example:

#include 

int main() {
    int arr[] = {10,20,30};
    int *ptr = arr;

    printf("Value pointed by ptr: %d\n", *ptr);

    ptr++;   // move pointer to next element

    printf("Value after ptr++: %d\n", *ptr);

    return 0;
}

pointer arithmetic

4. Write a program to swap two numbers using pointers.

Swapping two numbers using pointers in C demonstrates how pointers can access and modify variables through their memory addresses. Instead of returning values, the function directly changes the original variables by passing their addresses. This method is efficient and commonly used to understand pointer concepts and parameter passing in C programming.

Program:

#include 

void swap(int *a, int *b) {
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

int main() {
    int x = 5, y = 10;

    swap(&x, &y);

    printf("After swap: x=%d y=%d", x, y);
    return 0;
}

swapping two numbers using pointers in c

5. What is a function pointer in C?

A function pointer in C is a pointer that stores the address of a function instead of a normal variable. It allows you to call a function indirectly using the pointer. Function pointers are useful when passing functions as arguments to other functions or implementing callbacks. They make programs more flexible and reusable. For example, a pointer can store the address of a function and later execute it using that pointer, just like calling the function normally.

6. What is structure padding?

Structure padding is the extra memory added by the compiler inside a structure to align data in memory properly. It helps the CPU access data faster and more efficiently. Because different data types require different memory alignment, the compiler may insert unused bytes between structure members. This increases the overall size of the structure but improves performance. For example, if a char and an int are in a structure, padding may be added between them.

7. What is a static variable inside a function?

A static variable inside a function is a variable that keeps its value between function calls. Normally, local variables are created and destroyed every time the function runs. But a static variable is created only once and retains its previous value when the function is called again. It is only accessible inside that function but remembers its last stored value. Static variables are often used when a function needs to track how many times it has been called.

8. Write a program to check whether a number is a palindrome.

Palindrome number is a number that reads the same forward and backward, like 121 or 1331.

Program:

#include 
int main() {
    int n, rev = 0, rem, temp;
    printf("Enter a number: ");
    scanf("%d", &n);
    temp = n;

    while(n != 0) {
        rem = n % 10;
        rev = rev * 10 + rem;
        n = n / 10;
    }

    if(temp == rev)
        printf("Palindrome number");
    else
        printf("Not a palindrome");

    return 0;
}

palindrome number in c

9. What happens if free() is not used after malloc()?

If free() is not used after malloc(), the memory allocated dynamically will not be released back to the system. This causes a memory leak, which means the program keeps using memory even when it no longer needs it. Over time, this can reduce available memory and slow down the system, especially in large or long-running programs. Therefore, it is important to always free dynamically allocated memory when it is no longer required.

10. What is pointer to pointer?

A pointer to pointer is a pointer that stores the address of another pointer. In other words, it points to a pointer variable instead of a normal variable. It is declared using two asterisks (**). Pointer to pointer is useful when you want to modify a pointer inside a function or work with dynamic memory structures. For example, if p is a pointer to an integer, then pp can store the address of p.

Read Also: Java Interview Questions and Answers

C Programming Interview Questions for Experienced Professionals

Following question are for those candidates who have 5+ years of work experience:

1. Explain Memory Layout of a C Program.

The memory layout of a C program shows how memory is divided when a program runs. It usually contains text segment, data segment, BSS segment, heap and stack. The text segment stores compiled code. The data segment stores initialized global and static variables, while BSS stores uninitialized ones. The heap is used for dynamic memory allocation using malloc() and free(). The stack stores function calls, parameters and local variables. This layout helps manage memory efficiently during program execution.

2. What is the difference between shallow copy and deep copy?

A shallow copy copies only the reference or address of the original data, not the actual content. It means both variables point to the same memory location. If one changes the data, the other is affected. A deep copy, on the other hand, copies the actual data into a new memory location. Each variable has its own separate copy of the data. In C, shallow copy can happen when copying structures with pointers, while deep copy requires manually allocating memory and copying the contents.

3. What is undefined behavior in C?

Undefined behavior in C occurs when a program performs an operation that the C standard does not define. This means the compiler may produce unexpected results, crashes, or different outputs on different systems. Examples include accessing an array out of bounds, using uninitialized variables, dividing by zero, or modifying a variable multiple times in one expression. Since the behavior is not defined, the compiler does not guarantee how the program will behave.

4. What is a Segmentation Fault?

A segmentation fault is a runtime error that occurs when a program tries to access memory that it is not allowed to access. This usually happens due to invalid pointers, accessing memory outside array bounds, dereferencing a null pointer, or accessing freed memory. The operating system stops the program to prevent memory corruption. Segmentation faults are common in C because the language allows direct memory access using pointers.

5. What is const correctness in C?

Const correctness means using the const keyword properly to ensure that certain variables or data cannot be modified. It helps make programs safer and easier to understand. For example, declaring a variable as const int x means its value cannot be changed after initialization. It is also used with pointers to prevent modification of data through them. Using const correctly helps avoid accidental changes and improves code reliability.

6. What is the difference between stack and heap?

Stack and heap are two areas of memory used in C programs to store data. The stack stores local variables and function calls automatically, while the heap is used for dynamic memory allocation managed manually by the programmer.

Parameters Stack Heap
Memory Allocation Memory is allocated automatically by the compiler when a function is called. Memory is allocated manually by the programmer using functions like malloc(), calloc(), or realloc().
Memory Deallocation Memory is automatically freed when the function finishes execution. Memory must be freed manually using free(). If not freed, it can cause memory leaks.
Speed Stack allocation and deallocation are faster because memory management is simple. Heap allocation is slower because it involves complex memory management.
Size Limit Stack memory is limited and smaller in size. Heap memory is larger and can store large amounts of data.
Usage Used for storing local variables, function parameters and return addresses. Used for dynamic memory allocation when the size of data is not known at compile time.

7. What are reentrant functions?

A reentrant function is a function that can be safely used by multiple threads or interrupts at the same time without causing problems. It does not rely on shared or global data and only uses local variables or parameters. Because of this, each call to the function works independently. Reentrant functions are important in multitasking systems and embedded programming because they avoid data corruption when the function is interrupted or called simultaneously.

8. What is the difference between char *p and char p[]?

The difference between char *p and char p[] is important in C programming because both deal with strings but work differently in memory, pointer behavior and how they store and modify character data.

Parameters char *p (Pointer to char) char p[] (Character Array)
Definition It is a pointer variable that stores the address of a character or string. It is an array that stores characters directly in memory.
Memory Allocation Memory for the string is usually stored in a read-only memory location (string literal). Memory is allocated in the array itself, usually on the stack.
Modifying the String The string usually cannot be modified because it may point to read-only memory. The characters in the array can be modified.
Pointer Behavior The pointer can be changed to point to another string. The array name cannot be reassigned to another address.

9. What is the use of the volatile keyword in C?

The volatile keyword tells the compiler that the value of a variable may change at any time without the program modifying it directly. Because of this, the compiler should not apply certain optimizations that assume the value stays constant. It is commonly used in embedded systems, hardware registers, interrupt service routines and shared variables in multithreading environments where values can change unexpectedly.

10. How does static behave in different contexts?

The static keyword behaves differently depending on where it is used. Inside a function, a static variable keeps its value between function calls instead of being recreated each time. For global variables, static restricts their visibility to the current file only. For functions, static means the function can only be accessed within the same source file. This helps control scope and preserve values when needed.

Scenario-Based C Programming Interview Questions

Scenario-based C programming interview questions are asked to evaluate how candidates apply theoretical knowledge to real problems. They help interviewers assess problem-solving skills, debugging ability and practical understanding of C programming concepts.

1. Your C application runs continuously on a server. After several hours, the system slows down and the program consumes increasing amounts of memory. You suspect that some dynamically allocated memory is not being released properly. How would you identify where the memory leak occurs and fix it in your program?

If my program keeps using more memory over time, I would first suspect a memory leak, meaning memory allocated with malloc() or calloc() is not being freed. To find it, I would use debugging tools like Valgrind on Linux to detect memory leaks. I would also review the code and check if every malloc() has a corresponding free(). Once I identify the location, I would add the missing free() calls and make sure memory is released when it is no longer needed.

2. You need to build a C program that processes a 10GB log file, but the system only has 4GB of RAM available. How would you design the program so it processes the file efficiently without loading the entire file into memory?

Since the file is larger than available memory, I would not load the entire file at once.

Instead, I would process the file in small chunks or line by line using functions like fgets() or fread(). The program would read a portion of the file, process it and then move to the next part. This method keeps memory usage low and allows the program to handle very large files efficiently.

3. You are developing firmware in C for a microcontroller that only has 32KB of RAM. Memory usage must be extremely efficient. What techniques or programming strategies would you use to minimize memory usage while maintaining performance?

For a system with very limited memory, I would focus on efficient memory usage.

First, I would avoid dynamic allocation and prefer static or stack memory. I would use smaller data types like uint8_t instead of int when possible. I would also reuse buffers, reduce unnecessary variables and avoid large structures. Careful code design and memory optimization are important in embedded systems.

4. You wrote a C program that uses multiple threads to update shared data. Occasionally, the output of the program is incorrect or inconsistent. What could be causing this problem and how would you modify the program to ensure correct results?

If multiple threads update shared data, the problem could be a race condition. This happens when two or more threads access the same data at the same time without proper synchronization. To fix this, I would use mutexes or locks to protect shared variables. This ensures that only one thread modifies the data at a time, which prevents inconsistent results.

5. While testing a C program, the application crashes with a segmentation fault when accessing a pointer variable. How would you investigate the cause of the crash and what steps would you take to prevent this error?

A segmentation fault usually occurs when a program accesses invalid memory, such as a null pointer, an uninitialized pointer, or freed memory. I would use a debugger like gdb to find the exact line where the crash happens. Then I would check if the pointer is properly initialized and pointing to valid memory. I would also add checks like verifying pointers are not NULL before using them.

6. A C program processes millions of records but is running very slowly. The algorithm seems correct, but the performance is not acceptable. What methods or techniques would you use to analyze the program and optimize its execution speed?

If the program is slow, I would first profile the program to identify which part takes the most time. Tools like gprof or performance analyzers can help find bottlenecks.

Then I would optimize the algorithm, reduce unnecessary loops, improve data structures and minimize expensive operations like repeated disk access. Sometimes caching results or improving memory access patterns can significantly improve performance.

7. Your C program accepts user input and stores it in a fixed-size character array using unsafe input functions. You discover that attackers might exploit this to overwrite memory. What security vulnerability exists in this situation and how would you modify the program to prevent it?

Using unsafe functions like gets() can cause a buffer overflow, where input exceeds the array size and overwrites memory. To prevent this, I would use safer functions such as fgets() or scanf() with length limits. I would also validate user input and always ensure that input does not exceed the buffer size.

8. You are building a C application that allows external developers to add new features without modifying the main program. The main program must be able to call functions provided by these plugins. How would you implement this mechanism using C language features?

To support plugins, I would design the program using function pointers and dynamic libraries. External developers could write shared libraries (.so files). The main program could load them using functions like dlopen() and get function addresses using dlsym(). This allows the main program to call plugin functions without modifying the original code.

9. You are developing a Linux utility in C that must communicate with a hardware device through a device file. Which system calls or file-handling techniques would you use to open, read from and write to the device file?

In Linux, hardware devices are usually accessed through device files. I would use system calls like:

  • open() to open the device file
  • read() to receive data from the device
  • write() to send data to the device
  • close() to close the file

These system calls allow the program to communicate directly with the hardware driver.

10. You are implementing a task scheduler in C where tasks have different priorities and the highest priority task must always execute first. Which data structure would you choose to implement this behavior and why?

For a scheduler where the highest priority task must execute first, I would use a priority queue. A priority queue automatically keeps tasks sorted based on priority. The task with the highest priority is always removed first. This structure is efficient because inserting and removing tasks can be done quickly, which makes it suitable for scheduling systems.

Wrapping Up

This article has covered a comprehensive list of C Programming interview questions with detailed answers. Exploring them will make you ready to tackle your next interview with full confidence. Keep practicing and exploring new trending technologies to stay updated with the real time knowledge.

FAQs

1. Why is C still asked in programming interviews?

C helps interviewers test a candidate’s understanding of core programming concepts such as memory management, pointers, data structures and problem-solving skills.

2. Are C programming interview questions asked only for C developer roles?

No, C questions are also asked in interviews for software engineering, embedded systems and system programming roles because they test strong programming fundamentals.

3. What topics are usually covered in C interviews?

Common topics include pointers, arrays, strings, structures, memory allocation, recursion, file handling and basic algorithms.

4. Do companies ask coding questions in C interviews?

Yes, many interviews include coding questions where candidates must write programs to solve problems using C.

Explore Our Trending Articles-

About the Author
Sanjay Prajapat
About the Author

Sanjay Prajapat is a Data Engineer and technology writer with expertise in Python, SQL, data visualization, and machine learning. He simplifies complex concepts into engaging content, helping beginners and professionals learn effectively while exploring emerging fields like AI, ML, and cybersecurity in today’s evolving tech landscape.

Drop Us a Query
Fields marked * are mandatory

Programming Certification Courses

×

Your Shopping Cart


Your shopping cart is empty.