C Interview Questions and Answers

In this collection, I have chosen 60+ mostly asked C interview questions and answers, which will surely help you to get success in interviews.

 

1. What is C language?

C is a high-level programming language developed in the early 1970s for use in operating systems and software development. It is a versatile language that is used in a wide range of industries and applications. C is a mid-level language, meaning it combines features from both low-level and high-level languages. It is often used to develop complex software applications, while low-level programming languages such as Assembly are used to program basic computer functions.

 

2. What are the features of C language?

C language has the following features:
– It is a structured language
– It is a middle-level language
– It supports low-level programming
– It is portable, efficient and powerful language.
– It is a compiled language
– It supports data types
– It supports pointers
– It supports dynamic memory allocation
– It provides a large collection of library functions.

C interview questions and answers

3. What are the different data types in C language?

The data types in C language are the following:
– int: an integer type used to store whole numbers
– float: a floating point type used to store numbers with decimal points
– double: a double precision floating point type used to store large numbers with decimal points
– char: a character type used to store character values
– void: a special type used to indicate the absence of a value

 

4. What is the difference between Compiler and Interpreter?
A compiler translates all source code into object code before execution, whereas an interpreter reads and executes source code line by line.

 

5. What is the use of a header file in C language?
A header file in C language is used to store function declarations, macros, and other information necessary for the program. It is included at the beginning of the program to enable the compiler to recognize the functions and other information.

 

6. What are the different types of loops in C language?
There are three different types of loops in C language are:
– for loop
– while loop
– do-while loop

 

7. What is the use of break and continue statement?
Break and continue are used for controlling the flow of loops in a program. Break ends the loop, whereas continue proceeds to next iteration.

 

8. What is a pointer in C language?
A variable that contains the address of another variable is known as a pointer. It is used to point to a memory location, which can be used to store or access data.

 

9. What is an array in C language?
An array is a collection of data items of the same type that are stored in contiguous memory locations. It can store multiple values of the same type in a single variable.

 

10. What are the various control statements used in C language?
The various control statements used in C language are if-else, switch-case, for, while, and do-while.

 

11. What is difference between call by value and call by reference?
In call by value, the value of the argument is passed to the function, whereas in call by reference, the address of the argument is passed to the function.

 

12. What is difference between scanf() and gets() function?
gets() function can accept multiple word strings( with space characters) while scanf() function can accept only a single word string(without space character).

 

13. What is the difference between gets and puts in C?
The gets() and puts() functions are both used to handle input and output from the console in C programming. The difference between them is that gets() is used to retrieve user input, where as puts() is used to output text to the console. Gets() reads a line of user input including spaces, while puts() just displays text on the screen.

 

14. What is the difference between scanf and sprintf?
Scanf() is used to read formatted input from the keyboard (or another source) while sprintf() is used to write formatted output to a character array.

 

15. What is %d in C?
The %d is format specifier, that is used to print an integer value.

 

16. What is %I in C?
%I is a format specifier for an integer data type in the C programming language. This specifier is used to read or print a value of type int, short, long, long long, or unsigned int.

 

17. What is ++ i in C?
++i is a pre-increment operator in C. It is used to increment the current value of a variable by one.

 

18. What are the 7 types of operators?
1. Arithmetic operators (e.g. +, -, *, /, %, etc.)
2. Comparisons operators (e.g. ==, !=, <, >, <=, >=, etc.)
3. Logical operators (e.g. &&, ||, !, etc.)
4. Assignment operators (e.g. =, +=, -=, *=, etc.)
5. Bitwise operators (e.g. &, |, ^, ~, <<, >>, etc.)
6. Ternary operator (?:)
7. Misc Operators (e.g. sizeof, ., ->, ::, etc.)

 

19. What is a structure in C language?
A structure is a user-defined data type that can hold many values of various data types in a single variable.

 

20. What is a union in C language?
A union is a user-defined data type that can store multiple values of different data types in a single variable, but all the values share the same memory location.

 

21. What is the difference between a structure and a union in C language?
The difference between a structure and a union in C language is that a structure can store multiple values of different data types in separate memory locations, whereas a union stores multiple values of different data types in the same memory location.

 

22. What is a preprocessor directive in C language?
A preprocessor directive is a special instruction to the compiler that tells it how to process the source code before compiling it.

 

23. What is an enumeration in C language?
An enumeration is a user-defined data type that can store a set of named values as a list.

 

24. What are macros in C language?
Macros are special instructions to the compiler that tell it to replace a certain piece of code with another.

 

25. What is a file in C language?
A file is a collection of related data stored on a storage medium. It can be used to store data permanently or temporarily.

 

26. What is the difference between a file and a stream in C language?
A file is a collection of related data stored on a storage medium. while a stream is a regularly flow of data from one location to another.

 

27. What is a function in C language?
A function in C language is a block of code that performs a specific task and returns a result when it is invoked or called. It can be called multiple times from different parts of the program to perform the same task. It can also accept arguments to process the data and return a result.

 

28. What is the main difference between a function and a procedure in C language?
The main difference between a function and a procedure in C language is that a function returns a value, whereas a procedure does not.

 

29. What is the difference between an array and a pointer?
The main difference between an array and a pointer is that an array is a collection of related data items of the same data type stored in contiguous memory locations, while a pointer is a variable that stores the address of another variable.

 

30. What is a Linked List in C language?
A Linked List is a data structure that stores a collection of data items in a linear order. It consists of nodes that are connected together using pointers.

 

31. What is the purpose of the malloc() and calloc() functions in C language?
The malloc() and calloc() functions are used to dynamically allocate memory for variables at runtime. They allocate a block of memory and return the address of the allocated memory.

 

32. What is typecasting in C language?
Data type conversion, from one data type to another data type is called typecasting. It is done by using typecast operators such as (int), (float), and (char).

 

