W11 quiz: cstring, optparams, structs Flashcards
Like variables, the contents of an array could be any values until/unless we specifically store something. The first time we store a value in an array position we are initializing that array element.
_ True?
_ False?
True
The update statement is performed at the bottom of a for loop, just after
each pass through the body.
_ True?
_ False?
True
What output is produced by the segment of code shown below:
for (int i = 1; i <= 10; i = i + 2)
{
cout «_space;i;
}
a: 13579
b: 1357
c: 12345678910
d: 13578
a: 13579
What loos needs a semi-colon after?
a: do
b: while
c: all of the options listed
d: for
a: do
What is the output of the following program:
int main()
{
int myArray[4] = {77, 33, 44, 8};
for(int i=0; i < 4; ++i) { cout << myArray[i]; } } a: 7348 b: None of the options listed c:8443377 d: 7733448
d: 7733448
In nested loops, the outer loop runs to completion first (likely multiple times)
before the inner loop is executed.
_ True?
_ False?
False
The following code will produce an infinite loop:
int main()
{
int i = 10;
while(i<100)
{
cout «_space;i «_space;endl;
}
}
_ True?
_ False?
True
What loops are guaranteed to execute at least once?
a: while
b: none of the options listed
c: do
d: for
c: do
An array is organized into positions, each acting as a storage spot for one item.
_ True?
_ False?
True
What are the 2 expanding ways that we can declare and call functions?
optional parameters and function overloading
Is it possible to provide default values for a parameter?
Yes
What option can the caller have with the parameter?
The caller has the option of calling the function with or without passing that specific parameter
Is it possible to declare multiple different versions of a function with the same name?
Yes
What is the condition for declaring multiple different versions of a function with the same name?
The parameter lists are “different enough” for the compiler to always identify the correct one to call
Can we assign a default for one or more parameters in the declaration?
Yes,
example:
void myfunction(int x, char y = ‘a’, float z = 1.3)
note: must be done in the prototype when following the course code standards
Can the caller omit one or more of the parameters?
Yes
example:
myfunction(10); // uses ‘a’ for y, 1.3 for z
myfunction(10, ‘q’); // uses 1.3 for z