125 Top C Programming Multiple Choice Questions and Answers

C LANGUAGE Interview Questions with Answers:-

1. Who invented C Language?
Dennis Ritchie in 1972 developed a new language by inheriting the features of both BCPL and B and adding additional features. He named the language as just C.

2. Who invented B Language?
Ken Thomson at AT&T Bell Labs developed a language and named it B. Even the B language was found to have some shortcomings to support the development of both business applications and system software.

3. Who invented BCPL Language?
Basic Combined Programming Language(BCPL) was developed by Martin Richards, Cambridge University.

4. Why C Language?
C is one of the high-level languages. It is a general-purpose language, which means it can be used to write programs of any sort.

5. Define what are the features of C Languages?

In C one can write programs like that of high-level languages as in COBOL, BASIC, FORTRAN, etc. as well as it permits very close interaction with the inner workings of the computer. It is a general-purpose programming language. It is usually called system programming language but equally suited to writing a variety of applications.
It supports various data types It follows the programming style based on fundamental control flow constructions for structured programming Functions may be predefined or user-defined and they may return values of basic types, structures, unions or pointers.

6. Define what are the advantages of c language?

1. Easy to write
2. Rich set of operators and functions that are built–in
3. Support for bitwise operation
4. Flexible use of pointers
5. Direct control over the hardware
6. Ability to access BIOS/DOS routines
7. Interacting using Interrupts
8. Ability to write TSR programs
9. Ability to create.COM files
10. Ability to create library files (.LIB)
11. Ability to write interface programs
12. Incorporating assembly language in C program

7. Define what are the disadvantages of c language?

C is considered difficult to learn Because of its conciseness, the code can be difficult to follow It is not suited to applications that require a lot of report formatting and data file manipulation

8. Define what are the salient features of c languages?
The following are the salient features of C language are :

C is called a middle-level language
C supports a structured design approach
C is extensible
C is rich in data types and operators
C is portable

9. Define what is a header file?
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, a studio.h, math.h, stdlib.h, string.h etc.

10. Define what is character set?
A character set is the set of characters allowed and supported in the
programming language.
Generally, a program is a collection of instructions, which contain
groups of characters. Only a limited set of characters is allowed to
write instructions in the program.

11. Define what is C token?
The smallest individual units of a C program are known as tokens.

12. List the different types of C tokens?

1. Constants
2. Identifiers
3. Keywords
4. Operators
5. Special symbols
6. Strings

13. Define what is a string?
A string is a sequence of characters ending with NUL. It can be treated
as a one–dimensional array of characters terminated by a NUL character.

14. Define what are qualifiers?
Qualifiers or modifiers are identifiers that may precede the scalar data
types (except float) to specify the number of bits used for representing
the respective type of data in memory. The qualifiers in C are short,
long, signed, and unsigned.

15. Define what is a function?
A function is a set of statements to perform a specific task.

16. Define what is constant?
A constant is a value that does not change during the program execution.
A constant used in C does not occupy memory.

17. Define what are the different types of constants?

1. There are five types of constants. They are :
2. Integer constants
3. Floating point constants
4. Character constants
5. String Literals
6. Enumeration Constants

18. Define what is variable?
An identifier is used to identify and store some value. If the value of the identifier is changed during the execution of the program, then the identifier is known as a variable.

19. Define what are the rules for the identifier?

The first character must be an alphabet or underscore (_) Digits may be included in the variable The maximum number of characters in a word are 32 (It may vary depending upon the platform) No other special characters are allowed.

20. Define what are global variables?
Global Variables are those, which are required to be accessed by all the functions defined after their declaration. So, the variables declared before the main {) can be accessed by all the functions, which follow their declaration.

21. Define what is a keyword?
Keywords are those words of C which have the predefined meaning assigned by the C language. They form a part of the database required by the C compiler.

22. Define what are the different types of c instructions?

There are basically three types of instructions in C are :
Type Declaration Instruction
Arithmetic Instruction
Control Instruction

