Here we have mentioned most frequently asked C Interview Questions and Answers specially for freshers and experienced.


 

1. How do you construct an increment statement or decrement statement in C?

Ans:

There are actually two ways you can do this. One is to use the increment operator ++ and decrement operator –. For example, the statement “x++” means to increment the value of x by 1. Likewise, the statement “x –” means to decrement the value of x by Another way of writing increment statements is to use the conventional + plus sign or – minus sign. In the case of “x++”, another way to write it is “x = x +1”.

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

Ans:

When using Call by Value, you are sending the value of a variable as parameter to a function, whereas Call by Reference sends the address of the variable. Also, under Call by Value, the value in 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.

3. Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

Ans:

Placing comment symbols /* */ around a code, also referred to as “commenting out”, is a way of isolating some codes that you think maybe causing errors in the program, without deleting the code. The idea is that if the code is in fact correct, you simply remove the comment symbols and continue on. It also saves you time and effort on having to retype the codes if you have deleted it in the first place.

4. What is the equivalent code of the following statement in WHILE LOOP format?

for (a=1; a<=100; a++)
printf ("%d\n", a * a);

Ans:

a=1;
while (a<=100) {
printf ("%d\n", a * a);
a++;
}

5. What is a stack?

Ans:

A stack is one form of a data structure. Data is stored in stacks using the FILO (First In Last Out) approach. At any particular instance, only the top of the stack is accessible, which means that in order to retrieve data that is stored inside the stack, those on the upper part should be extracted first. Storing data in a stack is also referred to as a PUSH, while data retrieval is referred to as a POP.

6. What is a sequential access file?

Ans:

When writing programs that will store and retrieve data in a file, it is possible to designate that file into different forms. A sequential access file is such that data are saved in sequential order: one data is placed into the file after another. To access a particular data within the sequential access file, data has to be read one data at a time, until the right one is reached.

7. What is variable initialization and why is it important?

Ans:

This refers to the process wherein a variable is assigned an initial value before it is used in the program. Without initialization, a variable would have an unknown value, which can lead to unpredictable outputs when used in computations or other operations.

8. What is spaghetti programming?

Ans:

Spaghetti programming refers to codes that tend to get tangled and overlapped throughout the program. This unstructured approach to coding is usually attributed to lack of experience on the part of the programmer. Spaghetti programing makes a program complex and analyzing the codes difficult, and so must be avoided as much as possible.

9. Differentiate Source Codes from Object Codes

Ans:

Source codes are codes that were written by the programmer. It is made up of the commands and other English-like keywords that are supposed to instruct the computer what to do. However, computers would not be able to understand source codes. Therefore, source codes are compiled using a compiler. The resulting outputs are object codes, which are in a format that can be understood by the computer processor. In C programming, source codes are saved with the file extension .C, while object codes are saved with the file extension .OBJ

10. In C programming, how do you insert quote characters (‘ and “) into the output screen?

Ans:

This is a common problem for beginners because quotes are normally part of a printf statement. To insert the quote character as part of the output, use the format specifiers \’ (for single quote), and \” (for double quote).



 

11. What is the use of a ‘\0’ character?

Ans:

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

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

Ans:

The = symbol is often used in mathematical operations. It is used to 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.

13. What is the modulus operator?

Ans:

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

14. What is a nested loop?

Ans:

A nested loop is a loop that runs within another loop. Put it in another sense, you have an inner loop that is inside an outer loop. In this scenario, the inner loop is performed a number of times as specified by the outer loop. For each turn on the outer loop, the inner loop is first performed.

15. Which of the following operators is incorrect and why? ( >=, <=, <>, ==)

Ans:

<> is incorrect. While this operator is correctly interpreted as “not equal to” in writing conditional statements, it is not the proper operator to be used in C programming. Instead, the operator != must be used to indicate “not equal to” condition.

16. Compare and contrast compilers from interpreters.

Ans:

Compilers and interpreters often deal with how program codes are executed. Interpreters execute program codes one line at a time, while compilers take the program as a whole and convert it into object code, before executing it. The key difference here is that in the case of interpreters, a program may encounter syntax errors in the middle of execution, and will stop from there. On the other hand, compilers check the syntax of the entire program and will only proceed to execution when no syntax errors are found.

17. How do you declare a variable that will hold string values?

Ans:

The char keyword can only hold 1 character value at a time. By creating an array of characters, you can store string values in it. Example: “char MyName[50]; ” declares a string variable named MyName that can hold a maximum of 50 characters.

18. Can the curly brackets { } be used to enclose a single line of code?

Ans:

