- Given the function definition
void Twist (int a, int& b)
{ int c;
c = a + 2;
a = a * 3;
b = c + a;
}
What is the output of the following code fragment that invokes Twist?
int r = 1;
int s = 2;
int t = 3;
Twist (t, s);
cout << r << ' ' << s << ' ' << t << endl;
1 14 3
1 10 3
5 14 3
1 14 9
- Given the function definition
void DoThis (int& alpha, int beta)
{ int temp;
alpha = alpha + 100;
temp = beta;
beta = 999;
}
What is the output of the following code fragment that invokes DoThis?
int gamma = 10;
int delta = 20;
DoThis (gamma, delta);
cout << gamma << ' ' << delta << ' ' << endl;
gamma = 10 and delta = 20
gamma = 110 and delta = 20
gamma =10 and delta = 999
gamma = 110 and delta = 999
- Given the function prototype:
void Fix (int&, double);
Which of the following is an appropriate function call when someInt and someDouble are delcared?
int someInt = 0;
double someDouble = 0.0;
Fix (24, 6.85);
someDouble = 0.3 * Fix(someInt, 6.85);
Fix (someInt + 5, someDouble);
Fix (someInt, someDouble);
- Which of the following is the correct function heading for a parameterless function named PrintStars?
void PrintStars
void PrintStars;
void PrintStars()
void PrintStars();
- Given the function heading:
void GetNums (int howMany, float& alpha, float& beta)
Which of the following is a valid function prototype for GetNums?
void GetNums (int howMany, float& alpha, float beta);
void GetNums (int, float&, float &);
int GetNums (int, float&, float&);
int GetNums(int howMany, float& alpha, float& beta);
- The function someFunc() should have two formal parameters of type int named alpha and beta.
The parameter for alpha should be pass-by-value and the parameter for beta should be pass-by-reference.
What is the most appropriate function heading for someFunc()?
void SomeFunc (int alpha, int beta)
void SomeFunc (int& alpha, int beta)
void SomeFunc (int alpha, int& beta)
void SomeFunc (int& alpha, int& beta)
- If a C++ function does not use parameters, you still must put parentheses around the empty parameter list.
True
False
- Given:
string name1 = "Aaron", name2 = "Aardvark", name3;
What is the output of the following code segment?
if (name1 > name2)
{name3 = name1;
name1 = name2;
name2 = name3;
}
cout << "The first name on the list is " << name1 << endl;
Aaron
Aardvark
- In C++, an array can be passed as a parameter either by value or by reference.
True
False
- Given the declaration
int beta [20];
the expression beta [3] accesses the third component of the array.
True
False
- C++ does not check for out-of-bounds array indices while a program is running.
True
False
- An individual array component can be passed as a parameter to a function.
True
False
- What is the output of the following program fragment?
int alpha[5] = {100, 200, 300, 400, 500};
int i;
for (i = 4; i > 0; i--)
cout << alpha[i] << ' ';
cout << endl;
400 300 200 100
500 400 300 200 100
500 400 300 200
4 3 2 1
- In C++, an array is passed by default as a value parameter.
True
False
- Given the declarations
int status [10];
int i;
Which of the following loops correctly zeros out the status array?
for (i = 0; i <= 10; i++) status[i] = 0;
for (i = 0; i < 10; i++) status[i] = 0;
for (i = 1; i <= 10; i++) status[i] = 0;
for (i = 1; i < 10; i++) status[i] = 0;
- Given the declaration
int beta [20];
the statement
beta = beta + 1;
adds 1 to all 20 elements of the array.
True
False
- Given:
char myString[] = "Adios";
the C++ compiler allocates an array of 5 elements.
True
False
- The following are valid C++ statements:
int num[3];
num = {0, 0, 0};
True
False
- In C++, the subscript of a one-dimensional array must be of type integer.
True
False
- In a C++ program, 't' is contained in memory as a single character, whereas "t"
is contained in memory as two characters.
True
False