23. Define what is an expression?
An expression is defined as a combination of operands and operators to obtain some computation. Operands represent variables or values and The operator tells is Define what operation to be performed.

24. Define what are the types of data files?
There are two types of data files :

stream-oriented or standard data files
system oriented or low-level data files

25. Why C is called a middle-level language?
C 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. The feature of ALLs is that of enabling us to develop system level programs and the features of HLLs are those of higher degree of readability and machine independence.

26. Define How can variables be characterized?
The variables can be categorized by storage class as well as by data type. The storage class specifies the portion of the program within which the variables are recognized.

27. Give the rules for variable declaration?

The rules for variable declaration in C are given below : A variable name consists of alphabets, digits and the underscore (_) character The length of variable should be kept up to 8 characters through your system may allow up to 40 characters They must begin with an alphabet Some systems also recognize an underscore as the first character White space and commas are not allowed Any reserved word (keyword) cannot be used as a variable name.

28. Define what is the purpose of type declarations?
The type declaration allows creating a synonym for other data types. Its syntax is typedef type identifier; The declaration typedef unsigned long int INTEGER

29. Define what is recursion?
C language a function may call another function. When a function calls itself, it is referred to as recursive call and the process is known as recursion. C provides very good facilities for recursion.

30. Define what is data types?
Data types refer to the classes of data that can be manipulated by C programs. The three fundamental data types supported by C are the character, integer, and real type.

31. Define what are the types of macro formats?
There are two types of macro formats. There are

Simple
Parameterized

32. Define what are the different types of errors?

1. Compile–Time Errors
2. Linker Errors
3. Runtime Errors
4. Logical Errors

33. Define what is meant by errors and debugging?
Errors may be made during program creation even by experienced programmers. Such type of errors is detected by the compiler. Debugging means removing the errors.

34. Define what is the purpose of the main() function?

The function main() invokes other functions within it. It is the first function to be called when the program starts execution. It is the starting function. It returns an int value to the environment that called the program. Recursive call is allowed for main( ) also. It is a user-defined function.

35. Define what is meant by type casting?
It is the explicit type conversion required for a number before carrying out processing or assigning to another variable.

36. Define what are the primitive data types in c?
There are five different kinds of data types in C.

Char
Int
Float
Double
Void

37. Define what is the use of typedef?
The typedef help in easier modification when the programs are ported to another machine. A descriptive new name given to the existing data type may be easier to understand the code.

38. Define what is meant by type specifiers?
Type specifiers decide the amount of memory space occupied by a variable. In the ease of integral types; it also explicitly states the range of values that the object can hold.

39. Define what are the types of type specifiers?
The available data type specifiers are :

1. Short
2. Long
3. Signed
4. Unsigned

40. Define what is masking?
Masking is a process in which a given bit pattern is partly extracted into another bit pattern by means of a logical bitwise operation.

41. Define what is the difference between single character constant and string constant?

A single character constant consists of only one character and it is enclosed within a pair of single quotes. A string constant consists of one or more characters and it is enclosed within a pair of double quotes.

42. Define what is signed and unsigned?
A numeric value may have a positive or negative sign. In the memory, for a variable, one bit is used exclusively to maintain the sign of the data. If we don’t have a sign, the sign bit also may be used for data. If the value is negative, the sign bit is 1, and if it is positive, it will be 0.

43. Define what are the different categories of functions in C?
In C, the functions can be divided into the following categories :

1. Functions with no arguments and no return values
2. Functions having arguments but no return values
3. Functions having arguments and return values also

44. Define what is this pointer?
It is a pointer that points to the current object. This can be used to access the members of the current object with the help of the arrow operator

45. Define what is zero-based addressing?
The array subscripts always start at zero. The compiler makes use of subscript values to identify the elements in the array. Since subscripts
start at 0, it is said that the array uses zero-based addressing.

