C Programming Interview Questions (2022)

Dheeraj Patidar

In this article, I will share you some frequently asked C Programming Questions so that you can prepare more well for Interview.

Some frequently asked C programming interview questions and answers are given below.


C Programming Interview Questions  (2022)

1) What is C Programming?

C is a programming language developed at Bell telephone laboratories in 1972 by Dennis Ritchie. It is one of the oldest and finest programming language.

C programming language is reliable simple and easy to use structured programming language. 

Read more…

2) Why is C known as a mother language?

C is known as a mother of programming languages because JVM and other compilers are made in C programming.

Most of the high level programming languages like C++, Python, Rust, Java, JavaScript, etc are written in C programming. 

The concept of Array, function, file handling, etc are inherent from the C programming to other languages.

3) Why is C called a mid-level programming language?

C is called a mid-level programming language because it binds the low level and high -level programming language.

As well C programming is used as System programming to develop the operating system as well as an Application programming to generate menu driven customer driven billing system.

4) Who is the founder of C language?

The founder of C Programming is Dennis Ritchie.

5) When was C language developed?

C language was developed in 1972 at bell laboratories of AT&T.

6) What are the features of C Programming?

The main features of C Programming are as follows:

  • Simple: C is a simple language because it follows the structured approach, i.e., a program is broken into parts
  • Fast Speed: C language is very fast as it uses a powerful set of data types and operators.
  • Mid Level: C is a mid-level programming language as it combines the low- level language with the features of the high-level language.
  • Portable: C is highly portable means that once the program is written can be run on any machine with little or no modifications.
  • Structured: C is a structured language as the C program is broken into parts.
  • Memory Management: C provides an inbuilt memory function that saves the memory and improves the efficiency of our program.
  • Fast Speed: C language is very fast as it uses a powerful set of data types and operators.
  • Extensible: C is an extensible language as it can adopt new features in the future.

7) What is the use of printf() and scanf() functions?

printf(): the printf() function is used to print integer, float, and string, to the screen.

scanf(): the scanf() function is used to take value entered by user in any variable.

Some formate specifiers are as follows:

  • %d: It is a format specifier used to print an integer value.
  • %s: It is a format specifier used to print a string.
  • %c: It is a format specifier used to display a character value.
  • %f: It is a format specifier used to display a floating point value.

8) What is the use of static variable in C programming?

following are the uses of static keyword in C:

  • Static variables are used because the scope of the static variable is available in the entire program. So, we can access a static variable anywhere in the program.
  • The static variable is initialized only once in the memory heap to reduce the memory usage.
  • A variable which is declared as static is known as a static variable. The static variable retains its value between multiple function calls.
  • The static variable is used as a common value which is shared by all the methods.
  • The static variable is initially initialized to zero. If we update the value of a variable, then the updated value is assigned.

9) What is the use of function in C?

Functions are used to:

  • Avoid rewriting of the same code again and again 
  • Call part of program number of time for specific operation.
  • Devide the program in systematic manner.
  • Make code easy to understand and breakdown the long task into small sub task.

10) What is the difference between Local Variable and Global Variable in C Programming

Following are the differences between a local variable and global variable:

Basis for comparison Local variable Global variable
Declaration Declared Inside function or block is known as a local variable. Declared outside function or block is known as a global variable.
Scope function in which they are declared. throughout the program.
Access can be accessed only by those statements inside a function in which they are declared. Any statement in the entire program can access variables.
Life created when the function block is entered and destroyed on its exit. until the program is executing.
Storage Variables are stored in a stack unless specified. The compiler decides the storage location of a variable.

11) What is Recursion in C?

When a function calls itself, and this process is known as recursion. The function that calls itself is known as a recursive function.

Recursive function comes in two phases:

  1. Winding phase
  2. Unwinding phase

Winding Phase: when a function call itself until a certain condition occurs.

Unwinding Phase: when a function call itself and after execution return to the original 

12) What is an array in C?

In C programming array is a variable which store similiar kind of multiple values. It basically store values in contiguous memory allocation. 

Array makes code optimized, easy to traverse and sort. The size and type of C array doesn’t change after declaration.