While curly brackets are mainly used to group several lines of codes, it will still work without error if you used it for a single line. Some programmers prefer this method as a way of organizing codes to make it look clearer, especially in conditional statements.

19. What are header files and what are its uses in C programming?

Ans:

Header files are also known as library files. They contain two essential things: the definitions and prototypes of functions being used in a program. Simply put, commands that you use in C programming are actually functions that are defined from within each header files. Each header file contains a set of functions. For example: stdio.h is a header file that contains definition and prototypes of commands like printf and scanf.

20. What is syntax error?

Ans:

Syntax errors are associated with mistakes in the use of a programming language. It maybe a command that was misspelled or a command that must was entered in lowercase mode but was instead entered with an upper case character. A misplaced symbol, or lack of symbol, somewhere within a line of code can also lead to syntax error.




 

21. What are variables and it what way is it different from constants?

Ans:

Variables and constants may at first look similar in a sense that both are identifiers made up of one character or more characters (letters, numbers and a few allowable symbols). Both will also hold a particular value. Values held by a variable can be altered throughout the program, and can be used in most operations and computations. Constants are given values at one time only, placed at the beginning of a program. This value is not altered in the program. For example, you can assigned a constant named PI and give it a value 3.1415 . You can then use it as PI in the program, instead of having to write 3.1415 each time you need it.

22. How do you access the values within an array?

Ans:

Arrays contain a number of elements, depending on the size you gave it during variable declaration. Each element is assigned a number from 0 to number of elements-1. To assign or retrieve the value of a particular element, refer to the element number. For example: if you have a declaration that says “intscores[5];”, then you have 5 accessible elements, namely: scores[0], scores[1], scores[2], scores[3] and scores[4].

23. Can I use “int” data type to store the value 32768? Why?

Ans:

No. “int” data type is capable of storing values from -32768 to 32767. To store 32768, you can use “long int” instead. You can also use “unsigned int”, assuming you don’t intend to store negative values.

24. Can two or more operators such as \n and \t be combined in a single line of program code?

Ans:

Yes, it’s perfectly valid to combine operators, especially if the need arises. For example: you can have a code like ” printf (“Hello\n\n\’World\’”) ” to output the text “Hello” on the first line and “World” enclosed in single quotes to appear on the next two lines.

25. Why is it that not all header files are declared in every C program?

Ans:

The choice of declaring a header file at the top of each C program would depend on what commands/functions you will be using in that program. Since each header file contains different function definitions and prototype, you would be using only those header files that would contain the functions you will need. Declaring all header files in every program would only increase the overall file size and load of the program, and is not considered a good programming style.

26. When is the “void” keyword used in a function?

Ans:

When declaring functions, you will decide whether that function would be returning a value or not. If that function will not return a value, such as when the purpose of a function is to display some outputs on the screen, then “void” is to be placed at the leftmost part of the function header. When a return value is expected after the function execution, the data type of the return value is placed instead of “void”.

27. What are compound statements?

Ans:

Compound statements are made up of two or more program statements that are executed together. This usually occurs while handling conditions wherein a series of statements are executed when a TRUE or FALSE is evaluated. Compound statements can also be executed within a loop. Curly brackets { } are placed before and after compound statements.

28. What is the significance of an algorithm to C programming?

Ans:

Before a program can be written, an algorithm has to be created first. An algorithm provides a step by step procedure on how a solution can be derived. It also acts as a blueprint on how a program will start and end, including what process and computations are involved.

29. What is the advantage of an array over individual variables?

Ans:

When storing multiple related data, it is a good idea to use arrays. This is because arrays are named using only 1 word followed by an element number. For example: to store the 10 test results of 1 student, one can use 10 different variable names (grade1, grade2, grade3… grade10). With arrays, only 1 name is used, the rest are accessible through the index name (grade[0], grade[1], grade[2]… grade[9]).

30. Write a loop statement that will show the following output:

1
12
123
1234
12345

Ans:

for (a=1; a<=5; i++) {
for (b=1; b<=a; b++)
printf("%d",b);
printf("\n");
}

 

31. What is wrong in this statement? scanf(“%d”,whatnumber);

Ans:

An ampersand & symbol must be placed before the variable name whatnumber. Placing & means whatever integer value is entered by the user is stored at the “address” of the variable name. This is a common mistake for programmers, often leading to logical errors.

32. How do you generate random numbers in C?

Ans:

Random numbers are generated in C using the rand() command. For example: anyNum = rand() will generate any integer number beginning from 0, assuming that anyNum is a variable of type integer.