33. What is the difference between pre-increment and post-increment operators?
The difference between pre-increment and post-increment operators is that pre-increment operator increments the value of a variable before it is used, while post-increment operator increments the value of a variable after it is used.

 

34. What is the difference between a global variable and a local variable?
The difference between a global variable and a local variable is that a global variable is declared outside a function and can be accessed by all functions, while a local variable is declared inside a function and can only be accessed by that function.

 

35. What is the main() function in C language?
The main() function is the entry point for a program written in the C language. It is the first function that is called when a program starts running. It is used to initiate program execution and typically contains calls to other functions in the program. The main() function is also responsible for handling the program’s command line arguments.

 

36. What is the purpose of the sizeof operator?
The sizeof operator is used to determine the size of a data type or a variable in bytes.

 

37. What is the difference between an argument and a parameter?
The difference between an argument and a parameter is that an argument is a value passed to a function, while a parameter is a variable in the definition of a function that receives the value passed to the function.

 

38. What is the use of the #define preprocessor directive?
The #define preprocessor directive is used to define constants and macros in a program. It is used to reduce the amount of code needed to be written, as the constant or macro can be used in place of a long expression.

 

39. What are the storage classes in C?
The storage classes in C are:
• Auto
• Extern
• Register
• Static

 

40. What is #define in C?
The #define statement is used to define a constant value in C. This statement is used to assign a name to a value and is used for making the code more readable and easier to maintain.

 

41. What is the purpose of the ‘volatile’ keyword in C?
The volatile keyword is used to inform the compiler that the value of a variable can be changed by an external source or an event outside the scope of the program. This is useful when working with hardware registers or embedded systems.

 

42. What is the difference between a string and an array of characters?
A string is a sequence of characters terminated by a null character (‘\0’), while an array of characters is an array of individual characters. A string is easier to work with than an array of characters, since the length of the string is stored in the first byte of the array.

 

43. What is the difference between a for loop and a while loop in C?
A for loop is a loop that is executed a specific number of times, while a while loop is a loop that is executed until a certain condition is met. A for loop is generally more efficient than a while loop, since the loop termination condition is checked only once at the start of the loop.

 

44. What is the difference between malloc() and calloc() in C?
Malloc() is a function used to allocate memory for a single object, while calloc() is a function used to allocate memory for an array of objects. Malloc() allocates memory without initializing it, while calloc() allocates and initializes the memory to zero.

 

45. What is the purpose of the ‘goto’ statement in C?
The goto statement is used to transfer control to a specific location within the program. It is generally considered bad practice to use goto statements, since they can lead to code that is difficult to understand and maintain.

 

46. What is the purpose of the ‘switch’ statement in C?
The switch statement is used to execute one of several blocks of code based on the value of an expression. It is useful for replacing multiple if-else statements with a single statement.

 

47. What is the purpose of the ‘enum’ keyword in C?
The enum keyword is used to define an enumeration, which is a set of named integer constants. Enums are useful for defining a set of related constants and making them easier to reference in code.

 

48. What is the difference between a structure and a union in C?
A structure is a collection of related data items that are stored together, while a union is a collection of related data items that are stored in one memory location. Structures are useful for storing different types of data that have different sizes, while unions are useful for storing data items that have different types but occupy the same amount of space.

 

49. What is the purpose of the ‘typedef’ keyword in C?
The typedef keyword is used to create an alias for an existing data type. It is useful for making complex data types easier to use and for creating user-defined data types.

 

50. What is the purpose of the ‘sizeof’ operator in C?
The purpose of the sizeof operator in C is to determine the amount of memory, in bytes, that is allocated to a given variable or data type.

 

51. What is the difference between a declaration and a definition in C?
A declaration is a statement that announces the existence of a variable or function, while a definition is a statement that reserves memory for a variable or function. A declaration must precede a definition in C.

 

52. What is the difference between a static and a global variable in C?
A static variable is a local variable that has static storage duration, while a global variable is a variable that is accessible to all parts of the program. Static variables are store in the stack whereas global variables are stored in the program’s data segment.

 

53. What is the purpose of the ‘register’ keyword in C?
The register keyword is used to tell the compiler to store a variable in a processor register instead of in memory. This can improve the performance of a program by reducing the number of memory accesses required.

 

54. What is a String in C?
A string in C is a data type that is used to represent text as an array of characters. It is a combination of characters that are enclosed within a single or double quotation marks. Some examples of the strings are the following:-
“Code Revise”, “I love to Code!” and “123456789”.

 

55. What is difference between main and void main?
The difference between main and void main is that main is the starting point for an executable program and must return an int value, whereas void main does not return a value.

 

56. What is clrscr() in C?
clrscr() is a library function in C programming language, which is used to clear the console screen. It is defined in the header file “conio.h”.

 

57. What is #include and #define in C?
#include is a preprocessor directive used to include C-language library functions, header files and data files in the source code.
#define is a preprocessor directive used to define symbolic constants and macro functions.

 

58. What is the difference between declaration and definition and initialization in C?
Declaration: A declaration tells the compiler about a variable and its type, but does not define the storage for it.
Definition: The definition of a variable is when storage is allocated for it in memory.
Initialization: Initialization of a variable means to assign a specific value to it.

 

59. What are different types of tokens in C programming?
Identifiers, Constants, Strings, Operators, and Special Symbols are the different kinds of tokens in the C programming language.

 

60. What is the difference between pre-processor directives and statement in C?
Pre-processor directives control the compilation process. Statement is a normal execution statement. Pre-processor directives are recognized by the # symbol whereas statements are recognized by a semi-colon.

 

 

Other Important link:-

C++ Interview Questions and Answers

 

 

 

 

Scroll to Top