There are two types of array:

One-dimensional array

One-dimensional array is an array that stores the elements one after the another.

Syntax: data_type array_name[size]; 

Multidimensional array

Multidimensional array is an array that contains more than one array.

Syntax: data_type array_name[size]; 

Read more…

13) What is a pointer in C? Types of pointer

pointer is variables that stores the address of another variable. Generally pointers are used to to access the information of a memory location.


data type* variable;


data type *variable;


int *a;

Types of pointer in C:

Typed Pointer: always points to specific type of data. Like integer pointer, double pointer, struct emp pointer, string pointer, array pointer.

Untyped Pointer: Can points to any type of data. Also called generic pointer. Only void pointer comes under generic pointer.

Read more…

14) What are the usage of the pointer in C?

Accessing array elements: Pointers are used in traversing through an array of integers and strings. The string is an array of characters which is terminated by a null character ‘\0’.

Dynamic memory allocation: Pointers are used in allocation and deallocation of memory during the execution of a program.

Call by Reference: The pointers are used to pass a reference of a variable to other function.

Data Structures like a tree, graph, linked list, etc.: The pointers are used to construct different data structures like tree, graph, linked list, etc.

15) What is Dangling Pointer in C?

Dangling Pointer is a pointer which holds the non-existing memory address. Means we can say that Dangling pointer is a pointer pointing to a memory location that has been freed (or deleted).

There are different conditions in which any pointer become dangling pointer :-

  • When Variable goes out of scope
  • When Function call
  • When De-allocation of memory by free function

16) What is String?

string is a one dimensional character array terminated by a null (‘\0’). When the compiler encounters a sequence of characters enclosed in the single quotation marks, it appends a null character \0 at the end by default. Null Character (\0) Means terminating String and the ASCII value of Null (\0) character is 0.

Syntax:- char identity[size];

Declaration:- char name[20];

Read more…

17) What is the structure?

structure is a user defined data type. Using structure we can Store n number of elements of different data type in a single variable.

For example in Array Consept we can store n number of element but of same data type. due to this disadvantage of array the concept of structure is introduced.


struct structureName 


    dataType member1;

    dataType member2;





struct emp


char ename[20]; //use of string for storing name

int ecode;

float esalary;


One more important thing about structure is that Primitive data type having only single word like int, float, char. but user Defined dataType is a collection of word like structure emp.


struct emp
char ename[20];
int ecode;
float esalary;

int main(){

int a; // Here int is a dataType of variable a
struct emp e1; // here struct emp is a dataType of variable e1
some code

Read more…

18) What is union in c programming?

union is a user defined data type like structure. But union members share same memory location for storing and processing the data. 


In above example we found that in structure a and b both members get different memory location but in union a and b share same memory location. 


union unionName 


    dataType member1;

    dataType member2;





union abc


int a;

char b;


19) What is Static Memory Allocation?

Fixed Memory allocated during the run time is called static memory. We called static memory is a fixed memory because this memory size is decided by programmer. 

If user cannot Store any element in array then wastage of memory is occur and if user want to input element across the limit then it is not possible. That’s why we called static memory is a fixed memory. 

Some Problems in Static Memory Allocation:-

  • If you want to allocate memory for an array during run time then you have to fix the size of array at the time of declaration because Size is fixed and user cannot increase or decrease the size at run time.
  • If the values stored by the user in array is less than the specified size then there will be wastage of memory occur.
  • If the values stored by the user in array is more than the specified size then the program may crush or misbehave.

20) What is dynamic memory allocation?

To avoid all the problems during static memory they introduced dynamic memory allocation concept. When Memory allocation is depend on the increment and decrement of the data is called dynamic memory allocation. 

We can say that Sometimes the size of the array you declared may be insufficient. To solve this issue, you can allocate memory manually during run-time. This is known as dynamic memory allocation in C programming.

Following are the functions used in dynamic memory allocation:

  • malloc()
  • calloc()
  • realloc()
  • free()

Read more…

21) What is the Difference between Static nar Dynamic Memory Allocation?

Static Memory Dynamic Memory
Static Memory is Allocated during the run time of Program but it is a fixed size memory which is previously decided by programmer.

