COP 3330 FSU Exam 1 Exam with
complete solutions latest version
Which of the following code fragments produces the output:
z = 1.5
a)
int x = 1;
int y = 2;
float z = (x + y)/2;
std::cout << "z = " << z << '\n';
b)
int x = 1;
int y = 2;
float z = x + y;
std::cout << "z = " << z/2 << '\n';
c)
int x = 1;
int y = 2;
float z = x/2 + y/2;
std::cout << "z = " << z << '\n';
d)
int x = 1;
int y = 2;
float z = (x + y)/y;
std::cout << "z = " << z << '\n'; - CORRECT ANSWER-int x = 1;
int y = 2;
float z = x + y;
std::cout << "z = " << z/2 << '\n';
BRAINSCAPE1
, BRAINSCAPE1
Given the declarations
int A [20];
int * p = A;
Which of the following does not output the index 3 element of A?
a)
A += 3;
std::cout << *A;
b)
std::cout << *(p + 3);
c)
std::cout << A[3];
d)
std::cout << *(A + 3);
e)
p += 3;
std::cout << *p;
f)
std::cout << p[3]; - CORRECT ANSWER-A += 3;
std::cout << *A;
What will the following program segment do?
int counter = 1;
do
{
std::cout << counter << ' ';
}
while (++counter <= 10);
a) Print the integers 1 through 11
b) Print the integers 1 through 10
c) Print the integers 1 through 9
d) Cause a syntax error - CORRECT ANSWER-Print the integers 1 through 10
Which of the following is not true about a for loop structure?
a) The three expressions in the for header are optional
b) A for loop can always be used to replace a while loop, and vice versa
BRAINSCAPE1