Top C Interview Questions and Answers for Freshers (Simple & Easy Explanation)

Mou

October 29, 2025


Top C Interview Questions and Answers for Freshers (Simple & Easy Explanation)

If you are preparing for your first programming interview, especially in C language, this guide will help you a lot. C is one of the oldest and most powerful programming languages that helps in understanding the basics of coding, memory, and logic building. Most companies, even today, ask C programming questions in their technical interviews.

In this post, we will cover commonly asked C interview questions for freshers along with simple explanations and examples. All answers are written in easy language so that even beginners can understand them clearly.


1. What is C language?

Answer:
C is a structured, high-level programming language developed by Dennis Ritchie at Bell Labs in 1972. It is mainly used to develop system software, operating systems, and embedded systems.

C is often called the mother of all programming languages because many modern languages like C++, Java, and Python are based on its concepts.


2. What are the main features of C language?

Answer:
Some important features of C are:

  • Simple and efficient: Easy to learn and execute fast.
  • Structured language: Programs are divided into functions.
  • Portable: Same C code can run on different machines.
  • Memory management: Supports dynamic memory allocation.
  • Rich library: Many built-in functions and operators are available.

3. What is the difference between compiler and interpreter?

Answer:

CompilerInterpreter
Translates the entire code at once.Translates line by line.
Faster execution.Slower execution.
Example: C, C++ use compiler.Example: Python uses interpreter.

C uses a compiler to convert source code into machine code before execution.


4. What are the basic data types in C?

Answer:
C provides different data types to store values:

  • int – for integer numbers (e.g., 10, -5)
  • float – for decimal numbers (e.g., 3.14)
  • char – for single characters (e.g., ‘A’)
  • double – for large floating-point numbers

Example:

int age = 25;
float salary = 20000.50;
char grade = 'A';

5. What is the difference between local and global variables?

Answer:

  • Local variable: Declared inside a function and can be used only within that function.
  • Global variable: Declared outside all functions and can be accessed anywhere in the program.

Example:

#include <stdio.h>
int num = 10; // global variable

void show() {
    int num2 = 20; // local variable
    printf("%d", num2);
}

6. What is the use of printf() and scanf()?

Answer:

  • printf() is used to display output on the screen.
  • scanf() is used to take input from the user.

Example:

int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("You entered: %d", age);

7. What are keywords in C?

Answer:
Keywords are reserved words that have special meaning in C. They cannot be used as variable names.
Example: int, return, if, else, while, break, for, switch, etc.
There are 32 keywords in C.


8. What is the difference between = and == operator?

Answer:

  • = is the assignment operator. (Used to assign value)
  • == is the comparison operator. (Used to check equality)

Example:

int a = 5;       // assigns 5 to a
if (a == 5) {    // compares value of a with 5
    printf("Equal");
}

9. What is a function in C?

Answer:
A function is a block of code that performs a specific task. It helps in reusing code and organizing programs better.

Example:

#include <stdio.h>
void greet() {
    printf("Hello, welcome!");
}

int main() {
    greet();
    return 0;
}

10. What is recursion in C?

Answer:
Recursion is a process where a function calls itself to solve a smaller version of a problem.

Example (factorial):

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

11. What are loops in C?

Answer:
Loops are used to execute a block of code multiple times.
Types of loops:

  • for loop
  • while loop
  • do-while loop

Example:

for(int i = 1; i <= 5; i++) {
    printf("%d ", i);
}

12. Difference between while and do-while loop

Answer:

while loopdo-while loop
Condition is checked first.Condition is checked after executing the body.
May not run even once.Runs at least once.

Example:

do {
   printf("Hello");
} while(0);

It prints “Hello” once.


13. What is an array?

Answer:
An array is a collection of similar data types stored in continuous memory locations.

Example:

int numbers[5] = {1, 2, 3, 4, 5};

Here, numbers can store 5 integers.


14. What is a pointer in C?

Answer:
A pointer is a variable that stores the memory address of another variable.

Example:

int a = 10;
int *ptr = &a;
printf("%d", *ptr); // prints 10

15. What is the difference between call by value and call by reference?

Answer:

  • Call by value: Copies the actual value to the function. Changes inside the function do not affect the original variable.
  • Call by reference: Passes the address, so changes affect the original variable.

Example:

void change(int *x) {
   *x = 50;
}

16. What is a structure in C?

Answer:
A structure is a user-defined data type that groups different data types together.

Example:

struct Student {
   int id;
   char name[20];
   float marks;
};

17. What is a string in C?

Answer:
A string is a collection of characters ending with a null character ('\0').

Example:

char name[] = "Moutusi";
printf("%s", name);

18. What is the difference between break and continue?

Answer:

  • break → exits from loop immediately.
  • continue → skips the current iteration and continues with the next.

Example:

for(int i=1; i<=5; i++) {
   if(i==3) continue;
   printf("%d ", i);
}

Output: 1 2 4 5


19. What is the use of header files in C?

Answer:
Header files contain predefined functions and macros.
Example:

  • #include <stdio.h> – for input/output functions.
  • #include <math.h> – for math functions like sqrt() or pow().

20. What are macros in C?

Answer:
Macros are preprocessor directives used to define constants or expressions before the program runs.

Example:

#define PI 3.14

21. What is dynamic memory allocation?

Answer:
Dynamic memory allocation means allocating memory at runtime using functions like malloc(), calloc(), realloc() and free().

Example:

int *ptr = (int*)malloc(5 * sizeof(int));

22. What is the difference between malloc() and calloc()?

Answer:

malloc()calloc()
Allocates single block of memory.Allocates multiple blocks of memory.
Memory not initialized.Memory initialized to zero.

23. What is a dangling pointer?

Answer:
A dangling pointer is a pointer that points to memory which has been freed or deleted.
It leads to unpredictable behavior and crashes.


24. What is a segmentation fault?

Answer:
Segmentation fault occurs when a program tries to access memory that it should not, such as dereferencing a NULL or invalid pointer.


25. What is the difference between ++i and i++?

Answer:

  • ++i → pre-increment (value increases first, then used).
  • i++ → post-increment (value used first, then increases).

Example:

int i = 5;
printf("%d", ++i); // 6
printf("%d", i++); // 6 then becomes 7

26. What is the use of sizeof() operator?

Answer:
It returns the memory size (in bytes) of a data type or variable.
Example:

printf("%lu", sizeof(int)); // typically prints 4

27. What is type casting in C?

Answer:
Type casting converts a variable from one data type to another.
Example:

float a = 5.6;
int b = (int)a;  // converts float to int

28. What are storage classes in C?

Answer:
Storage classes define the scope, visibility, and lifetime of variables.
Types:

  1. auto
  2. register
  3. static
  4. extern

29. What is the difference between compile-time and runtime errors?

Answer:

  • Compile-time error: Found by compiler (syntax errors).
  • Runtime error: Occurs while program runs (like division by zero).

30. What is the purpose of return 0 in main()?

Answer:
It indicates successful execution of the program to the operating system.


Conclusion

C is the foundation of many programming languages, and having a good grip on it gives you a strong base for your programming career. These C interview questions for freshers are not just for interviews but also to help you understand how things work behind the scenes in programming.

Practice small programs, understand memory concepts, and focus on logic. That’s the real key to cracking C interviews easily.


Leave a Comment