C Interview Questions

1. What is C language?

C is a general-purpose, procedural programming language. It was developed by Dennis Ritchie in 1972 and is used to write operating systems, compilers, and system-level programs.

2. What are the key features of C language?

  • Simple and fast
  • Portable (runs on different systems)
  • Procedural (code is written as functions)
  • Rich library
  • Low-level memory access (via pointers)

3. What is the difference between == and = in C?

=is an assignment operator (e.g., a = 10,)

= is a comparison operator (e.g., IF(a == 10,TRUE()))

4. What is a variable in C?

A variable is a name that stores data.

Example:

int age = 25; 

5. What are data types in C?

They define the type of data a variable can hold:

  • int – Integer (e.g., 10)
  • float – Decimal (e.g., 3.14)
  • char – Character (e.g., 'A')
  • double – Double precision decimal

6. What is a pointer?

A pointer stores the memory address of another variable.

Example:

int a = 10;
int *p = &a;

7. What is the use of & and * in pointers?

& gives the address of a variable

* gives the value stored at that address

8. What is a function in C?

A block of code that performs a task.

Example:

int add(int a, int b) {   
     return a + b; 
} 

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

  • Call by value: Copies the value (original doesn't change)
  • Call by reference: Uses address (original can change)

10. What is an array?

An array stores multiple values of the same type.

Example:

int marks[3] = {85, 90, 95};

11. What is a string in C?

A string is an array of characters ending with \0.

Example:

char name[] = "John";

12. What is the difference between ++a and a++?

  • ++a: Pre-increment (increases first, then uses)
  • a++: Post-increment (uses first, then increases)

13. What is typedef in C?

It creates a new name for an existing data type.

Example:

typedef int age; 
Age a = 25; 

14. What is recursion?

A function calling itself.

Example:

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

15. What is the static keyword?

It keeps the variable value even after the function ends.

16. What is the difference between struct and union?

  • struct: All members have separate memory.
  • union: All members share the same memory.

17. What is NULL in C?

NULL is a constant that means the pointer doesn't point to anything.

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

malloc() allocates memory (doesn’t initialize it).

calloc() allocates and initializes memory to zero.

19. What is sizeof operator?

It gives the size (in bytes) of a variable or data type.

Example: sizeof(int) → usually 4 bytes.

20. What is the role of the main() function?

main() is the entry point of every C program. Execution starts from here.