46. Define what is a loop?
A loop is a process to do a job repeatedly with possibly different data each time. The statements executed each time constitute the loop body, and each pass is called iteration. A condition must be present to terminate the loop.

47. Define what are the types of data types and explain?
There are five basic Data types in C. These are :

void: means nothing i.e. no data involvement in an action
char: to work with all types of characters used in computer
operations
int: to work with an integer type of data in any computational work
float: to work with the real type of data or scientific numbers
in the exponential form
double: to work with double precision of numbers when the
an approximation is very crucial.

48. Define what is friend function?
The function declaration should be preceded by the keyword friend. The function definitions do not use either the keyword or the scope
operator::.
The functions that are declared with the keyword friend as a friend function. Thus, a friend function is an ordinary function or a member of another class.

49. Define what is break statement?
When a break is encountered inside a loop, the loop is terminated and the control passes to the statement following the body of the loop.

50. Define what is the use of getchar() function?
It returns a character just entered from the standard input unit, that is, keyboard. The entered character can be either assigned to a character variable or echoed to the computer screen.

51. Define what are reserved words?
Reserved words are words that are part of the standard C language library. This means that reserved words have special meaning and therefore cannot be used for purposes other than Define what it is originally intended for. Examples of reserved words are int, void, and return.

52. Define what is linked list?
A linked list is composed of nodes that are connected with another. In C programming, linked lists are created using pointers. Using linked lists is one efficient way of utilizing memory for storage.

53. Define what is FIFO?
In C programming, there is a data structure known as a queue. In this structure, data is stored and accessed using FIFO format, or /First-In-First-Out/. A queue represents a line wherein the first data that was stored will be the first one that is accessible as well.

54. Define what are binary trees?
Binary trees are actually an extension of the concept of linked lists. A binary tree has two pointers, a left one and a right one. Each side can further branch to form additional nodes, which each node having two pointers as well.

55. Not all reserved words are written in lowercase. TRUE or FALSE?
FALSE. All reserved words must be written in lowercase; otherwise, the C compiler would interpret this as unidentified and invalid.

56. Define what is the difference between the expression “++a” and “a++”?
In the first expression, the increment would happen first on variable a, and the resulting value will be the one to be used. This is also known as a prefix increment. In the second expression, the current value of variable a would the one to be used in an operation, before the value of itself is incremented. This is also known as postfix increment.

57. Define what would happen to X in this expression: X += 15;

(assuming the value of X is 5)
X +=15 is a short method of writing X = X + 15, so if the initial value
of X is 5, then 5 + 15 = 20.

58. In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?
FALSE. C language is a case sensitive language. Therefore, NAME, name, and Name are three uniquely different variables.

59. Define what is an endless loop?
An endless loop can mean two things. One is that it was designed to loop continuously until the condition within the loop is met, after which a break function would cause the program to step out of the loop. Another idea of an endless loop is when an incorrect loop condition was written, causing the loop to run erroneously forever. Endless loops are
oftentimes referred to as infinite loops.

60. Define what is a program flowchart and Define How does it help in writing a program?
A flowchart provides a visual representation of the step by step procedure towards solving a given problem. Flowcharts are made of symbols, with each symbol in the form of different shapes. Each shape may represent a particular entity within the entire program structure, such as a process, a condition, or even an input/output phase.

61. Define what is wrong with this program statement? void = 10;
The word void is a reserved word in C language. You cannot use reserved words as a user-defined variable.

62. Is this program statement valid? INT = 10.50;
Assuming that INT is a variable of type float, this statement is valid. One may think that INT is a reserved word and must not be used for other purposes. Define, However, recall that reserved words are express in lowercase, so the C compiler will not interpret this as a reserved word.

63. Define what are actual arguments?
When you create and use functions that need to perform an action on some given values, you need to pass these given values to that function. The values that are being passed into the called function are referred to as actual arguments.

