Exam 3 Flashcards

(55 cards)

1
Q

Why do local variable lose their values between calls to the function in which they are defined?

A

Local variables lose their values to transfer the value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between an argument and a parameter variable?

A

An argument is values that are sent into a function and a parameter is a variable that holds a value being passed into a function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Where do you define parameter variables?

A

Define the parameter variable after the void statement in the parantheses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If you are writing a function that accepts an argument and you want to make sure the function cannot change the value of the argument, what do you do?

A

Declare the function as a const

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When a function accepts multiple arguments, does it matter what order the arguments are passed?

A

Yes, when the function is written it expects each parameter to be of a certain type in a certain order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you return a value of a function?

A

Return y

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the advantage of breaking your applications code into several small procedures?

A

There are small, simpler functions so it’s easy to maintain and understand.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How would a static local variable be useful?

A

Can refer to local static variable outside of the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Give an example where passing an argument by reference would be useful

A

To modify the value of the function arguemnts and to avoid making copies of an object for performance reasons

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The _ is the part of a function definition that shows the function name, return type, and parameter list.

A

Header

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

If a function doesn’t return a value, the word _ will appear as it’s return type.

A

Void

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Either a functions _ or it’s _ must precede all calls to the function

A

Definition, prototype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Values that are sent into a function are called

A

Arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Special variables that hold copies of function argument are called _

A

Parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When only a copy of an argument is passed to a function, it is said to be passed by

A

Value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A(n) _ eliminates the need to place a function definition before all calls to the function

A

Prototype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

A _ variable is defined inside a function that is not accessible outside the function

A

Local

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

_ variables are defined outside all functions and are accessible to any function within their scope

A

Global

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Unless you explicitly initialize global variables, they are automatically initialized to

A

Zero

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

If a function had a local variable with the same name as a global variable, only the _ variable can be seen THE by the function

A

Local

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

_ local variables retain ther value between function calls

A

static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

The _ statement causes a function to end immediately

A

return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

_ arguments are passed to parameters automatically if no argument is provided in the function call

24
Q

When a function uses a mixture of parameters with and without default arguments, the parameters with default arguemnts must be define _

25
The value of a default argument must be a
constant
26
When used as parameters, _ variables allow a function to access the parameters orginal argument
reference
27
Reference variables are defined like regular variables, except there is an _ in front of the same name.
&
28
The _ function causes a program to terminate
exit
29
two or more functions may have the same name, as long as their _ are different
parameter lists
30
What's the difference between a size declarator and a subscript?
The size declarator is used in a definition of an array to indicate the number of elements the array will have. A subscript is used to access a specific element in an array
31
Look at the following array definition. in values [10]; how many elements does this array have? What is the subscript of the first element in the array? What is the subscript of the last element in the array? Assuming that an int uses four bytes of memory, how much memory does the array use?
The array has 10 elements. The subscript of the first element is zero. The subscript of the last element is 9. Using four-byte integers, this array uses 40 bytes of memory.
32
Why should a function that accepts an array as an argument, and proccesses that array, also accept an argument specifying the array's size?
Because with the array alone, the function has now way of determining the number of elements it has.
33
Consider the following array definition: int numbers [5] = {4, 7, 6, 8, 2]; What does each of the following statements display? cout << values [4] << endl; _ cout << (values [2] + values [3]) << endl; cout << ++values [1] << endl;
2 14 8
34
How do you define an array without providing a seize declarating
By providing an initialization list. The array is sized to hold the number of values in the list.
35
Look at the following array definition. int number [5] = {1, 2, 3}; What value is stored in number [2]? What value is stored in number [4]?
3 0
36
Assuming that array1 and array2 are both arrays, why is it not possible to assign the contents of array2 to array1 with the following statement? array1=array2;
Because an array name without brackets and a subscript represents the array's beginning memory address. The statement shown attempts to assign the address of array2 to array1, which is not permitted.
37
Assuming that numbers is an array of doubles, will the following statement display the contents of the array? cout << numbers << endl;
no
38
Is an array passed to a function by value or referene?
by reference
39
When you pass an array name as an argument to a function, what is actually being passed?
The array's beginning memory address.
40
How do you establish a parallel relationship between two or more arrays?
By using the same subscript value for each array
41
Look at the following array definition. double sales [8][10]; How many rows, columns, and elements does the array have? Write a statement that stores a number in the last column of the last row in the array.
Eight rows Ten columns 2 elements sales[8][10] = 75.2;
42
When writing a function that accepts a two dimensional array as an argument, which size delcarator must you provide in the parameter for the array?
The programmer must include the number of columns and number of rows.
43
What advantages does a vector offer over an array?
A vector can be change its size but an array is a fixed size
44
The _ indicates the number of elements, or values, an array can hold.
size declarator
45
The size declarator must be a(n) _________ with a value greater than _________.
integer 0
46
Each element of an array is accessed and indexed by a number known as a(n) _________.
subscript
47
The number inside the brackets of an array definition is the _________, but the number inside an array’s brackets in an assignment statement, or any other statement that works with the contents of the array, is the _________.
size declarator subscript
48
C++ has no array _________ checking, which means you can inadvertently store data past the end of an array.
bounds
49
Starting values for the elements of an array may be specified with a(n) _________ list.
initialization
50
If an array is partially initialized, the uninitialized elements will be set to ____
zero
51
If the size declarator of an array definition is omitted, C++ counts the number of items in the _________ to determine how large the array should be.
initialization list
52
Any time the name of an array is used without brackets and a subscript, it is seen as ______
an address
53
You cannot use the _________ operator to copy data from one array to another in a single statement.
=
54
To pass an array to a function, pass the _ of the array.
address, or name
55
An _ array is like several arrays of the same type put together
multi-dimensional