Home
41.
Is it better to code a compound if statement or to nest multiple if statements?

You should make your code easy to understand. If you nest if statements, they will be evaluated If you use a single compound statement, the expressions are evaluated only until the entire statement evaluates to false.

42.
What is the difference between unary and binary operators?

As the names imply, unary operators work with one variable, and binary operators work with two.

43.
Is the subtraction operator (-) binary or unary?

It's both! The compiler is smart enough to know which one you’re using. It knows which form to use based on the number of variables in the expression that is used. In the following statement, it is unary:
x = -y;
versus the following binary use:
x = a - b;

44.
What is an expression?

An expression is anything that evaluates to a numerical value.

45.
In an expression that contains multiple operators, what determines the order in which operations are performed?

The relative precedence of the operators.

46.
If the variable x has the value 10, what are the values of x and a after each of the following statements is executed separately?
a = x++;
a = ++x;

After the first statement, the value of a is 10, and the value of x is 11. After the second statement, both a and x have the value 11. (The statements must be executed separately.)

47.
What are the compound assignment operators, and how are they useful?

The compound assignment operators let you combine a binary mathematical operation with an assignment operation, thus providing a shorthand notation. The compound operators are +=, -=, /=, *=, and %=.

48.
What other ways are there to use recursion?

The factorial function is a prime example of using recursion. The factorial number is needed in many statistical calculations. Recursion is just a loop; however, it has one difference from other loops. With recursion, each time a recursive function is called, a new set of variables is created.

49.
My class has only one constructor that has been defined with a parameter with a default value. Is this still a default constructor?

Yes. If an instance of a class can be created without arguments, then the class is said to have a default constructor. A class can have only one default constructor.

50.
Does main() have to be the first function in a program?

No. It is a standard in C that the main() function is the first function to execute; however, it can be placed anywhere in your source file. Most people place it either first or last so that it’s easy to locate.