64. Define what is a newline escape sequence?
A newline escape sequence is represented by the character. This is used to insert a new line when displaying data in the output screen. More spaces can be added by inserting more n characters. For example, it would insert two spaces. A newline escape sequence can be placed before the actual output expression or after.

65. Define what is output redirection?
It is the process of transferring data to an alternative output source other than the display screen. Output redirection allows a program to have its output saved to a file. For example, if you have a program named COMPUTE, typing this on the command line as COMPUTE >DATA can accept input from the user, perform certain computations, then have the output redirected to a file named DATA, instead of define Howing it on the screen.

66. Define what are run-time errors?
These are errors that occur while the program is being executed. One common instance wherein run-time errors can happen is when you are trying to divide a number by zero. When run-time errors occur, program execution will pause, define Howling which program line caused the error.

67. Define what is the difference between functions abs() and fabs()?
These 2 functions basically perform the same action, which is to get the absolute value of the given value. Abs() is used for integer values, while fabs() is used for floating type numbers. Also, the prototype for abs() is under <stdlib.h>, while fabs() is under <math.h>.

68. Define what are formal parameters?
In using functions in a C program, formal parameters contain the values that were passed by the calling function. The values are substituted in these formal parameters and used to Define whatever operations as indicated within the main body of the called function.

69. Define what are control structures?
Control structures take charge at which instructions are to be performed in a program. This means that program flow may not necessarily move from one statement to the next one, but rather some alternative portions may need to be pass into or bypassed from, depending on the outcome of the conditional statements.

70. Write a simple code fragment that will check if a number is positive or negative.
[c]
If (num&gt;=0)
printf(&quot;number is positive&quot;);
else
printf (&quot;number is negative&quot;);
[/c]

71. When is a “switch” statement preferable over an “if” statement?
The switch statement is best used when dealing with selections based on a single variable or expression. Define, However, switch statements can only evaluate integer and character data types.

72. Define what are global variables and Define How do you declare them?
Global variables are variables that can be accessed and manipulated anywhere in the program. To make a variable global, place the variable declaration on the upper portion of the program, just after the preprocessor directives section.

73. Define what are enumerated types?
Enumerated types allow the programmer to use more meaningful words as values to a variable. Each item in the enumerated type variable is actually associated with a numeric code. For example, one can create an enumerated type variable named DAYS whose values are Monday, Tuesday… Sunday.

74. Define what does the function to upper() do?
It is used to convert any letter to its upper case mode. Tupper() function prototype is declared in <ctype.h>. Note that this function will only convert a single character and not an entire string.

75. Is it possible to have a function as a parameter in another function?
Yes, that is allowed in C programming. You just need to include the entire function prototype into the parameter field of the other function where it is to be used.

76. Define what are multidimensional arrays?
Multidimensional arrays are capable of storing data in a two or more dimensional structure. For example, you can use a 2-dimensional array to store the current position of pieces in a chess game, or position of players in a tic-tac-toe program.

77. Which function in C can be used to append a string to another string?
The strcat function. It takes two parameters, the source string, and the string value to be appended to the source string.

78. Define what is the difference between functions get() and getche()?
Both functions will accept a character input value from the user. When using getch(), the key that was pressed will not appear on the screen and is automatically captured and assigned to a variable. When using the(), the key that was pressed by the user will appear on the screen, while at the same time being assigned to a variable.

79. Do these two program statements perform the same output?

1) scanf(“%c”, &letter); 2) letter=getchar() Yes, they both do the exact same thing, which is to accept the next key
pressed by the user and assign it to the variable named letter.

80. Define what are structure types in C?
Structure types are primarily used to store records. A record is made up of related fields. This makes it easier to organize a group of related data.

81. Define what do the characters “r” and “w” mean when writing programs that will make use of files?
“r” means “read” and will open a file as input wherein data is to be retrieved. “w” means “write”, and will open a file for output. Previous data that was stored on that file will be erased.

