C Programming Interview Questions and Answers-2

Q: – Why is the main() function needed in a program?
The execution of a C program starts and ends with the main() function. Without the main() function, the computer does not know where to start to run a program.
Q: – What does the #include directive do?
The #include directive is used to include header files that contain the declarations to the functions used in your C program. In other words, the #include directive tells the C preprocessor to look into the include path to find the specified header file.
Q: – Why do you need a linker?
After compiling, some function code may still be missing in the object file of a program. A linker must then be used to link the object file to the C standard library or other user-generated libraries and include the missing function code so that an executable file can be created.
Q: – What is the difference between a constant and a variable?
The major difference is that the value of a constant cannot be changed, whereas the value of a variable can. You can assign different values to a variable whenever it’s necessary in your C program.
Q: – Why do you need a statement block?
Many C keywords can only control one statement. A statement block provides a way to put more than one statement together, and put the statement block under the control of a C keyword. Then, the statement block is treated as a single statement.
Q: – Which arithmetic operators have a higher precedence?
Among the five arithmetic operators, the multiplication, division, and remainder operators have a higher precedence than the addition and subtraction operators.
Q: – How many parts does a function normally have?
A function normally has six parts: the function type, the function name, the arguments, the opening brace, the function body, and the closing brace.
Q: – How can you declare two character variables?
There are two ways to do the declaration. The first one is
…char variable-name1, variable-name2;
The second one is
char variable-name1;
char variable-name2;
Q: – What are %c, %d, and %f?
These are format specifiers. %c is used to obtain the character format; %d is for the integer format; %f is for the floating-point format. %c, %d, and %f are often used with C functions such as printf().
Q: – What are the main differences between the int data type (integer) and the float data type (floating-point)?
First, an integer does not contain any fraction parts, but a floating-point number does. A floating-point number must have a decimal point. In C, the float data type takes more bits than the int data type. In other words, the float data type has a larger range of numeric values than the int data type.

Tagged , . Bookmark the permalink.

Leave a Reply