Top 40 C Language Interview Questions for 2021

Here is the list of commonly asked C programming interview questions. These are the basic C interview questions that will help you during interviews.

Table of Contents

1. What are the features of the C programming language?

Below are the features of the C programming language:

  • Simple: It follows a structured approach where it allows the program to be split or broken into smaller parts
  • Fast: Faster compilation and execution
  • Portable: Allows execution of the C program on any machine without or very little modification
  • Mid-level: It combines features of both low-level and high-level language.
  • Memory management: Has in-built memory
  • Extensible: It can adopt new features.

2. What are the different data types in C?

  • int: Integer values
  • float: Float value which is a number with a fraction part
  • double: double-precision floating-point value
  • char: a single character
  • void: special-purpose type without any value

3. What are the uses of print() and scanf() functions?

The print() functions prints the values like integer, character, float, string, etc

The scanf() function takes or retrieves the input from the user.

4. What is the difference between a global and a local variable?

Global variableLocal variable
It is a variable which is declared outside a function or a blockIt is a variable that is declared inside a function or a block
Scope is within the entire programScope is within the specified function or block
It is accessible by any statementIt is accessible only by statements within the block or function where the variable is declared
The compiler decides where to store the variableLocal variable is stored in a stack
The lifetime of global variable ends with the termination of the programThe lifetime of the local variable ends with the function exit

5. What is a static variable?

A variable that is declared with the keyword static is a static variable. The value of a static variable is retained throughout the program and is common for all method calls. It is initialized only once and hence saves a lot of memory.

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

Call by valueCall by reference
When we pass the argument as a value, the original value is not modifiedWhen we pass the argument as a reference, then the original value is also modified
Actual and formal arguments are stored in separate locationsActual and formal arguments are stored in the same memory locations
Call by value arguments are safe since value is not modifiedCall by reference arguments are unsafe since values can be updated
The copy of the original argument is passedThe address of the original argument is passed.

7. What is a NULL pointer in C?

A NULL pointer is a pointer that does not have any address which means it has only a value of 0.

8. What is a dangling pointer?

A dangling pointer is a pointer whose memory space is deleted while it is still pointing to it. This means when the pointer points to some memory and another pointer deletes it, then the first pointer is called a dangling pointer.

9. What is a pointer to a pointer?

When a pointer points to the address of another pointer, we call it a pointer to a pointer concept. It is also called a chain of pointers.

10. What is a pointer in C?

Every time we create a variable, it allocates some memory. This memory refers to an address number. The variable that holds this address number is a pointer. In other words, a pointer is a variable that stores the address of the value and hence makes the performance much faster.

11. What are the different storage class specifiers in C?

The different storage class specifiers are register, auto, static, and extern

12. What is a memory leak?

A memory leak is a situation when we forget to delete or free the memory after its usage.

13. When to use pointers in C?

We use pointers in the below cases:

  • To retrieve the address of the variable
  • To implement pass by reference
  • Pass large structures

14. What is debugging?

Debugging is the process of identifying and removing errors. When there are compilation errors, we cannot execute the code.

15. Is the statement correct: strValue = “C interview questions”?

No, this is incorrect since we cannot assign values to a variable using the equalto operator(=) in the C programming language. We need to use the strcpy() method as given below.

strcpy(myValue,"C interview questions");

16. What is FIFO?

FIFO stands for First-In-First-Out. This is mainly used in the queue data structure, where the element we insert first is retrieved first. It is used in storing and retrieval operations.

17. What is the difference between = and == symbols?

The equalto = is a mathematical operator that we use to assign a value to a variable whereas the equalto relational operator == is used to compare two values.

18. Write a C program to print “C programming questions” without a semicolon.

void main() {
     if(printf("C programming questions")) {

19. What are the functions used in dynamic memory allocation?

Dynamic memory allocation allocates memory during runtime which means during execution we can increase or decrease the memory space. Below are the functions that support dynamic memory allocation:

  1. malloc(): It does not initialize the memory and contains garbage value
  2. calloc(): It initializes the memory with the value 0.
  3. realloc(): It reallocates the memory to occupy the new size.
  4. free(): It releases the memory

20. What is the difference between malloc and calloc?

Allocates multiple blocks of memoryAllocates single block of memory
It contains a single argumentIt contains two arguments
It stores garbage value as defaultIt stores 0 as default initialization

21. What is an auto keyword in C programming language?

Every local variable that we create is an automatic or auto variable event though we do not explicitly mention using the auto keyword. A local variable is always declared within the function and contains a garbage value by default if we do not initialize it with any value.

22. What is the use of sprintf() function?

The sprint() function returns the number of characters in the string and does not print the value in the console. Instead, it stores it in the buffer.

23. Is it possible to compile a C program without the main() function?

Yes, we can compile but cannot execute it. To execute, we can use the #define statement

24. What is the difference between getch() and getche()?

The getch() reads a single character and does not print the value in the output screen whereas the getche() method reads a single character and prints it in the output screen.

25. What are reserved words in C programming?

The reserved words are special words that have a unique meaning or functionality. It is present in the C library and we cannot use them as variable names. Example: void, return, etc

26. What is the difference between pre-increment(++a) and post-increment(a++) operators?

The prefix operator increments the value first and then assigns the value to the variable. The postfix operator increments the value after the variable is used.

27. What is a newline escape sequence?

The newline escape sequence denotes a new line while printing the output in the console. We can achieve this using the “\n” symbol.

28. Can we store the value 32768 as an int data type?

No, we cannot since an integer value ranges from -32768 to 32767. Instead, we can use it as a long int.

29. What is a C token?

A token is an identifier in C programming language. It contains identifiers, keywords, literals, constants, operators, and special characters.

30. What is toupper() method in C

The toupper() method converts the value from lower case to upper case.

31. What is the difference between declaring the header file with <> and ” “?

When we use <> with the header file, it searches for the header file within the built-in path whereas when we use ” “, it searches for the header file in the current working directory.

32. What is typecasting?

Typecasting is the process of converting from one data type to another. For example, we can convert a value from float to integer explicitly by typecasting.

33. Write a C program to swap to numbers without using the third variable.

#include <stdio.h>

int main()
   int a = 5;
   int b = 10;
   printf("Values before swapping: a=%d b=%d", a,b);
   a = a + b;
   b = a - b;
   a = a - b;
   printf("Values after swapping: a=%d b=%d", a,b);

    return 0;
Values before swapping: a=5 b=10                                                                                                              
Values after swapping: a=10 b=5

34. What is the difference between while(0) and while(1)?

while(0) always returns false which means it never executes the code within the while loop whereas while(1) always returns true and represents an infinite loop that continuously executes the code within the loop and does not exit.

35. What are command-line arguments?

The command-line arguments allow users to provide input from the console by passing the parameters mentioned in the main method.

36. What is a static variable?

Static variables are variables that share the same values across the code. We can use the static keyword to represent a static variable.

37. What is recursion?

Recursion is the process of calling the same function by itself again.

38. What is the fullform of ANSI?

ANSI stands for American National Standards Institute

39. What is a pointer to a function?

A pointer that holds a reference to a function is a pointer to a function.

40. Which keyword performs unconditional branching?

We can use the goto keyword to perform unconditional branching.

Array Interview Questions
Graph Interview Questions
LinkedList Interview Questions
String Interview Questions
Tree Interview Questions
Core Java Interview Questions