COP 3330 FSU Exam 1 Graded A+
Consider the following function prototype:
void Funky (const int * a, size_t size);
and suppose your have a client program with an array declared as follows:
int intArray[20];
a)
The call
Funky(intArray,10);
is not allowed to change the value of intArray.
b)
The call
Funky(intArray,10);
will likely result in a compile error.
c)
The call
Funky(intArray,20)
is allowed to change the value intArray[20].
d)
The call
Funky(intArray,10)
is not allowed to change the value of intArray[5]. - ANSWER-The call
Funky(intArray,10)
is not allowed to change the value of intArray[5]
Consider the following program:
int F(int a, int& b)
{
a = a - 1;
b = b - 1;
return a + b;
}
int main()
{
int x,y,z;
x = 2; y = 3; z = 4;
std::cout << "x = " << x << '\n'
<< "y = " << y << '\n'
<< "z = " << z << '\n';
, }
What is the screen output?
a)
x=2
y=3
z=4
x=2
y=3
z=4
b)
x=1
y=2
z=3
x=2
y=2
z=5
c)
x=2
y=3
z=4
x=2
y=2
z=5
d)
x=2
y=3
z=4
x=2
y=2
z = 3 - ANSWER-x = 2
y=3
z=4
x=2
y=2
z=3
Discuss why an init is preferred over initialization inside the constructor body. -
ANSWER-Efficiency
Clarity
Universality
Good Habits
Given the class definition:
Consider the following function prototype:
void Funky (const int * a, size_t size);
and suppose your have a client program with an array declared as follows:
int intArray[20];
a)
The call
Funky(intArray,10);
is not allowed to change the value of intArray.
b)
The call
Funky(intArray,10);
will likely result in a compile error.
c)
The call
Funky(intArray,20)
is allowed to change the value intArray[20].
d)
The call
Funky(intArray,10)
is not allowed to change the value of intArray[5]. - ANSWER-The call
Funky(intArray,10)
is not allowed to change the value of intArray[5]
Consider the following program:
int F(int a, int& b)
{
a = a - 1;
b = b - 1;
return a + b;
}
int main()
{
int x,y,z;
x = 2; y = 3; z = 4;
std::cout << "x = " << x << '\n'
<< "y = " << y << '\n'
<< "z = " << z << '\n';
, }
What is the screen output?
a)
x=2
y=3
z=4
x=2
y=3
z=4
b)
x=1
y=2
z=3
x=2
y=2
z=5
c)
x=2
y=3
z=4
x=2
y=2
z=5
d)
x=2
y=3
z=4
x=2
y=2
z = 3 - ANSWER-x = 2
y=3
z=4
x=2
y=2
z=3
Discuss why an init is preferred over initialization inside the constructor body. -
ANSWER-Efficiency
Clarity
Universality
Good Habits
Given the class definition: