C Programming Interview Questions

Ques. What are the key features of C programming language?

Ans. C is a platform-dependent language. C offers the possibility to break down a large program into small modules. Also, the possibility of a programmer to control the language. C comes with support for system programming and hence it compiles and executes with high speed when compared to other high-level languages.

Ques. What is the use of header files in C?

Ans. Header files contain the definitions and set of rules of the functions being used in the programs. For example, when you use printf() or scanf() in your program, you nee to include stdio.h library function. Else your compiler will show an error. This is because, the standard input and output functions printf() and scanf() are stored in this header file. So similarly every header file stores a set of predefined functions which makes it easy to program.

Ques. What is Memory Leak in C?

Ans. A memory leak occurs when programmers create a memory in the heap and forget to delete it. It decreases the efficiency of the performance of the system.

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

Ans. ‘++a’ is called prefix increment. First, the value stored in the variable ‘a’ gets incremented and then gets assigned to the same variable. Whereas, ‘a++’ is called postfix increment. The value stored in the variable ‘a’ gets incremented after the execution of the particular line.

Ques. What is a Dangling Pointer in C?

Ans. A pointer pointing to a dereferenced memory location is called dangling pointer. i.e. pointer pointing to the memory location which is deleted. There are three different ways where a pointer can act as a dangling pointer. De-allocation of memory When the local variable is not static When the variable goes out of scope

Ques. Difference between malloc() and calloc() functions?

Ans. malloc and calloc are library functions that allocate memory dynamically, which means that memory is allocated during the runtime from the heap segment. Malloc and Calloc differ in the number of arguments used, their initialization methods and also in the return values.

Ques. What is the difference between a structure and a Union?

Ans. All the members of a structure can be accessed simultaneously but union can access only one member at a time Altering the value of a member will not affect the other members of the structure but where it affects the members of a union Lesser memory is needed for a union variable than a structure variable of the same type

Ques. What are static variables and functions?

Ans. The variables and functions that are declared using the keyword Static are considered as Static Variable and Static Functions. The variables declared using Static keyword will have their scope restricted to the function in which they are declared.

Post Question