Dynamic Memory is also allocated during the run time of a program but the size of memory is depend on the increment & decrement of elements
we cannot increase the size of array & structure at the run time of program It is possible to increase the size of array, structure at the run time of Program.

If the values stored by the user in array is more than the specified size then the program may crush or misbehave. This problem is not occur in dynamic memory allocation because the size of memory is depend on the number of elements.
there is no pointer concept is used to allocate static memory. In the concept of dynamic memory allocation pointer concept is used. Because malloc and calloc function returns the address of memory block which is created by them.
static memory is a default memory which is allocated by computer when we declare any array or structure. Dynamic memory is a custom memory which is are located by computer but declared by malloc and calloc function according to the End-user requirement.
No special functions are used to allocate static memory. To allocate memory dynamically we need to use 4 special functions of stdlib.h header file which is malloc(), calloc(), realloc(), free()

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

Key Points calloc() malloc()
Description The malloc() function allocates a single block of requested memory. The calloc() function allocates multiple blocks of requested memory.
Initialization It initializes the content of the memory to zero. It does not initialize the content of memory, so it carries the garbage value.
Number of arguments It consists of two arguments. It consists of only one argument.
Return value It returns a pointer pointing to the allocated memory. It returns a pointer pointing to the allocated memory.

23) What is command line argument?

The argument passed to the main() function while executing the program is known as command line argument. 

For example:

main(int count, char *args[]){  

//code to be executed  


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

The getch() function reads a single character from the keyboard. Entered data isn’t showed on screen, because it has no buffer.

The getche() function reads a single character from the keyword, but data is displayed on the output screen. Press Alt+f5 to see the entered character.

25) What is typecasting in C?

The conversion of one data type to another is called typecasting. If we want to store the floating type value to an int type, then we will convert the data type into another data type explicitly.


(type_name) expression;  

26) What are the functions to open and close the file in C language?

The fopen() function is used to open file whereas fclose() is used to close file.

27) What is an infinite loop?

A loop running continuously for an indefinite number of times is called the infinite loop.

Infinite For Loop:


//code to be executed  


Infinite While Loop:


//code to be executed  


Infinite Do-While Loop:


//code to be executed  


28) What is the purpose of sprintf() function?

The sprintf() stands for “string print.” The sprintf() function does not print the output on the console screen. It transfers the data to the buffer. It returns the total number of characters present in the string.


int sprintf ( char * str, const char * format, … );  

29) What functions are used for dynamic memory allocation in C language?

1) malloc()

  • The malloc() function is used to allocate the memory during the execution of the program.
  • It does not initialize the memory but carries the garbage value.
  • It returns a null pointer if it could not be able to allocate the requested space.


ptr = (cast-type*) malloc(byte-size) // allocating the memory using malloc() function

2) malloc()

The calloc() is same as malloc() function, but the difference only is that it initializes the memory with zero value.


ptr = (cast-type*)calloc(n, element-size); // allocating the memory using calloc() function

3) realloc()

The realloc() function is used to reallocate the memory to the new size.

If sufficient space is not available in the memory, then the new block is allocated to accommodate the existing data.


ptr = realloc(ptr, newsize); // updating the memory size using realloc() function.  

In the above syntax, ptr is allocated to a new size.

4) free()

The free() function releases the memory allocated by either calloc() or malloc() function.


free(ptr); // memory is released using free() function.  

The above syntax releases the memory from a pointer variable ptr.

30) What is sizeof operator and what is the use of it in C programming?

size of operator is a unary operator which is used to determine the size of any operand. It returns this size of a variable. It can be applied to any data type like int, float, char, pointer, structure, typedef, union, etc.

Syntax or Prototype :- 

int sizeof(operand or data type)

Ex. => sizeof(a) , sizeof(int), sizeof(struct emp), sizeof(arr), sizeof(str).


So guys, these are all questions which are frequently asked in Interviews. If you have add C programming in your Resume then readout these questions before interview.

I will add more questions in this post. Keep in touch with us so you will get more and more interview questions idea.

Thanks for Visiting us!

Leave a Reply

Your email address will not be published. Required fields are marked *