C Interview Questions & Answers part 5

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: – Is the unary minus operator (-) the same as the subtraction operator (-)?

No, they are not the same, although the two operators share the same symbol. The meaning of the symbol is determined by the context in which it appears. The unary minus operator is used to change the sign of a numeric value. In other words, the unary minus operator yields the negation of the value. The subtraction operator is an arithmetic operator that performs a subtraction between its two operands.

Q: –Why do we need the sizeof operator?

The sizeof operator can be used to measure the sizes of all data types defined in C. When you write a portable C program that needs to know the size of an integer variable, it’s a bad idea to hard-code the size based on the machine you are currently using. The better way to tell the program the size of the variable is to use the sizeof operator, which yields the size of the integer variable at runtime.

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.

Q: – What are stdin, stdout, and stderr?

In C, a file is treated as a series of bytes that is called file stream. stdin, stdout, and stderr are all pre-opened file streams. stdin is the standard input for reading; stdout is the standard output for writing; stderr is the standard error for outputting error messages.

 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: –What value is yielded by a relational expression?

A relational expression evaluates to either 0 or 1. If the relation indicated by a relational operator in an expression is true, the expression evaluates to 1; otherwise, the expression evaluates to 0.

Q: –What can the %lu format specifier do?

The %lu format specifier can be used in a printf() string to convert the corresponding argument to the unsigned long int data type. In addition, the %lu format specifier is equivalent to %Lu.

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.

Submitted By:-Rohit Kumar          Email-ID: – rohitkumar1372@yahoo.in