33. What could possibly be the problem if a valid function name such as tolower() is being reported by the C compiler as undefined?

Ans:

The most probable reason behind this error is that the header file for that function was not indicated at the top of the program. Header files contain the definition and prototype for functions and commands used in a C program. In the case of “tolower()”, the code “#include ” must be present at the beginning of the program.

34. What are comments and how do you insert it in a C program?

Ans:

Comments are a great way to put some remarks or description in a program. It can serves as a reminder on what the program is all about, or a description on why a certain code or function was placed there in the first place. Comments begin with /* and ended by */ characters. Comments can be a single line, or can even span several lines. It can be placed anywhere in the program.

35. What is debugging?

Ans:

Debugging is the process of identifying errors within a program. During program compilation, errors that are found will stop the program from executing completely. At this state, the programmer would look into the possible portions where the error occurred. Debugging ensures the removal of errors, and plays an important role in ensuring that the expected program output is met.

36. What does the && operator do in a program code?

Ans:

The && is also referred to as AND operator. When using this operator, all conditions specified must be TRUE before the next action can be performed. If you have 10 conditions and all but 1 fails to evaluate as TRUE, the entire condition statement is already evaluated as FALSE.

37. In C programming, what command or code can be used to determine if a number of odd or even?

Ans:

There is no single command or function in C that can check if a number is odd or even. However, this can be accomplished by dividing that number by 2, then checking the remainder. If the remainder is 0, then that number is even, otherwise, it is odd. You can write it in code as:

if (num % 2 == 0)
printf("EVEN");
else
printf("ODD");

38. What does the format %10.2 mean when included in a printf statement?

Ans:

This format is used for two things: to set the number of spaces allotted for the output number and to set the number of decimal places. The number before the decimal point is for the allotted space, in this case it would allot 10 spaces for the output number. If the number of space occupied by the output number is less than 10, addition space characters will be inserted before the actual output number. The number after the decimal point sets the number of decimal places, in this case, it’s 2 decimal spaces.

39. What are logical errors and how does it differ from syntax errors?

Ans:

Program that contains logical errors tend to pass the compilation process, but the resulting output may not be the expected one. This happens when a wrong formula was inserted into the code, or a wrong sequence of commands was performed. Syntax errors, on the other hand, deal with incorrect commands that are misspelled or not recognized by the compiler.

40. What are the different types of control structures in programming?

Ans:

There are 3 main control structures in programming: Sequence, Selection and Repetition. Sequential control follows a top to bottom flow in executing a program, such that step 1 is first perform, followed by step 2, all the way until the last step is performed. Selection deals with conditional statements, which mean codes are executed depending on the evaluation of conditions as being TRUE or FALSE. This also means that not all codes may be executed, and there are alternative flows within. Repetitions are also known as loop structures, and will repeat one or two program statements set by a counter.



 

41. What is || operator and how does it function in a program?

Ans:

The || is also known as the OR operator in C programming. When using || to evaluate logical conditions, any condition that evaluates to TRUE will render the entire condition statement as TRUE.

42. Can the “if” function be used in comparing strings?

Ans:

No. “if” command can only be used to compare numerical values and single character values. For comparing string values, there is another function called strcmp that deals specifically with strings.

43. What are preprocessor directives?

Ans:

Preprocessor directives are placed at the beginning of every C program. This is where library files are specified, which would depend on what functions are to be used in the program. Another use of preprocessor directives is the declaration of constants.Preprocessor directives begin with the # symbol.

44. What will be the outcome of the following conditional statement if the value of variable s is 10?

Ans:

s >=10 && s < 25 && s!=12
The outcome will be TRUE. Since the value of s is 10, s >= 10 evaluates to TRUE because s is not greater than 10 but is still equal to 10. s< 25 is also TRUE since 10 is less then 25. Just the same, s!=12, which means s is not equal to 12, evaluates to TRUE. The && is the AND operator, and follows the rule that if all individual conditions are TRUE, the entire statement is TRUE.

45. Describe the order of precedence with regards to operators in C.

Ans:

Order of precedence determines which operation must first take place in an operation statement or conditional statement. On the top most level of precedence are the unary operators !, +, – and &. It is followed by the regular mathematical operators (*, / and modulus % first, followed by + and -). Next in line are the relational operators <, <=, >= and >. This is then followed by the two equality operators == and !=. The logical operators && and || are next evaluated. On the last level is the assignment operator =.

46. What is wrong with this statement? myName = “Robin”;

Ans:

You cannot use the = sign to assign values to a string variable. Instead, use the strcpy function. The correct statement would be: strcpy(myName, “Robin”);

47. How do you determine the length of a string value that was stored in a variable?

Ans:

To get the length of a string value, use the function strlen(). For example, if you have a variable named FullName, you can get the length of the stored string value by using this statement: I = strlen(FullName); the variable I will now have the character length of the string value.

48. Is it possible to initialize a variable at the time it was declared?

Ans:

Yes, you don’t have to write a separate assignment statement after the variable declaration, unless you plan to change it later on. For example: char planet[15] = “Earth”; does two things: it declares a string variable named planet, then initializes it with the value “Earth”.

49. Why is C language being considered a middle level language?

Ans:

This is because C language is rich in features that make it behave like a high level language while at the same time can interact with hardware using low level methods. The use of a well structured approach to programming, coupled with English-like words used in functions, makes it act as a high level language. On the other hand, C can directly access memory structures similar to assembly language routines.

50. What are the different file extensions involved when programming in C?

Ans:

Source codes in C are saved with .C file extension. Header files or library files have the .H file extension. Every time a program source code is successfully compiled, it creates an .OBJ object file, and an executable .EXE file.




 

51. What are reserved words?

Ans:

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 what it is originally intended for. Examples of reserved words are int, void, and return.

52. What are linked list?

Ans:

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. What is FIFO?

Ans:

In C programming, there is a data structure known as 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. What are binary trees?

Ans:

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?

Ans:

FALSE. All reserved words must be written in lowercase; otherwise the C compiler would interpret this as unidentified and invalid.

56. What is the difference between the expression “++a” and “a++”?

Ans:

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 a itself is incremented. This is also known as postfix increment.

57. What would happen to X in this expression: X += 15; (assuming the value of X is 5)

Ans:

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?

Ans:

FALSE. C language is a case sensitive language. Therefore, NAME, name and Name are three uniquely different variables.

59. What is an endless loop?

Ans:

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. What is a program flowchart and how does it help in writing a program?

Ans:

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. What is wrong with this program statement? void = 10;

Ans:

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;

Ans:

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. However, recall that reserved words are express in lowercase, so the C compiler will not interpret this as a reserved word.

63. What are actual arguments?

Ans:

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. What is a newline escape sequence?

Ans:

A newline escape sequence is represented by the \n 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, \n\n would insert two spaces. A newline escape sequence can be placed before the actual output expression or after.

65. What is output redirection?

Ans:

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 showing it on the screen.

66. What are run-time errors?

Ans:

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, showing which program line caused the error.

67. What is the difference between functions abs() and fabs()?

Ans:

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 , while fabs() is under .

68. What are formal parameters?

Ans:

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 in whatever operations as indicated within the main body of the called function.

69. What are control structures?

Ans:

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.

Ans:

If (num>=0) 
printf("number is positive");
else
printf ("number is negative");


 

71. When is a “switch” statement preferable over an “if” statement?

Ans:

The switch statement is best used when dealing with selections based on a single variable or expression. However, switch statements can only evaluate integer and character data types.

72. What are global variables and how do you declare them?

Ans:

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. What are enumerated types?

Ans:

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. What does the function toupper() do?

Ans:

It is used to convert any letter to its upper case mode. Toupper() function prototype is declared in . 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?

Ans:

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. What are multidimensional arrays?

Ans:

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?

Ans:

The strcat function. It takes two parameters, the source string and the string value to be appended to the source string.

78. What is the difference between functions getch() and getche()?

Ans:

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 getche(), the key that was pressed by the user will appear on the screen, while at the same time being assigned to a variable.

79. Dothese two program statements perform the same output? 1) scanf(“%c”, &letter); 2) letter=getchar()

Ans:

Yes, they both do the exact same thing, which is to accept the next key pressed by the user and assign it to variable named letter.

80. What are structure types in C?

Ans:

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. What does the characters “r” and “w” mean when writing programs that will make use of files?

Ans:

“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. What is the difference between text files and binary files?

Ans:

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?

Ans:

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. What is dynamic data structure?

Ans:

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 static data structure, wherein the programmer has to indicate a fix number of memory space to be used in the program.

85. What are the different data types in C?

Ans:

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. What is the general form of a C program?

Ans:

A C program begins with the preprocessor directives, in which the programmer would specify which header file and 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. What is the advantage of a random access file?

Ans:

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, what will happen if a break statement is omitted?

Ans:

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 how arrays can be passed to a user defined function

Ans:

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. What are pointers?

Ans:

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.


 

61. What is wrong with this program statement? void = 10;

Ans:

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;

Ans:

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. However, recall that reserved words are express in lowercase, so the C compiler will not interpret this as a reserved word.

63. What are actual arguments?

Ans:

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. What is a newline escape sequence?

Ans:

A newline escape sequence is represented by the \n 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, \n\n would insert two spaces. A newline escape sequence can be placed before the actual output expression or after.

65. What is output redirection?

Ans:

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 showing it on the screen.

66. What are run-time errors?

Ans:

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, showing which program line caused the error.

67. What is the difference between functions abs() and fabs()?

Ans:

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 , while fabs() is under .

68. What are formal parameters?

Ans:

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 in whatever operations as indicated within the main body of the called function.

69. What are control structures?

Ans:

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.

Ans:

If (num>=0) 
printf("number is positive");
else
printf ("number is negative");


 

71. When is a “switch” statement preferable over an “if” statement?

Ans:

The switch statement is best used when dealing with selections based on a single variable or expression. However, switch statements can only evaluate integer and character data types.

72. What are global variables and how do you declare them?

Ans:

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. What are enumerated types?

Ans:

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. What does the function toupper() do?

Ans:

It is used to convert any letter to its upper case mode. Toupper() function prototype is declared in . 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?

Ans:

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. What are multidimensional arrays?

Ans:

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?

Ans:

The strcat function. It takes two parameters, the source string and the string value to be appended to the source string.

78. What is the difference between functions getch() and getche()?

Ans:

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 getche(), the key that was pressed by the user will appear on the screen, while at the same time being assigned to a variable.

79. Dothese two program statements perform the same output? 1) scanf(“%c”, &letter); 2) letter=getchar()

Ans:

Yes, they both do the exact same thing, which is to accept the next key pressed by the user and assign it to variable named letter.

80. What are structure types in C?

Ans:

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. What does the characters “r” and “w” mean when writing programs that will make use of files?

Ans:

“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. What is the difference between text files and binary files?

Ans:

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?

Ans:

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. What is dynamic data structure?

Ans:

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 static data structure, wherein the programmer has to indicate a fix number of memory space to be used in the program.

85. What are the different data types in C?

Ans:

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. What is the general form of a C program?

Ans:

A C program begins with the preprocessor directives, in which the programmer would specify which header file and 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. What is the advantage of a random access file?

Ans:

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, what will happen if a break statement is omitted?

Ans:

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 how arrays can be passed to a user defined function

Ans:

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. What are pointers?

Ans:

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?

Ans:

Yes, it is possible to pass an entire structure to a function in a call by method style. 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 argument type.

92. What is gets() function?

Ans:

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 \0 is placed after the last character.

93. The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?

Ans:

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. How do you search data in a data file using random access method?

Ans:

Use the fseek() function to perform random access input/ouput 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?

Ans:

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?

Ans:

Yes, use the qsort() function. It is also possible to create user defined functions for sorting, such as those based on the balloon sort and bubble sort algorithm.

97. What are the advantages and disadvantages of a heap?

Ans:

Storing data on the heap is slower than it would take when using the stack. However, the main advantage of using the heap is its flexibility. That’s because 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. How do you convert strings to numbers in C?

Ans:

You can write you own functions to do string to number conversions, or instead use C’s built in functions. You can use atof 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.

Ans:

int temp;
temp = num1;
num1 = num2;
num2 = temp;

100. What is the use of a semicolon (;) at the end of every program statement?

Ans:

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.



 

101. What is C language?

Ans:

C is a mid level and procedural programming language.

102. Why C is known as a mother language?

Ans:

C is known as a mother language because most of the compilers, kernals and JVMs are written in C language.

103. Why C is called a mid level programming language?

Ans:

It supports the feature of both low-level and high level languages that is why it is known as a mid level programming language.

104. Who is the founder of C language?

Ans:

Dennis Ritchie.

105. When C langauge was developed?

Ans:

C language was developed in 1972 at bell laboratories of AT&T.

106. What are the features of C language?

Ans:

The main features of C language are given below:
Simple
Portable
Mid Level
Structured
Fast Speed
Memory Management
Extensible

107. What is the use of printf() and scanf() functions?

Ans:

The printf() function is used for output and scanf() function is used for input.

108. What is the difference between local variable and global variable in C?

Ans:

Local variable: A variable which is declared inside function or block is known as local variable.
Global variable: A variable which is declared outside function or block is known as global variable.

int value=50;//global variable 
void function1(){
int x=20;//local variable
}

109. What is the use of static variable in C?

Ans:

A variable which is declared as static is known as static variable. The static variable retains its value between multiple function calls.

