Interview Questions And Answers in C

Here are the most commonly asked interview questions on C language in any technical interview round.

Short answers to know the concept and remind it.

Most Common C interview questions with answers for freshers

1. Why is C known as the Mother Language ?

Because most of the compilers and JVMs are written in C language. Most of the languages which are developed after C language has borrowed heavily from it like cpp, python, Rust, JS etc.

2. What are the differences between Local Variables and Global Variables?

Local variables: A variable which is declared inside function or block and scope of variable is available within a function and Variables can be accessed only by those statements inside a function in which they are declared.

Global variables: A variable which is declared outside function or block and scope of variable is available throughout the program and Any statement in the entire program can access variables.

3. What is the use of writing a function in C Programming Language ?

• To avoid the rewriting the same code again and again.

• Can be called any number of times from any place of our program.

• Any part of our program can easily be tracked.

• It provide the reusability concept.

4. What is the difference between Call By Value and Call By Reference ?

Call By Value:

• Copy of the value is passed to the function, then the original value is not modified.

• Actual arguments are created in separate memory locations.

Copies of the actual arguments are passed to the formal arguments.

Call By Reference:

• Copy of the value is passed to the function, then the original value is modified.

• Actual arguments are created in same memory locations.

Address of the actual arguments are passed to the formal arguments.

5. What is recursion in C ? (IMP)

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:

Winding phase

Unwinding phase

6. What is a pointer in C ? (IMP)

A pointer is a variable that refers to the address of a value.Whenever a variable is declared inside a program, then the system allocates some memory to a variable. The memory contains some address number. The variables that hold this address number is known as the pointer variable.

7. What is a Null pointer in C ?

A pointer that doesn’t refer to any address of value but NULL is known as a NULL pointer. When we assign a ‘0’ value to a pointer of any type, then it becomes a Null pointer.A pointer pointing to nothing .

Eg: char *p=NULL;

8. What is a Far pointer in C ?

A pointer which can access all the 16 segments of RAM is known as far pointer. A far pointer is a 32-bit pointer that obtains information outside the memory in a given section.

9. What is a Dangling pointer in C ? (IMP)

If a pointer is pointing any memory location, but meanwhile another pointer deletes the memory occupied by the first pointer while the first pointer still points to that memory location, the first pointer will be known as a dangling pointer. This problem is known as a dangling pointer problem.

• Dangling pointer arises when an object is deleted without modifying the value of the pointer. The pointer points to the de-allocated memory.

10. What is the usage of pointer in C ?

• Accessing array elements

• Dynamic memory allocation

• Call by Reference

• The pointers are used to construct different data structures like tree, graph, linked list, etc.

11. What is Static Memory Allocation ? (IMP)

• Memory is allocated at compile time, and memory can’t be increased while executing the program. It is used in the array.

• The lifetime of a variable in static memory is the lifetime of a program.

• The static memory is allocated using static keyword.

• The static memory is implemented using stacks or heap.

• The pointer is required to access the variable present in the static memory.

• The static memory is faster than dynamic memory.

• In static memory, more memory space is required to store the variable.

12. What is Dynamic Memory Allocation ? (IMP)

• Memory is allocated at runtime and memory can be increased while executing the program. It is used in the linked list.

• The malloc() or calloc() function is required to allocate the memory at the runtime.

• An allocation or deallocation of memory is done at the execution time of a program.

• No dynamic pointers are required to access the memory.

• The dynamic memory is implemented using data segments.

• Less memory space is required to store the variable.

13. What is a structure in C ?

The structure is a user-defined data type that allows storing multiple types of data in a single unit. It occupies the sum of the memory of all members.

Structure variables accessing the same structure but the memory allocated for each variable will be different.

14. What is a union ?

The union is a user-defined data type that allows storing multiple types of data in a single unit. However, it doesn’t occupy the sum of the memory of all members. It holds the memory of the largest member only.

15. What is an auto keyword in C ?

In C, every local variable of a function is known as an automatic (auto) variable. The local variables are also known as an auto variable. It is optional to use an auto keyword before the data type of a variable. If no value is stored in the local variable, then it consists of a garbage value.

16. What is a token ?

The Token is an identifier. It can be constant, keyword, string literal, etc. A token is the smallest individual unit in a program. C has the following tokens:

Identifiers: Identifiers refer to the name of the variables.

Keywords: Keywords are the predefined words that are explained by the compiler.

Constants: Constants are the fixed values that cannot be changed during the execution of a program.

Operators: An operator is a symbol that performs the particular operation.

Special characters: All the characters except alphabets and digits are treated as special characters.

17. 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

}

18. What is a file?

A file is a named location which stores data or information permanently. A file is always stored inside a storage device using file name (e.g. STUDENT.MARKS).

19. What is Function Overloading ?

Overloading is when two or more methods in the same class have the same method name but different parameters.

20. What is Function Overriding ?

Overriding is when two methods having the same method name and parameters but one of the methods is in the parent class and the other is in the child class.

21. How memory allocation can be done in C ?

Using malloc( ):

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

Using calloc( ):

ptr = (float*) calloc(25, sizeof(float));

22. How memory de-allocation can be done in C ?

The memory allocated using functions malloc() and calloc() is not de-allocated on their own. Hence the free() method is used to de-allocate the memory.

Syntax: free(ptr);

23. What is realloc() method in C ?

It is used to dynamically change the memory allocation of a previously allocated memory.

24. Differentiate between Compiler and Interpreter ?

An interpreter reads one instruction at a time and carries out the actions implied by that instruction. It does not perform any translation. But a compiler translates the entire instructions.

25. What are storage specifiers in C ?

auto: It is a default storage class.

extern: It is a global variable.

static: It is a local variable which is capable of returning a value even when control is transferred to the function call.

register: It is a variable which is stored inside a Register.

26. Can the main( ) function left empty ?

Yes, But program doing nothing.

27. What is infinite loop ?

A loop executing repeatedly as the loop-expression always evaluates to true such as

while(0 == 0){

}

Software Engineer, Web developer, Full time learner, blogger(educational, development blogs, Interview preparation materials for freshers)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store