Ever wanted to get the best discounts? Get up to 20% off. View offers

C and Interview Questions

Disclosure: Hackr.io is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission.

50+ Best C Interview Questions

Posted in C, Interview Questions

Table of Contents

Despite being almost 50 years old, C is still leading the programming scene from the forefront. The programming language not only has a wide variety of applications but is also the inspiration for a variety of modern, powerful programming languages, such as Java, C#, and Python.

Although there are very few job profiles these days that only require a high-level proficiency in C, most programming jobs necessitate for a good understanding of the fundamental concepts of the C programming language. So, many programming job interviews involve C Interview questions and answers.

Best C Interview Questions and Answers

If you’re preparing for a C programming interview questions, then you’ve landed at the right spot. Here are 40+ best C interview questions to help you get going for that job interview or to simply self-assess how good you’ve gotten with the general-purpose, procedural programming language:

Basic Level Interview Questions

Question: List some of the most important features of the C programming language.

Answer: C supports a plethora of great features. Most important among them are:

  • Extensibility - Capable of adopting new features.
  • Fast - Support for system programming allows faster compilation and execution compared to popular high-level languages like Java and Python.
  • Memory Management - Comes with built-in memory management for saving memory and optimizing memory use.
  • Middle-Level Programming Language - Binds the gap between a machine-level language and a high-level language. It can be used for system programming as well as application programming.
  • Platform independence/Portability - A C program written for one machine can run on other machines with little to no modifications.
  • Simplicity - Follows the structured approach. Facilitates breaking down a big, complex program into smaller, independent, and easy-to-manage modules (sub-programs).

Question: Please explain what is a header file in C? What will happen if we include a header file twice in a C program?

Answer: Header files store the definitions and set of rules governing different built-in functions of the C programming language. For instance, the printf() and scanf() functions are defined in the stdio.h header file.

Every header file contains a set of predefined functions, meant to make programming in C simpler. You need to include the specific header file in your C program to be able to use the functions defined in it. For example, you can’t use printf() and scanf() functions without including the stdio.h header file.

When a header file is included twice in a C program, the second one gets ignored. In actual, the #, called the include guard, preceding a header file ensures that it is included only once during the compilation process.

Question: What do you know about the C language, and who invented it and when?

Answer: The C language is one of the most commonly used computer programming languages. The language is used by giving step by step instructions, which makes it a procedural language. It is quite a widely used language that helps in carrying out systematic programming, lexical variable scope, and recurrent. C language, which is among the most popular languages, had its origin in the early 1970s in America. It was developed by American computer scientist Dennis M. Ritchie at Bell Laboratories. Since then, it has served mankind in the best possible manner and has helped in developing several system applications.

Question: Why is C language known as “The mother of programming languages”?

Answer: The C language is commonly called the “The mother of programming languages” as it is the language that forms the bases of programming. It is a time-honoured language and has been widely used to develop some of the most significant compilers and kernels. C language is as old as the hills, and most of the modern languages are nothing but an adaptation from the C languages.

Question: What are the advantages of using C language over other programming languages?

Answer: C language has the edge over the other programming language, which certainly makes it “The mother of programming language.” Some of the benefits of using C language are stated below:

Middle – Level Language: As the C language is in the midway of a high-level language and low-level language, it brings together the features of both of them. So this distinctive feature of the language makes it possible to be used for low as well as high-level programming.

  • Structured Level Language: C language is a structured programming language that allows a complex program to be divided into simpler programs called the functions. Thus making it quite a user friendly.
  • Case Sensitive Language: It is a case sensitive language due to which the lower and the upper case letters are treated differently.
  • Portable Language: C language is a highly flexible language that enables it to be used for scripting system applications, which makes it a part of many well known operating systems.
  • Powerful and Efficient Language: It is a user-friendly language and can effectively operate on games, graphics, enterprise applications, applications that need some calculations, etc.

Question: What are some of the limitations of C language?

Answer: As everything has a finite potential, so the C language stands in no exception. The following are some of the drawbacks of C languages:

  • Concept of OOPs: C language prohibits the concept of OOPs as it is based on the procedural approach. (Inheritance, Polymorphism, Encapsulation, Abstraction, Data Hiding).
  • Run Time Checking: C language does not do the running checking which means that errors are not detected after every line of coding, but only once the complete coding is done making it inconvenient to correct the bugs
  • Concept of the Namespace: C language does not exhibit the property of Namespace, so there cannot be two variables with the same name in the C language program.
  • Lack of Exception Handling: The language doesn’t exhibit the important feature of exception handling. The feature of exception handling doesn’t allow the user to detect the errors and bugs while compiling the code.
  • Insufficient Level for Abstraction: C language doesn’t have a very wide data handling capacity, which poses a threat to the security of the language.

Question: What is the objective of the main () function in C?

Answer: The main () function in C language to the inlet to the C program. It is the entry point where the process of execution of the program starts. When the execution of the C program initiates, the control of the program is directed towards the main () function. It is mandatory that every C language program has a main () function. Although it is the function that indicates the programming process, it is not the first function to be executed.

Question: What can be understood by variable and constant?

Answer: In C language, both constant and variable is widely used while designing a program. The major difference is between variables, and constant is that variable can alter its assigned value at any point of the program. In contrast, the value of the constant remains unaltered during the entire program. The value of the constant is locked during the execution of the program. For example, the value of pi can be set as a constant during the entire course of the program.

Question: Distinguish between the header file within angular braces < > and double quotes “.