void function1(){ 
int x=10;//local variable
static int y=10;//static variable
x=x+1;
y=y+1;
printf("%d\n",x);//will always print 11
printf("%d\n",y);//will always increment value, it will print 11, 12, 13 and so on
}

110. What is the use of function in C?

Ans:

A function in C language provides modularity. It can be called many times. It saves code and we can reuse the same code many times.




 

111. What is the difference between call by value and call by reference in C?

Ans:

We can pass value to function by one of the two ways: call by value or call by reference. In case of call by value, a copy of value is passed to the function, so original value is not modified. But in case of call by reference, an address of value of passed to the function, so original value is modified.

112. What is recursion in C?

Ans:

Calling the same function, inside function is known as recursion. For example:

void function1(){ 
function1();//calling same function
}

113. What is array in C?

Ans:

Array is a group of similar types of elements. It has contiguous memory location. It makes the code optimized, easy to traverse and easy to sort.

114. What is pointer in C?

Ans:

A pointer is a variable that refers to the address of a value. It makes the code optimized and makes the performance fast.

115. What are the usage of pointer in C?

Ans:

Accessing array elements
Dynamic memory allocation
Call by Reference
Data Structures like tree, graph, linked list etc.

116. What is NULL pointer in C?

Ans:

A pointer that doesn’t refer to any address of a value but NULL, is known as NULL pointer. For example:
int *p=NULL;

117. What is far pointer in C?

Ans:

A pointer which can access all the 16 segments (whole residence memory) of RAM is known as far pointer.

118. What is dangling pointer in C?

Ans:

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

119. What is pointer to pointer in C?

Ans:

In case of pointer to pointer concept, one pointer refers to the address of another pointer.

120. What is static memory allocation?

Ans:

In case of static memory allocation, memory is allocated at compile time and memory can’t be increased while executing the program. It is used in array.


 

121. What is dynamic memory allocation?

Ans:

In case of dynamic memory allocation, memory is allocated at run time and memory can be increased while executing the program. It is used in linked list.

122. What functions are used for dynamic memory allocation in C language?

Ans:

malloc()
calloc()
realloc()
free()

123. What is the difference between malloc() and calloc()?

Ans:

malloc(): The malloc() function allocates single block of requested memory. It has garbage value initially.
calloc(): The calloc() function allocates multiple block of requested memory. It initially initializes all bytes to zero.

124. What is structure?

Ans:

Structure is a user-defined data type that allows to store multiple types of data in a single unit. It occupies the sum of memory of all members.

125. What is union?

Ans:

Like Structure, union is a user-defined data type that allows to store multiple types of data in a single unit. But it doesn’t occupies the sum of memory of all members. It occupies the memory of largest member only.

126. What is auto keyword in C?

Ans:

In C, every local variable of a function is known as automatic (auto) variable. Let’s explain with an example:

void f() 
{
int i ;
auto int j;
}

Here, both ‘i’ and ‘j’ variables are automatic variables.
Note: A global variable can’t be an automatic variable.

127. What is the purpose of sprintf() function?

Ans:

It is used to print the formatted output into char array.

128. Can we compile a program without main() function?

Ans:

Yes, we can compile but it can’t be executed.
But, if we use #define, we can compile and run C program without using main() function. For example:

#include 
#define start main
void start() {
printf("Hello");
}

129. What is token?

Ans:

Token is an identifier. It can be constant, keyword, string literal etc.

130. What is command line argument?

Ans:

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
}


 

131. What is the acronym for ANSI?

Ans:

American National Standard Institute.

132. What is the difference between getch() and getche()?

Ans:

The getch() function reads a single character from keyboard. It doesn’t uses any buffer, so entered data is not displayed on the output screen.
The getche() function reads a single character from keyword but data is displayed on the output screen. Press Alt+f5 to see the entered character.

133. What is new line escape sequence?

Ans:

The new line escape sequence is represented by “\n”. It inserts a new line on the output screen.

134. Who is the main contributor in designing the C language after Dennis Ritchie?

Ans:

Brain Kernighan.

135. What is the difference between near, far and huge pointers?

Ans:

A virtual address is composed of selector and offset.
A near pointer doesn’t have explicit selector whereas far and huge pointers have explicit selector. When you perform pointer arithmetic on far pointer, selector is not modified but in case of huge pointer it can be modified.
These are the non-standard keywords and implementation specific. These are irrelevant in modern platform.

136. What is the maximum length of an identifier?

Ans:

It is 32 characters ideally but implementation specific.

137. What is typecasting?

Ans:

Converting one data type into another is known as typecasting. For example:

float f=3.4; 
int a=(int)f;//typecasting

138. What are the functions to open and close file in C language?

Ans:

The fopen() function is used to open file whereas fclose() is used to close file.

139. Can we access array using pointer in C language?

Ans:

Yes, by holding the base address of array into pointer, we can access the array using pointer.

140. What is infinite loop?

Ans:

A loop running continuously for indefinite number of times is called infinite loop.
Infinite For Loop:

for(;;){ 
//code to be executed
}
Infinite While Loop:
while(1){
//code to be executed
}
Infinite Do-While Loop:
do{
//code to be executed
}while(1);



 

141. Write a program to print “hello world” without using semicolon?

Ans:

There are various ways to do so. Let’s see a program to print “hello world” using if.

#include 
void main(){
if(printf("hello world")){}
}

142. Write a program to swap two numbers without using third variable?

Ans:

#include 
#include
main()
{
int a=10, b=20;
clrscr();
printf("Before swap a=%d b=%d",a,b);

a=a+b;//a=30 (10+20)
b=a-b;//b=10 (30-20)
a=a-b;//a=20 (30-10)

printf(“\nAfter swap a=%d b=%d”,a,b);
getch();
}

143. Write a program to print fibonacci series without using recursion?

Ans:

#include 
#include
void main()
{
int n1=0,n2=1,n3,i,number;
clrscr();
printf("Enter the number of elements:");
scanf("%d",&number);
printf("\n%d %d",n1,n2);//printing 0 and 1

for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already printed
{
n3=n1+n2;
printf(” %d”,n3);
n1=n2;
n2=n3;
}
getch();
}

144. Write a program to print fibonacci series using recursion?

Ans:

#include 
#include
void printFibonacci(int n){
static int n1=0,n2=1,n3;
if(n>0){
n3 = n1 + n2;
n1 = n2;
n2 = n3;
printf("%d ",n3);
printFibonacci(n-1);
}
}
void main(){
int n;
clrscr();
printf("Enter the number of elements: ");
scanf("%d",&n);

printf(“Fibonacci Series: “);
printf(“%d %d “,0,1);
printFibonacci(n-2);//n-2 because 2 numbers are already printed

getch();
}

145. Write a program to check prime number in C Programming?

Ans:

#include 
#include
void main()
{
int n,i,m=0,flag=0;
clrscr();
printf("Enter the number to check prime:");
scanf("%d",&n);
m=n/2;
for(i=2;i<=m;i++)
{
if(n%i==0)
{
printf("Number is not prime");
flag=1;
break;
}
}
if(flag==0)
printf("Number is prime");
getch();
}

146. Write a program to check palindrome number in C Programming?

Ans:

#include 
#include
main()
{
int n,r,sum=0,temp;
clrscr();
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
printf("palindrome number ");
else
printf("not palindrome");
getch();
}

147. Write a program to print factorial of given number without using recursion?

Ans:

#include 
#include
void main(){
int i,fact=1,number;
clrscr();
printf("Enter a number: ");
scanf("%d",&number);

for(i=1;i<=number;i++){
fact=fact*i;
}
printf(“Factorial of %d is: %d”,number,fact);
getch();
}

148. Write a program to print factorial of given number using recursion?

Ans:

#include 
#include

long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}

void main()
{
int number;
long fact;
clrscr();
printf(“Enter a number: “);
scanf(“%d”, &number);

fact = factorial(number);
printf(“Factorial of %d is %ld\n”, number, fact);
getch();
}

149. Write a program to check armstrong number in C?

Ans:

#include 
#include
main()
{
int n,r,sum=0,temp;
clrscr();
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
printf("armstrong number ");
else
printf("not armstrong number");
getch();
}

150. Write a program to reverse a given number in C?

Ans:

#include 
#include
main()
{
int n, reverse=0, rem;
clrscr();
printf("Enter a number: ");
scanf("%d", &n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
printf("Reversed Number: %d",reverse);
getch();
}

 

151. What are the key features in C programming language?

Ans:

Portability – Platform independent language.
Modularity – Possibility to break down large programs into small modules.
Flexibility – The possibility to a programmer to control the language.
Speed – C comes with support for system programming and hence it is compiling and executes with high speed when comparing with other high-level languages.
Extensibility – Possibility to add new features by the programmer.

152. What are the basic data types associated with C?

Ans:

Int – Represent number (integer)
Float – Number with a fraction part.
Double – Double-precision floating point value
Char – Single character
Void – Special purpose type without any value.

153. What is the description for syntax errors?

Ans:

The mistakes when creating a program called syntax errors. Misspelled commands or incorrect case commands, an incorrect number of parameters when called a method /function, data type mismatches can identify as common examples for syntax errors.

154. What is the process to create increment and decrement stamen in C?

Ans:

There are two possible methods to perform this task.
1) Use increment (++) and decrement (-) operator.
Example When x=4, x++ returns 5 and x- returns 3.
2) Use conventional + or – sign.
When x=4, use x+1 to get 5 and x-1 to get 3.

