7) Given the function prototype
void fix( int&, double );
which of the following is an appropriate function call? (someInt is of type int, and
someDouble is of type double.)
A. fix(24, 6.85);
B. someDouble = 0.3 * fix(someInt, 6.85);
C. fix(someInt + 5, someDouble);
D. A and C above
E. none of the above
Why i this one E? I feel like C should work. Does it have something to do with the (int&) ?
------------
20) After execution of the code fragment
int arr[5];
int i;
for (i = 0; i <4; i++) {
arr[i] = i + 2;
if (i >=2)
arr[i+1] = arr[i] + 3;
}
what is contained in arr[3]?
A. 4
B. 6
C. 7
D. 9
E. none of the above
Also, why is this one E. I keep getting C, but i am not to sure if i am doing right. a[0] = 2, a[1] = 3, a[2]= 4 then a[3] = 7 on the bottom. But as I sit here typing this, I think that gets overwritten when the loop goes again, so a[3] = 3 + 2 = 5, so is that why it is E?
for the first one int& is a reference to an int variable. Think of it as an alias to a variable. letter C won't work because someInt + 5 will be calculated first and will result in a literal integer value. References can only refer to memory addresses, and that's why C won't work.
for the second question, you're correct that's the reason why it's E. =)