Answer: Quite a difference is noticed when the header file is placed within the angular braces < > and in the double-quotes. If the header file is placed within the angular braces < >, then the compiler finds out the specific header file only within the built-in include path. But if the header file is placed in the double quotes, “then the compiler tries to locate the specific header file primarily in the current working directory, and if it cannot be located there, then it searches in the built-in included path.

Question: Does a C program compile without the main() function succeeds in compiling? What about its execution?

Answer: Yes, a C program can be compiled even without adding the main() function. However, it will not execute without the main() function.

Question: Enumerate the basic data types in C?

Answer: There are 5 basic data types in C:

  1. int - Stores an integer number
  2. float - Stores a decimal number
  3. double - Stores a decimal number with the highest precision
  4. char - Stores a single character
  5. void - Stores no value

Question: What do you mean by reserved keywords? How many reserved keywords are there in C?

Answer: Words that are restricted for general use while writing a program, i.e., for using as a name for a variable, function, structure, etc. are called reserved keywords. Reserved keywords, also called reserved names, have special meanings, i.e., they are already defined for something. The C programming language has the following 32 reserved keywords:

  1. auto
  2. break
  3. case
  4. char
  5. const
  6. continue
  7. default
  8. do
  9. double
  10. else
  11. enum
  12. extern
  13. float
  14. for
  15. goto
  16. if
  17. int
  18. long
  19. register
  20. return
  21. short
  22. signed
  23. sizeof
  24. static
  25. struct
  26. switch
  27. typedef
  28. union
  29. unsigned
  30. void
  31. volatile
  32. while

Question: How are global variables different from static variables?

Answer: Global variables are variables with global scope, i.e., they are accessible throughout the program, unless shadowed. These variables are defined outside a function or code block. Static variables are variables allocated statically, i.e., their value can’t be changed. It is fixed for the entire run of a program. They can be defined outside as well as inside functions. Moreover, they can be accessed from anywhere inside the program.

Question: Please compare static memory allocation with dynamic memory allocation?

Answer: Following are the important differences between static and dynamic modes of memory allocation:

Memory increase:

In dynamic memory allocation, memory can be increased while executing the program. This is not the case; however, with the static memory allocation where the option of increasing memory during program execution is not available.

Memory requirement

Static memory allocation needs more memory space compared to dynamic memory allocation.

Used in

Arrays use static memory allocation while linked lists use dynamic memory allocation.

When does it happen?

Static memory allocation takes place at compile-time, while dynamic memory allocation happens at runtime.

Question: Can you explain memory leak in C? Why should it be addressed?

Answer: Memory leak happens when a memory created in a heap remains undeleted. This can lead to additional memory usage and, thus, affect the performance of a program. This is exactly why the issue of memory leak must be addressed.

Question: Please explain what do you understand by while(0) and while(1)?

Answer: while(0) means that the looping conditions will always be false, i.e., the code inside the while loop will not be executed. On the opposite, while(1) is an infinite loop. It runs continuously until coming across a break statement mentioned explicitly.

Note: Any non-zero integer inside the braces of the while loop will give an infinite loop. For example, while(-22) and while(24) will both yield an infinite loop.

Question: Explain the role of protected access specifier?

Answer: The privacy of a protected keyword lies somewhere between the keywords private and public . If a class is marked as protected, it can be accessed by its member functions, classes derived with public or protected access, privately derived classes and friends of the class that declared these members.

Question: What is the keyword volatile used for?

Answer: Volatile prevents the compiler from optimizing the variable or object in question. Any code can change the variable’s ((for example, thread)) value outside the scope of current code at any time. This implies that the compiler has to keep the value of a volatile variable in all the local copies of the variable.

Question: Explain the purpose of the ‘delete’ operator?

Answer: Delete removes all the objects created by the new expression, i.e. frees memory in the heap space. The array objects are deleted using the [] operator:

delete[] array;
NULL or void Pointer can be deleted as:
delete ptr;
The same is applicable for user-defined data types as well. For example,
int *var = new int;
delete var;

Question: Explain the purpose of extern storage specifier.

Answer: The extern storage specifier helps declare objects that can be used by many source files. It describes a variable that is externally defined. The definition can appear at the beginning of a block or outside a function. There is only one declaration of the extern variable. If any other instance is found, it is considered the same as the first one. Extern variables can have block scope or file scope depending on where they are defined.

Question: Define preprocessor.

Answer: A preprocessor is a program that produces an output which is used by some other program as an input. For example, translation is a preprocessing step after which the code is sent for compilation.Preprocessor

Question: What are command-line arguments?

Answer: To control a program from outside, we supply the command line argument parameter to the program when the main method is invoked. The syntax is:

int main(int argc, char *argv[]) 

where argc, argv are command-line arguments.

Question: List out the differences between reference and Pointer?



It is an alternative name for a variable.

Stores the address of a variable.

Declared using * : int *ptr.

Declared using & : int &refvar.

Cannot have null values.

Can have null values assigned.

Can be accessed through pass by value.

Uses pass by reference.

Must be initialized upon declaration, i.e. int &ref; will give an error.

No need for initialization during declaration itself, i.e. int *ptr is correct.

Shares same memory address as the original variable and takes up some space on the stack.

Has its size and memory address on the stack.

Question: Explain the various OOPs concepts in C++?

Answer: The OOPs concepts in C++ are:

  • Class (object): Class is an entity that represents something. It has attributes and functions. For example, Car can be class having model, color, size etc. as attributes and functions can be something like isSecondHand() or isAutomatic() etc. An object is a new instance of a class that represents the actual value. An object is created using the new operator.
  • Encapsulation: The binding of all the properties and functions is called encapsulation. For example, a class can encapsulate all the properties of similar objects.
  • Polymorphism: This concept allows reuse of functionality with modifications. There are two types: Overloading, Overriding. 
  • Inheritance: A class that takes properties and methods from its parents is said to inherit the parent class. For example, Ford is a type of Car and can use the common properties and methods of the class Car. So, it can inherit the class Car.
  • Abstraction: It means showing only the high-level details to the end-user and hiding the actual implementation details. 

Read in detail about OOPs concepts

Question: Write a program to print Hello World! Without using the semicolon.

Answer: We can do so by using the if statement without the condition:

#include <stdio.h> 
#include <conio.h>
void main()
printf("Hello World!")

Output: Hello World!

Question: Explain the various types of Polymorphism in C++ with examples.

Answer: There are two types of Polymorphism, i.e. static and dynamic. Method overloading is an example of static polymorphism and method overriding is an example of dynamic polymorphism.

  • Compile-time (static binding): In this, we have two functions with the same, but the number of arguments (parameters) is different. Based on the number of parameters, the compiler decides which of the functions has to be called. Such a type is called function/operator overloading. Example:
int sum(int a, int b){ c = a+b; return c;}
int sum(int x, int y, int z){ v = x+y+z; return v;}

In the main function, we can call any:

sum1 = sum(9,5);
sum2 = sum(9,5,3);

Note that the function to be called is decided during compile time.

  • Runtime (dynamic binding): In this, the same function is present in both the parent and the child class. When the instance of either of the classes is created during runtime, then the correct method is called. The child class thus overrides the function present in the parent class with its own specific implementation. Example:
class A{
   void run(){cout<<”I am in superclass A”;}
class B: public A{
   void run(){cout<<”I am in subclass B”;}

In our main function, we can call the functions as:

A a;
B b;

The first call will print the message “I am in superclass A” and the second will print “I am in subclass B”.

Question: Examples of Namespace in C++? 

Answer: A namespace is defined as:

namespace myNmspace
 int a, b; //entities

If the variables a & b are to be accessed from outside the namespace, then we have to use the scope operator (::) as: myNmspace :: a. 

If we want to use a namespace in the current region, we use the keyword using as follows: using namespace myNmspace;

Question: Explain the various operations performed by the Pointer with examples.

Answer: A pointer stores the address of a variable. Suppose, 

int x = 2;

int *y; // pointer declaration – no value assigned, this is called wild Pointer
y = &x; // address of x stored in pointer y

This will store the address of x into y. Note that we use the ‘&’ symbol to get the address.

If no address is present to be assigned, we can point the Pointer to NULL:

int *y = NULL; // This is called null pointer

A void pointer is used to store the address of any type of variable. It can be created as:

void *y = NULL;

A pointer can be used as a replacement for the variable value using ‘*’ symbol. For example,

z = *y+1 is equivalent to z = x+1.

We can perform equality check with pointers:

int *a, *b; if a=b, then both are pointing to the same variable.

We can perform increment and decrement, for example, y++, y--.

Question: Give some important differences between new() and malloc()?




It is an operator.

It is a function.

Returns a data type.

Returns void pointer.

Memory is allocated with default values through constructor.

Memory is not initialized; the default value is garbage.

New can be overloaded.

Cannot be overloaded.

The allocations cannot be resized.

Allocations can be resized using realloc.

Question: Explain the difference between delete and delete[]?

Answer: Delete removes a single object from memory, whereas delete[] is used for de-allocating memory of an array of objects. The importance of having delete[] is that if we have a pointer (say ptr) to an array of size 10 (new myarr[10]) and simply give delete ptr, since we don’t know how many objects ptr is pointing to, and thus delete will only delete the first item. The remaining 9 items will not be deleted. This will cause a memory leak. Example:

// delete
int *var = new int;
delete var;
// delete[]
int *arr = new int[1];
delete[] arr;

Question: State the difference between prefix increment and postfix increment.

Answer: In prefix increment, the value of the variable is incremented before the program execution. The variable is incremented post the program execution in postfix increment.

++a <- Prefix increment

a++ <- Postfix increment

Intermediate Level Interview Questions

Question: Please explain the concept of Dangling Pointer in C? In how many ways can a pointer act as a Dangling Pointer?

Answer: A pointer that points to a memory location that is already deleted is called a dangling pointer. As per another definition, a dangling pointer is a pointer that points to a dereferenced memory location. A pointer acts as a dangling pointer in three cases:

  1. Deallocation of memory
  2. When the local variable isn’t static
  3. When the variable goes out of scope

Initially, the dangling pointer holds a valid memory address. Later, however, the held address is released.

The Dangling Pointer Problem:

When A pointer is pointing to a memory location, and a B pointer deletes the memory occupied by the A pointer, then the A pointer still points to the memory location, which is no longer available. This is called the dangling pointer problem.

Question: How is the null pointer different from a void pointer?

Answer: A pointer is initialized as NULL when its value isn’t known at the time of declaration. Generally, NULL pointers do not point to a valid location. Unlike NULL pointers, void pointers are general-purpose pointers that do not have any data type associated with them. Void pointers can contain the address of any type of variable. So, the data type that a void pointer points to can be anything.

#include <stdio.h>
#include <conio.h>
void main()
   int a = 22;
   int *notnullpointer = &a;
   int *nullpointer1;                                                       // Null because there is no initialization.
   int *nullpointer2 = 0;                                                // Null because initialized with 0.
   if (notnullpointer == 0) printf ("\nNot null pointer is null.");
   else printf ("\nNot null pointer is not null.");
   if (nullpointer1 == 0) printf ("\nNull pointer 1 is null.");
   else printf ("\nNull pointer 1 is not null.");
   if (nullpointer2 == 0) printf ("\nNull pointer 2 is null.");
   else printf ("\nNull pointer 2 is not null.");
   printf ("\nNot null pointer has stored the address %d.", &notnullpointer);
   printf ("\nNull pointer 1 has no valid address.");
   printf ("\nNull pointer 2 has no valid address.");


Not null pointer is not null.
Null pointer 1 is null.
Null pointer 2 is null.
Not null pointer has stored the address 2054804456.
Null pointer 1 has no valid address.
Null pointer 2 has no valid address.

Unlike NULL pointers, void pointers are general-purpose pointers that do not have any data type associated with them. Void pointers can contain the address of any type of variable. So, the data type that a void pointer points to can be anything. For example:

int x = 22;
char b = 'a';
void *vp = &x; // Here the void pointer is holding address of int x
vp = &b; // Here the void pointer is holding address of char b

Question: What do you understand by a pointer on a pointer in C?

Answer: A pointer on a pointer is a pointer containing the address of some other pointer. It is a form of multiple indirections. The first pointer contains the address of the second pointer, which points to the location of the actual value.

Question: Please explain calloc() and malloc() functions?

Answer: calloc() and malloc() are library functions used for allocating memory dynamically, i.e., the memory is allocated during runtime from the heap segment. In case of successful memory allocation, a pointer to the memory block is returned. In scenarios where allocation fails, the two functions return a NULL value. Important differences between the calloc() and malloc() functions are:

Accessing the content

If we try to access the content of memory while using the malloc() function, we can get either the segmentation fault error or garbage values. Doing the same will get 0 in the case of calloc() function.


The malloc() function allocates the memory and returns a pointer to the beginning of the block. It doesn’t initialize the allocated memory. The calloc() function, on the other end, not only allocates the memory but also initializes the allocated memory block to 0.

Number of arguments

Unlike the malloc() function, the calloc() function has two arguments:

  1. The number of blocks that are to be allocated
  2. The size of each memory block

Question: Compare arrays with pointers in the C programming language?

Answer: Following are the various differences between arrays and pointers in C:

  • Definition - An array is a form of data structure that stores multiple, homogeneous elements at contiguous memory locations. A pointer, however, is a variable that stores or points to the memory address of some other variable.
  • Initialization - It is possible to initialize arrays at the definition. Pointers, however, can’t be initialized at the definition.
  • Size - While a pointer can store the address of only a single variable, an array is capable of storing multiple elements. The total number of elements stored by arrays is determined by the array size.

Question: What are the important differences between a structure and a union in C?

Answer: Following are the three important differences between a structure and a union in the C programming language:

  • For the same data type, a structure requires more memory than a union.
  • Modifying the value of a member of a structure doesn’t affect other members. Doing the same in a union, however, results in affecting all the members of the union.
  • While only one element can be accessed at a time in the union, it is possible to access all elements of a structure simultaneously.

Check out the in-depth comparison of union vs. structure in C.

Question: How is pass by value different from a pass by reference?

Answer: Pass by value and pass by reference are also called call by value and call by reference, respectively. In the call by value, values are send/passed to the function as parameters. Pass by value is used when there is a requirement of not modifying the actual parameters. Address pertaining to the actual parameters are send/passed to the function in the call by reference. Pass by reference is used when there is a need for modifying the actual parameters. Changes made to the arguments in the called function are not reflected in the calling function in a pass by value. Opposite to this, changes made to the arguments in the called function are reflected in the calling function in a pass by reference.

Know about pass by reference in detail.

Question: Is #include "stdio.h" correct? What’s the difference between using < > and " " for including the header file?

Answer: Yes, #include "stdio.h" is correct. The difference between using angle brackets (<>) and double quotes (" ") for including a header file is the way in which the compiler searches for the particular header file.

When we use angular brackets, the compiler searches for the header file only within the built-in include path. When, however, double quotes are used, the compiler searches for the header file first in the current working directory, and then in the built-in include path when not found in the current working directory.

Question: How will you resolve the scope of a global symbol?

Answer: We can use the extern storage specifier for resolving the scope of a global symbol. The extern keyword is used for extending the visibility or scope of variables and functions. As C functions are visible throughout the program by default, its use with function declaration or definition is not required.

Question: When do we use the register keyword?

Answer: The register storage specifier, i.e., the register keyword, is used for storing a variable in the machine register. This is typically used for heavily-used variables to the likes of a loop control variable. The main intent behind using the register keyword is to speed-up the program by minimizing variable access time.

Question: What do you understand by rvalue and ivalue?

Answer: The expression on the left of the assignment operator (=) is called an ivalue. An rvalue is an expression on the right side of the assignment operator, and it is assigned to an ivalue.

For instance,

int a = 25; 

int a is the ivalue in the above-mentioned example while 25 is the rvalue. While an ivalue persists beyond a single expression, the rvalue doesn’t persist beyond the expression using it.

Question: How are actual parameters different from formal parameters?

Answer: Actual parameters are the ones that are sent to the function at the calling end. Formal parameters, however, are the ones that are received during the function definition. A formal parameter is an identifier used in some function to stand for the value that is passed into the function by a caller. This actual value that is passed into the function by a caller is the actual parameter.

Formal parameters are bound to an actual value as long as their function is active. The formal parameters do not store any values when the function returns to its caller. For Example:

#include <stdio.h>
#include <conio.h>
int totalsum(int a, int b, int c)          // Formal parameters
   int total;
   total = a + b +c;
   return total;
int main()
   int sum;
   int a = 22;    int m = 24; int p = 28;      // Actual parameters
   sum = totalsum(a, m, p);
   printf ("The total sum is %d.", sum);


The total sum is 74.

Another major distinction between actual parameters and formal parameters is that while the latter are always variables, the former can be expressions, function calls, or even numbers. For example, in the above example, the following are also valid actual parameters (in the function call to totalsum):

sum = totalsum (10+15, 12*2, 56/2);  // Actual parameters are expressions.
sum = totalsum (a, (int) sqrt(576), p);  // One of the actual parameters is a function call.
sum = totalsum (22, 24, 28);         // Actual parameters are numbers.

Question: Please explain a self-referential structure.

Answer: A self-referential structure contains the same structure pointer variable as its element. In other words, it is a data structure in which the pointer points to the structure of the same data type. A self-referential structure is used in Graphs, Heaps, Linked Lists, Trees, et cetera.

Question: What do you understand by modular programming?

Answer: Modular approach to programming involves dividing an entire program into independent, interchangeable sub-programs, i.e., functions and modules for accomplishing the desired functionality. Each of the functions or modules involved in modular programming has everything required for executing a single aspect of the desired functionality of the entire program.

Question: Please explain tokens in C.

Answer: Tokens are the smallest, indivisible units of a C program with distinct meanings. Following are the various types of tokens in C:

  • Constants - Fixed values that can’t be changed during the program execution.
  • Identifiers - This refers to the name of the functions, variables, arrays, structures, etc.
  • Keywords/Reserved Names - Predefined words with special meanings that can’t be used as variable names.
  • Operators - Symbols that tell the C compiler to perform specific logical, mathematical, or relational operations.
  • Special Characters - All characters excluding the alphabets and digits are special characters.

Question: What do you understand by the C preprocessor?

Answer: The C compiler automatically uses the C preprocessor for transforming the program, i.e., performing certain things before the actual compilation starts. The C preprocessor is a macro processor because it enables defining brief abbreviations for longer constructs, called macros.

Question: Please explain bit fields in C.

Answer: Bit fields are variables defined with a predefined width (size) inside a structure. The general syntax of a bit field is:

struct {
   type [member_name] : width ;

type - Integer type, such as int and signed int, determining how a bit field’s value is interpreted.

member-name - Name of the bit field.

width - Number of bits in the bit field. Must be less than or equal to the bit width of the specified integer type.

Question: What are command line arguments in C?

Answer: Command line arguments are the parameters passed to the main() function in a C program during program execution. The typical use of command-line arguments is to fulfill the need of controlling the program from outside.

Observe the following code,

#include <stdio.h>
#include <conio.h>
void main (int numofargs, char *args[])

In the main() function, the count of the command line arguments is given out by the numofargs. The operating system updates it automatically. The args is a pointer array holding pointers of char type. These point to the (command line) arguments supplied to the program.

Note: When no command-line arguments are passed to the program, the numofargs parameter will be 1. args[0] holds the name of the C program, args[1] points to the first command-line argument, and args[n] points to the last command-line argument.

Question: Briefly explain the various file opening modes in C?

Answer: Files are opened in a C program using the fopen() function. It is defined in the stdio.h header file. The general syntax of fopen() is:

ptr = fopen (“file address”, “mode”); 

It is possible to open a file in the following 12 different opening modes in a C program:

  1. r - Opens a file for reading.
  2. rb - Opens a file for reading in binary mode.
  3. w - Opens a file for writing.
  4. wb - Opens a file for writing in binary mode.
  5. a - Opens a file for appending i.e. adding data to the end of the file.
  6. ab - Opens a file for appending in binary mode.
  7. r+ - Opens a file for both reading and writing.
  8. rb+ - Opens a file for both reading and writing in binary mode.
  9. w+ - Opens a file for both reading and writing.
  10. wb+ - Opens a file for both reading and writing in binary mode.
  11. a+ - Opens a file for both reading and appending.
  12. ab+ - Opens a file for both reading and appending in binary mode.

Leave for r, rb, r+, and rb+ modes; the file is created if it is not found when tried to open in other modes. The fopen() returns NULL if the file doesn’t exist in these 4 file opening modes.

Question: Compare local variables and global variables.

Answer: Following are the various differences between the local and global variables:

1. Declaration

Local variables are declared inside a function, while global variables are the variables declared outside the functions.

2. Life

The life of a local variable is tied with the function block where it is declared. The variable is destroyed when the function exits. Global variables remain for the entire lifetime of the program.

3. Scope

The scope of a local variable is confined to the function or code block where it is declared. Global variables have global scope, i.e., they are available throughout the program.

4. Storage

Unless specified explicitly, local variables are stored in a stack. The storage for a global variable is decided by the compiler itself.

Question: What is a static variable? Why do we need it?

Answer: A variable whose value is fixed and can’t be changed during program execution, i.e., it retains the stored value between multiple function calls, is called a static variable. The keyword static represents a static variable. A static variable is initially initialized to 0. When the value is updated, it gets assigned to the static variable. It is initialized only once in the memory heap. We use a static variable to:

