Académique Documents
Professionnel Documents
Culture Documents
1. What is wrong with the following definition for a C-style symbolic constant
called PI?
#define PI = 3.24159
double
PI = 3.24159;
In either case, the compiler does not do any error checking to make sure
that the appropriate (or correct) value is associated with the constant. That
is up to the programmer.
2. Which of the following is a condition that will test if the value in the integer
variable num is even?
a. (num % 2) == 0
b. (num / 2) == 0
c. (num % 2) == 1
d. (num / 2) == 1
e. none of the above
To test if an integer contains an even value, check if the remainder is equal
to 0 when the integer is divided by 2. If it is equal, then the integer is even.
If it is not equal (i.e.. it is equal to 1 instead), then the integer is odd.
a. 10
b. 8
c. an infinite number of times
d. 0
This is an infinite loop because the value of i is 1 and that is less than or
equal to 10 and the value of i will remain as 1 because there is nothing in
the loop body to change the value of i.
5. A function prototype does not have to __________.
a. include argument names
b. end with a semi-colon
c. agree with the function header
d. match with all calls of the function
A function prototype supplies the return data type, function name, number
of arguments the function requires, and the data type of any arguments
that the function requires. The argument names, if specified, are ignored.
6. What will be displayed by the following code?
int main()
{
int num = 3;
fn(num);
cout << num;
return 0;
}