155. What are reserved words with a programming language?

Ans:

The words that are part of the slandered C language library are called reserved words. Those reserved words have special meaning and it is not possible to use them for any activity other than its intended functionality.
Example void, return, int.

156. What is the explanation for the dangling pointer in C?

Ans:

When there is a pointer with pointing to a memory address of any variable, but after some time the variable was deleted from the memory location while keeping the pointer pointing to that location.

157. Describe static function with its usage?

Ans:

A function, which has a function definition prefixed with a static keyword is defined as a static function. The static function should call within the same source code.

158. What is the difference between abs() and fabs() functions?

Ans:

Both functions are to retrieve absolute value. abs() is for integer values and fabs() is for floating type numbers. Prototype for abs() is under the library file < stdlib.h > and fabs() is under < math.h >.

159. Describe Wild Pointers in C?

Ans:

Uninitialized pointers in the C code are known as Wild Pointers. These are a point to some arbitrary memory location and can cause bad program behavior or program crash.

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

Ans:

‘++a” is called prefixed increment and the increment will happen first on a variable. ‘a++’ is called postfix increment and the increment happens after the value of a variable used for the operations.



 

161. Describe the difference between = and == symbols in C programming?

Ans:

‘==’ is the comparison operator which is use to compare the value or expression on the left-hand side with the value or expression on the right-hand side.
‘=’ is the assignment operator which is use to assign the value of the right-hand side to the variable on the left-hand side.

162. What is the explanation for prototype function in C?

Ans:

Prototype function is a declaration of a function with the following information to the compiler.
Name of the function.
The return type of the function.
Parameters list of the function.

163. What is the explanation for cyclic nature of data types in C?

Ans:

Some of the data types in C have special characteristic nature when a developer assign value beyond the range of the data type. There will be no any compiler error and the value change according to a cyclic order. This is called as cyclic nature and Char, int, long int data types have this property. Further float, double and long double data types do not have this property.
This is called as cyclic nature and Char, int, long int data types have this property. Further float, double and long double data types do not have this property.

164. Describe the header file and its usage in C programming?

Ans:

The file contains the definitions and prototypes of the functions being used in the program are called a header file. It is also known as a library file.
Example– The header file contains commands like printf and scanf is the stdio.h.

165. There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?

Ans:

This concept called as commenting out and is the way to isolate some part of the code which scans possible reason for the error. Also, this concept helps to save time because if the code is not the reason for the issue it can simply uncomment.

166. What are the general description for loop statement and available loop types in C?

Ans:

A statement that allows executing statement or group of statements in repeated way is defined as a loop.
There are 4 types of a loop statement in C.
While loop
For Loop
Do…While Loop
Nested Loop

167. What is a nested loop?

Ans:

A loop running within another loop is referred as a nested loop. The first loop is called Outer loop and inside the loop is called Inner loop. Inner loop executes the number of times define an outer loop.
Is that possible to store 32768 in an int data type variable?
Ans) Int data type only capable of storing values between – 32768 to 32767.To store 32768 a modifier needs to use with int data type. Long Int can use and also if there is no any negative values unsigned int is also possible to use.

168. Is there any possibility to create customized header file with C programming language?

Ans:

It is possible and easy to create a new header file. Create a file with function prototypes that needs to use inside the program. Include the file in ‘#include’ section from its name.

169. Describe dynamic data structure in C programming language?

Ans:

Dynamic data structure is more efficient to the memory. The memory access occurs as needed by the program.

170. Is that possible to add pointers to each other?

Ans:

There is no possibility to add pointers together. Since pointer contains address details there is no way to retrieve the value from this operation.




 

171. What is indirection?

Ans:

If you have defined a pointer to a variable or any memory object, there is no direct reference to the value of the variable. This is called indirect reference. But when we declare a variable it has a direct reference to the value.

172. What are the ways to a null pointer can use in C programming language?

Ans:

Null pointers are possible to use in three ways.
As an error value.
As a sentinel value.
To terminate indirection in the recursive data structure.

173. What is the explanation for modular programming?

Ans:

The process of dividing the main program into executable subsection is called module programming. This concept promotes the reusability.