  • Reduce memory consumption
  • Sharing a common value across all functions

Question: Please explain recursion in C.

Answer: Recursion is the process when a function calls itself, directly or indirectly. Such a function is called a recursive function. There are two phases involved with a recursive function:

  1. Winding phase - It starts when the recursive function calls itself and ends once the condition is reached.
  2. Unwinding phase - Starts when the condition is reached, i.e., when the winding phase ends, and ends when the control returns to the original call.

Question: Can you write a C program to check whether an entered number is prime or not?


#include <stdio.h> 
#include <conio.h>
void main()
int a, i, b=0, flag=0;
printf("Enter a number: ");
printf("The number you entered is not a prime number!");
printf("The number you entered is a prime number.");

Sample output:

Enter a number: 22

The number you entered is not a prime number!

Question: Please write a program for finding out the factorial of a given number using recursion.


#include <stdio.h>
#include <conio.h>
long factorial (int n)
   if (n==0)
   return 1;
   return (n * factorial(n-1)); //recursion
void main()
   int number;
   long fact;
   printf("Enter a number: ");
   scanf("%d", &number);
   fact = factorial(number);
   printf("The factorial of %d is %ld!\n", number, fact);

Sample output:

Enter a number: 5
The factorial of 5 is 120!

Advanced Level Interview Questions

Question: What is a far pointer in C?

Answer: A far pointer is a 32-bit pointer capable of accessing all the 16 segments, i.e., the whole residence memory of RAM. It can access information outside the computer memory in a given segment. To use the far pointer, it is required to:

  • Allocate the sector register to store data address in the segment, and
  • Store another sector register within the most recent sector

Question: Please explain the auto keyword in C.

Answer: auto is the default storage class of all the variables declared inside a code block or function. Hence, local variables can also be referred to as automatic or auto variables. If no value is stored in an auto variable, then it gets a garbage value. Auto variables are called so because these variables allocate and deallocate memory upon entering and exiting the code block or function in which they are declared, respectively. Typically, there is no need to mention the auto keyword explicitly.

Question: Why do we use the sprintf() function?

Answer: The sprintf() function is called string print. We use the sprintf() function to store the output on a character buffer specified in the function, i.e., transferring data to the buffer. The general syntax of the function is:

int sprintf
(char *str, const char*string,.....);

The sprintf() function returns the total number of characters present in the string. Here is an example demonstrating the use of the sprintf() function: 

#include <stdio.h>
#include <conio.h>
int main()
   char buffer[25];
   sprintf(buffer, "This string is now stored in the buffer."); /* Using the sprintf() function for storing the string in the buffer.*/
   printf("%s", buffer);
   int n = sprintf(buffer, "This string is now stored in the buffer.");
   printf("\nThe total number of characters in the string is %d.", n); // The sprintf() function returns the total number of characters in the stored string.
   return 0;

Output: This string is now stored in the buffer.

The total number of characters in the string is 40.

Question: Tell the difference between getch() and getche() functions.

Answer: Both getch() and getche() functions are used for reading a single character from the keyboard. The difference between the two, however, lies in terms of displaying the output. The getche() function displays the data, the entered character, on the output screen while the getch() function doesn’t. Use Alt+F5 to see the entered character.

Question: Explain the difference between near, far, and huge pointers.

Answer: Any virtual address has the selector and offset. While a near pointer doesn’t have explicit selector, far and huge pointers do. Performing pointer arithmetic on the far pointer doesn’t result in modifying the selector. It does, however, in the case of a huge pointer.

Question: Please define typecasting.

Answer: Typecasting is the process of converting one data type into another. It is of two types:

1. Implicit type casting - Also known as an automatic conversion, implicit type conversion is performed automatically by the C compiler, i.e., it doesn’t require a casting operator. For example:

#include <stdio.h>
#include <conio.h>
void main ()
   int x = 22;
   float b = x; //implicit type conversion
   printf(“%f”, b);

Output: 22.000000

2. Explicit type casting - Unlike implicit type conversion, explicit type casting is performed by the programmer. A type casting operator is used for telling the compiler to convert (cast) one data type into another. For example:

#include <stdio.h>
#include <conio.h>
void main ()
   float x = 22.22;
   int b = (int) x; //explicit type conversion
   printf(“%d”, b);

Output: 22

Here, (int) is the typecasting operator.

Question: Write a C program to check whether an entered number is palindrome or not.

Answer: A palindrome number is one that reads the same, whether forwards or backwards. 

void main()   
   int n, r, sum=0, temp;
   printf("Enter a number: ");    
   printf("It is a palindrome number!");
   printf("It is not a palindrome number!");

Sample output:

Enter a number: 12321
It is a palindrome number!


Question: What can be understood from the null pointer and a dangling pointer?

Answer: There is a considerable difference that can be noticed in the null and the dangling pointer. The null pointer does not specifically point to anything. That is, it points to nothing. Whereas the dangling pointer is the one who initially holds a valid address, but later on, that valid address gets discharged.

Question: What are the distinct ways of passing parameters to the function and state along with which is to be used when?

Answer: There are primarily two ways of passing parameters to the function which are listed as follows:

  • Call by Reference- In this technique, the address of the actual parameter is sent instead of the values. It is chosen in the case when the user doesn’t want the actual parameter to be altered with the formal parameter.
  • Call by Value- In this technique, we only send values to the functions as the parameters. It is chosen in the case the user does want the actual parameter to be altered with the formal parameter but just to be used.

Question: What is the utilization of #undef preprocessor?

Answer: As per the C programming language, the main aim of the #undef directive is that it acts as a guide to the preprocessor to get rid of all the definitions for the particular macro. If a macro is non-specific, and #ifdef directive on that specified macro will show the result as false.

Question: What do you mean by increments and decrement statements in C programming and how we can construct that increment and decrement statements?

Answer: There are basically two types of statements, increment and decrement that are supported by C. There are basically two ways by which we can apply both the statements in C programming. The first one is using the increment operator that is ( ++ ) and the other is decrement operator ( -- ).

For example: if we use ( x ++ ), then this means to give command of increment the value of x with a rate of 1.

Question: List the difference between the source and object code.


  1. Source code: Source codes usually get a command from the programmer and these codes are responsible for instructing the computer regarding what to perform? With extension .C we can save this code in C programming.
  2. Object code: With the extension. OBJ, we can save the object code in C programming. This is the major difference between the two codes.

Question: Elaborate the process by which we can apply quote character (and) in output screen in C programming?

Answer: We all know that applying quote character is the part of printf statement an in order to apply this character in output screen, you can use the format of specifiers/ ‘ this is for a single quote and /” for a double quote.

Question: What do you mean by nested loop in C programming?

Answer: When the one loop gets into the other loop and starts running that loop is called nested loop. The outer loop will specifies the number of times the inner loop will perform its function and every time the first loop performs its tasks.

Question: What is the use of modulus operation in C programming?

Answer: Modulus operator in C programming is very important operator in this programming because this modulus operation tell the division operation in the programming function. It basically shows the remainder value left after the division between two numbers. It is represented with the symbol of (%).

For example:

  1. 20 % 3 = 2, this will be expressed as, when we divided 20 by 3 we are left with the remainder of 2.
  2. 11 % 2 =1, this means that when we divided 11 by 2 we get the remainder of 1.

Question: What is the general form that is supported by C programming? Explain its concept in detail.

Answer: It commences its process with the preprocessor directives and these directives perform a lot of function like it responsible for specifying the header files and it also tells about the constants to be used in the C programming process. This whole process is followed by the main function of this programming and that is the heading function. This function performs the variable declaration and the most important program statements.

Question: Random file access in C programming plays a very important part. Why? list some of its merits.

Answer - We all know that in every computer we store a large amount of significant information and every time we take a lot of time in finding the key content from the large database but this random access file helps in solving this problem.

  1. It helps to find the key data quicker from a large database.
  2. It helps indirectly shifting to target address when there are a lot of addresses in the programming.

Question: What is the role of structure types in C programming?

Answer: Major role played by structure types in C programming is to store the records. These records are stored according to their field types. This helps us to easily locate the record at the time of urgent search because we will find all the records in a particular field folder. This helps to save time and money.

Question: Is C language is a middle-level language? If yes then why is it so?

Answer: Yes C language is known to be a middle-level language. This is because it has a very unique and interesting feature that makes it to act like a higher-level language. But at the same time, it facilitates to use low-level methods in interacting with hardware. It also supports the use of the English type of words in its functioning. All such feature makes it to act as high-level language. Moreover, it has a unique feature of storing the memory structure.

Question: What are the functions of reserve words in C programming? Elaborate on them.

Answer: Standard C language library has certain words stored in it all such words are called reserve words. All such words are unique and have a different meaning so they cannot be used for any other kind of purpose rather than its original purpose. Some of the examples are void and return etc.

Question: What are the different control structures that is followed in the C programming?

Answer: In C programming we usually follow three types of control structures and that are sequence, selection and repetition.

  1. Sequence: this control structure follows the path that runs from a top to bottom in the process of execution of a program and this flow is in sequence.
  2. Selection: In this, the codes are executed on the conditions of evaluation as being true or false.
  3. Repetition: In this, the program statement will follow the steps of repetition. The other name of repetition is called a loop structure.

Question: What is the exact meaning of debugging in C programming?

Answer: Debugging means the process that helps in allocating the errors in the programming. It may stop the process of execution. In order to solve this process of execution, debugging will identify those errors and will remove those errors and complications. So it plays a very important role in the execution process of C programming. So it plays a very important role in the execution process of C programming.

Question: How can you apply comments in C program? Explain in detail.

Answer: Comments are basically used to give feedback or remarks in a program. All such comments are used to get instant information regarding the program that the user is using. These comments have no limit as it can be of one line and it may be of several lines and we can place these lines in any place of the program.

Question: What is the role of the algorithm in C programming? Elaborate that role.

Answer: In order to get the solution to any problem, we have to create the algorithm in order to get step by step solutions. It basically gives the ides of the starting and ending of any program, so it gives a kind of blueprint. It also tells about the computation of the process in a program.

Question: What is the exact meaning of syntax error?

Answer: The mistakes that occur in the programming language is called syntax error. It usually takes place when the command is misspelt by the program and because of that, it performs the wrong function. It can also take place when the command is to be given in lower case but by mistake, it is given in the upper case. Moreover, sometimes we make use of wrong symbols. All such problem and mistakes bring errors in the C programming.

Question: Why do we generate random symbol in the C programming?

Answer: Basically rand() command is used to generate the random symbol in the C programming.

For example- if we give the command for anyNum equal to rand(), in that case, it will generate an integer in number that commence from 0, it should be considered that the number is a variable of type integer.

Question: What is the exact meaning of C language in computer science?

Answer: C is a middle-level language that is also known as a structural programming language. because it has a very unique feature that makes it to act like a higher-level language. But at the same time, it facilitates to use low-level methods in interacting with hardware. It also supports the use of the English type of words in its functioning. All such feature makes it to act as high-level language. Moreover, it has a unique feature of storing the memory structure.

Question: Explain fast speed and memory management as a unique feature of C language?


