C Interview Questions With Answer


1. What are the advantages of c language?

There are some major advantages of c language given below.

  • Easy to write
  • − Ability to write TSR programs
  • − Rich set of operators and functions that are built–in
  • Ability to create .COM files
  • − Support for bit–wise operation
  • − Ability to create library files (.LIB)
  • Flexible use of pointers

2. What is a header file?

In programming languages, header files provide the definitions and declarations for the library functions. Thus, each header file contains the library functions along with the necessary definitions and declarations.

For example:

  • − stdio.h
  • − math.h,
  • − stdlib.h,
  • − string.h etc.

3. List the different types of C tokens?

  • − Constants
  • − Identifiers
  • − Keywords
  • − Operators
  • − Special symbols
  • − Strings

4. What is a constant? What are the different types of constants?

A constant is a value and constant value never change after the declaration . A constant used in C does not occupy memory. There are five types of constants. They are:

  • Integer constants
  • − Floating point constants
  • Character constants
  • − String literals
  • Enumeration constants

5. What is the purpose of main() function?

  • —The function main() invokes other functions within it. This function is auto called when the program starts execution.
  • − It is the starting function.
  • − It returns an int value to the environment that called the program.
  • − The recursive call is allowed for main( ) also.
  • − It is a user-defined function.

6. Why C is called a middle level language?

C programming language combines the features of both Assembly Level Languages (Low-Level Languages) and Higher Level Languages. For this reason, C is referred to as a Middle-Level Language.

7. What is the difference between Call by Value and Call by Reference?

When using Call by Value, you are sending the value of a variable as a parameter to a function, whereas Call by Reference sends the address of the variable. Also, under Call by Value, the value of the parameter is not affected by whatever operation that takes place, while in the case of Call by Reference, values can be affected by the process within the function.

8. What is the loop?

Loop is the process for the repeat any task until a certain condition is reached. In C-Prog suppose if you want to print any message for 10 times without loop then your have to print msg for 10 times. This problem may be fixed within 2 & 3 lines of code by the loop.

There are three types of loops support in C.

  • − while loop
  • − for loop
  • − do while loop

9.. What is for loop?

For loop used for executes for a group of statement repetition until condition not reached. First, initialize then check print statement and after increment/decrement then check the condition and again print statement.

10. What is do while loop?

The do while loop is exactly same as while loop the difference is that statement execute first before check condition always at least one condition will execute if the condition is false.

11. What is while loop in c?

While loop used when we don’t know exactly how many times the loop will run.

12 What is array?

Arrays are one types of data structure where we store and retrieve data. We used the array for sequential & same data type store value in the arrays.

13. What is pointers in c?

A Pointer is a variable that hold’s the address of another variable.

14. What are the advantages of a pointer in the C programming language?

  • − Pointer increases the processing speed of application.
  • − Pointer reduce the length of program
  • − Pointer helps in run time memory allocation that is called DMA(Dynamic memory allocation).
  • − Pointers obviously give us the ability to implement complex data structures like linked lists, trees, etc.
  • − Pointers also save the memory.

15. What is generic pointer in C?

In C void* acts as a generic pointer. When other pointer types are assigned to a generic pointer, conversions are applied automatically (implicit conversion).

16. What is a function?

A function is a block of code that designed to perform a particular task. When we create a function then we can call it for many times the actual advantage is to create one time and call it many times.

17. What do the ‘c’ and ‘v’ in argc and argv stand for?

In c programming, argc(argument count) is used for the number of command line argument the program is invoked with and v in argv(argument vector) is a pointer to an array of a character string that contains the arguments.

18. When is the void keyword used in a function?

When you declaring a function, you will have to decide whether that function would be returning a value or not. If you don't want to return a value from the function then you can set their void.

19. What is a user-defined function?

A function that is created by the user is called the user defined function.

20. What is memory management?

Memory management is a process that helps you for creating the memory size for data. In C we can create a dynamic memory allocation by malloc, calloc function. The memory size can increase & decrease of the requested memory.

21. What is keyword & identifer?

The keyword is a predefined word that is reserved words. Keywords have a special meaning that's already provided by c-developers.
Identifiers refer to the name of given such as variable, function name etc. It is created by user.

22. What is the use of a ‘\0′ character?

It is referred to as a terminating null character and is used primarily to show the end of a string value.

23. What is the modulus operator?

The modulus operator gives the outputs is a remainder of a division. It makes use of the percentage (%) symbol. For example 5 % 3 = 2, meaning when you divide 5 by 3, the remainder is 2.

24. What is the difference between the = symbol and == symbol?

This = symbol is used in mathematical operations. It is used for assign a value to a given variable. On the other hand, the = = symbol, also known as equal to or equivalent to, is a relational operator that is used to compare two values

25. What is Struture?

Structure in c language is custom data type where a user can store different type of data value. It is just like of class and template in C++. In C we can access the structure data by creating the structure member just like the object in c here process is different but the concept is same as like object.

26. What is file handling?

File handling in C where the user can store data permanently, without file handling we can not access the data in future. We store the data in a file format in C.

27. What is gets() function?

The gets() function used for full line data entry from the user. When the user presses the enter key to end the input, the entire line of characters is stored in a string variable.

28. What is static memory allocation?

Compiler allocates memory space for a declared variable. When we use the address of operator, the reserved address is obtained and this address is assigned to a pointer variable. This way of assigning the pointer value to a pointer variable at compilation time is known as static memory allocation.

29. What is dynamic memory allocation?

In C programming, a dynamic memory allocation uses functions such as malloc() or calloc() to get memory dynamically. If these functions are used to get memory dynamically and the values returned by these function are assigned to pointer variables, such a way of allocating memory at runtime is known as dynamic memory allocation.

30. What are compound statements?

Compound statements are used of two or more program statements that are executed together.

31. What is switch statement?

When we want to test multiple conditions same time then we can use a switch statement.

32.. What is Union?

Union in c language is custom data type where a user can store different type of data value. It is just like of structure in c but the difference is that it use the memory of the largest element of data. Union also uses less memory use compared than structure.

33. What is recursion?

Recursion is a function that calls itself. It helps in solve to the complex level of the program such tree, graph, binary search etc.

34. What is size of void pointer?

A size of any type of pointer in c is independent of the data type which is pointer is pointing i.e. the size of all type of pointer (near) in C is two byte either it is char pointer, double pointer, function pointer or a null pointer. Void pointer is not an exception to this rule and size of a void pointer is also two byte.

35. What is a const pointer?

A const pointer that means a pointer have an address. so if you declare a pointer then within a function then you can't change the address of that pointer.

36. How is calloc () different from malloc ()?

The main difference between the two is that calloc() when it is used to assign a block of memory, the allocated contents are initialized to 0. Malloc (), on the other hand, does not initialise the memory block it assigns. The memory just has random values left over from the previous usage.