82. Define what is the difference between text files and binary files?
Text files contain data that can easily be understood by humans. It includes letters, numbers and other characters. On the other hand, binary files contain 1s and 0s that only computers can interpret.

83. is it possible to create your own header files?
Yes, it is possible to create a customized header file. Just include in it the function prototypes that you want to use in your program, and use the #include directive followed by the name of your header file.

84. Define what is dynamic data structure?
Dynamic data structure provides a means for storing data more efficiently into memory. Using dynamic memory allocation, your program will access memory spaces as needed. This is in contrast to a static data structure, wherein the programmer has to indicate a fixed number of memory space to be used in the program.

85. Define what are the different data types in C?
The basic data types are int, char, and float. Int is used to declare variables that will be storing integer values. Float is used to store real numbers. Char can store individual character values.

86. Define what is the general form of a C program?
A C program begins with the preprocessor directives, in which the programmer would specify which header file and Define what constants (if any) to be used. This is followed by the main function heading. Within the main function lies the variable declaration and program statement.

87. Define what is the advantage of a random access file?
If the amount of data stored in a file is fairly large, the use of random access will allow you to search through it quicker. If it had been a sequential access file, you would have to go through one record at a time until you reach the target data. A random access file lets you jump directly to the target address where data is located.

88. In a switch statement, Define what will happen if a break statement is omitted?
If a break statement was not placed at the end of a particular case portion? It will move on to the next case portion, possibly causing incorrect output.

89. Describe Define How arrays can be passed to a user defined function?
One thing to note is that you cannot pass the entire array to a function. Instead, you pass to it a pointer that will point to the array first element in memory. To do this, you indicate the name of the array without the brackets.

90. Define what are pointers?
Pointers point to specific areas in the memory. Pointers contain the address of a variable, which in turn may contain a value or even an address to another memory.

91. Can you pass an entire structure to functions?
Yes, it is possible to pass an entire structure to a function in a call by method style. Define, However, some programmers prefer declaring the structure globally, then pass a variable of that structure type to a function. This method helps maintain consistency and uniformity in terms of the argument type.

92. Define what is gets() function?
The gets() function allows a 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 to a string variable. Note that the enter key is not included in the variable, but instead, a null terminator is placed after the last character.

93. The % symbol has a special use in a print statement. Define How would you place this character as part of the output on the screen?
You can do this by using %% in the printf statement. For example, you can write printf(“10%%”) to have the output appear as 10% on the screen.

94. Define How do you search for data in a data file using the random access method?
Use the fseek() function to perform random access input/output on a file. After the file was opened by the fopen() function, the fseek would require three parameters to work: a file pointer to the file, the number of bytes to search, and the point of origin in the file.

95. Are comments included during the compilation stage and placed in the EXE file as well?
No, comments that were encountered by the compiler are disregarded. Comments are mostly for the guidance of the programmer only and do not have any other significant use in the program functionality.

96. Is there a built-in function in C that can be used for sorting data? Yes, use the qsort() function. It is also possible to create user-defined functions for sortings, such as those based on the balloon sort and a bubble sort algorithm.

97. Define what are the advantages and disadvantages of a heap?
Storing data on the heap is slower than it would take when using the stack. Define, However, the main advantage of using the heap is its flexibility. That’s because the memory in this structure can be allocated and remove in any particular order. Slowness in the heap can be compensated if an algorithm was well designed and implemented.

98. Define How do you convert strings to numbers in C?
You can write your own functions to do string to number conversions, or instead use C’s built-in functions. You can use to convert to a floating point value, atoi to convert to an integer value, and atol to convert to a long integer value.

99. Create a simple code fragment that will swap the values of two variables num1 and num2.
[c]
int temp;
temp = num1;
num1 = num2;
num2 = temp;
[/c]

100. Define what is the use of a semicolon (;) at the end of every program statement?
It has to do with the parsing process and compilation of the code. A semicolon acts as a delimiter so that the compiler knows where each statement ends and can proceed to divide the statement into smaller
elements for syntax checking.