  1. Fast speed: The operators and data types used in C programming are very effective and powerful that increases the speed of working. Hence it helps in fastening up the speed.
  2. Memory management: It has a very unique feature of in build memory that can handle a large amount of data very effectively and efficiently. This helps in improving the overall performance of C programming.

Question: For which purpose do we use the function in C programming?

Answer: The use of functions are given as follows-

  1. It does not allow the duplication of codes and information in the program. It means the rewriting of the same codes is avoided.
  2. The function of C programming is also called any number of times and that can be from any place from our program.
  3. The function helps in tracking any kind of program very easily and this can only happen when the program is divided into functions.
  4. It is very easy to break the big tasks into a smaller one thus it performs the unique function of reusability. This process of breaking down of data makes the C programming more understandable.

Question: What are the different types of recursion supported by C programming? Also, explain its types.

Answer - The process in which the function of C programming calls itself, that process is called recursion and the function that calls itself is known by the name of recursion function in C programming. This recursion is of two-phase. The first one is the winding phase and other is unwinding phase.

  1. Winding Phase: When we reach a condition in the end while the function calls itself, then it is called a winding phase.
  2. Unwinding Phase: It starts when condition-stage is reached, in this case, the control returns to its original call.

Question: What are the different types of array that are supported by C programming?

Answer - When the elements of similar types are arranged together then that stage is called array and it supports continuous memory location. It is also responsible for making the process of coding quite easy and it also makes that code sorted. These are array are generally of two types. The first one is one dimension array and other is a multidimensional array.

  1. One dimension array: Here elements are stored in a process of sequence that is one element is stored after another.
  2. Multi dimension array: The condition when the array contains more than one array, that situation is called a multi-dimension array.

Question: Explain the role of the union in C programming.

Answer: Union basically allows the user to store multiple types of data in a single unit and it is a kind of user-defined data. Its unique feature is that it does not store the memory of all the data entered into a program but it stores in the memory of the largest member only. This helps to solve the problem of overloading memory. In this, we can only have access to one kind of variable at one time.

Question: Explain the meaning and role of the auto keyword in the C programming?

Answer: Every local variable function present in C programming is called automatic or auto variable. It is very important to know that local variables are those variable that is inside the function block. The other name of the local variable is the auto variable. If the local value does not hold any key value in it then it will only show the garbage value.

Question: Explain the term memory leak and why it is important to know about this term in C programming?

Answer: Memory leak in C programming takes place when the memory is kept on storing in the memory space without deleting any information that had been used up in the process of coding. In such a situation there may be a chance of memory leak. This will definitely prove harmful for the user if the user has a daemon and servers in the program. This can leak the information to the competitors and other rivalry firms.

Question: What do you know about logical errors and bring out the difference between syntax and logical errors.


  1. Logical errors: Logical errors always take place in complication process and can pass it very easily but in that case, we will not get the desired results. Such errors occurred when we pass the wrong formula into code.
  2. Syntax error: The mistakes that occur in the programming language is called syntax error. It usually takes place when the command is misspelt by the program and because of that, it performs the wrong function. It can also take place when the command is to be given in lower case but by mistake, it is given in the upper case. Moreover, sometimes we make use of wrong symbols. All such problem and mistakes bring errors in the C programming.

Question: What is the exact role played by sequential access file in C programming?

Answer - Its main function in C programming is to store and retrieve the data in the file and then transforming that file into different forms. These are always arranged and stored in sequential order. In order to get access to one particular file, we are facilitated by reading only one data at a time.

Question: What is the importance of linked list in the C programming?

Answer: When nodes are connected with each other in a list that list is called a linked list. This list can only be created by using the pointers. This helps in making efficient use of the memory space in a program.

Question: Explain the meaning of queue and FIFO in C programming?

Answer: Queue is a kind of data structure present in the C programming and all the data present in this queue is stored in the format called FIFO. The full form of FIFO is first-in-first-out. In every queue, the first data is available on the first line.

Question: How binary trees are similar to the linked lists?

Answer: Here binary trees are the extension of the linked lists and linked lists are the nodes which are connected with each other in a list that list is called a linked list. This list can only be created by using the pointers. This helps in making efficient use of the memory space in a program. The binary list also takes the use of two-pointers and those pointers are right and left pointers. So basically every node has two pointers at the ends.


That sums up our list of the 40+ best C interview questions. How many answers you already knew? Let us know via comments. Is there some wrong/outdated information in the article? We’d be much thankful for sharing the same with us and making the article better. Want to step-up your C skills? Or wish to learn C?

If you want to polish your C programming skills before the interview, feel free to check out these best C tutorials and this C Programming For Beginners udemy course.

Asking questions related to data structure and other concepts is the norm in C interviews. Consider this helpful book for facing an interview involving such questions 189 Programming Interview Questions.

People are also reading:

Vijay Singh

Vijay Singh

My name is Vijay Singh Khatri, and I enjoy meeting new people and finding ways to help them have an uplifting experience. I have had a variety of customer service opportunities, through which I was able to have fewer returned products and increased repeat customers, when compared with co-workers. Currently working with hackr.io View all posts by the Author

Leave a comment

Your email will not be published

The answer for the question How are global variables different from static variables is wrong because the static variables can be incremented. please check the answer


Select from the best sales here