Podcast
Questions and Answers
Unlike regular variables, arrays can hold multiple
Unlike regular variables, arrays can hold multiple
The amount of memory used by an array depends solely on the number of elements the array can hold.
The amount of memory used by an array depends solely on the number of elements the array can hold.
False
To access an array element, use the array name and the element's
To access an array element, use the array name and the element's
If a C++ program contains the following array definition int score[10];
, the following statement would store 100 in the first array element: score[1] = 100;
If a C++ program contains the following array definition int score[10];
, the following statement would store 100 in the first array element: score[1] = 100;
Signup and view all the answers
The statement int grades[ ] = {100, 90, 99, 80 };
is an example of
The statement int grades[ ] = {100, 90, 99, 80 };
is an example of
Signup and view all the answers
Which of the following statements correctly initialize the value variable?
Which of the following statements correctly initialize the value variable?
Signup and view all the answers
Which of the following statements will correctly carry out the operation stated in the comment to its right?
Which of the following statements will correctly carry out the operation stated in the comment to its right?
Signup and view all the answers
By using the same _____, you can build relationships between data stored in two or more arrays.
By using the same _____, you can build relationships between data stored in two or more arrays.
Signup and view all the answers
To step through a one-dimensional array, accessing the elements one by one, it would be most appropriate to use a _____ loop.
To step through a one-dimensional array, accessing the elements one by one, it would be most appropriate to use a _____ loop.
Signup and view all the answers
Arrays can be passed to functions, but individual array elements cannot be.
Arrays can be passed to functions, but individual array elements cannot be.
Signup and view all the answers
When an array is passed to a function, it is actually ______ the array that is passed.
When an array is passed to a function, it is actually ______ the array that is passed.
Signup and view all the answers
When you pass an array as an argument to a function, the function can modify the contents of the array.
When you pass an array as an argument to a function, the function can modify the contents of the array.
Signup and view all the answers
A two-dimensional array can be viewed as
A two-dimensional array can be viewed as
Signup and view all the answers
The elements of an array can be
The elements of an array can be
Signup and view all the answers
An element of a two-dimensional array is referenced by the array name and two subscripts, first the element row number and then the element column number.
An element of a two-dimensional array is referenced by the array name and two subscripts, first the element row number and then the element column number.
Signup and view all the answers
The following statement for(int val : myArray) cout << val << " ";
is an example of a(n)
The following statement for(int val : myArray) cout << val << " ";
is an example of a(n)
Signup and view all the answers
What does the following statement do? typedef int oneDArray[20];
What does the following statement do? typedef int oneDArray[20];
Signup and view all the answers
When you create a vector, it is unnecessary to specify how many elements it will hold because it will expand in size as you add new values to it.
When you create a vector, it is unnecessary to specify how many elements it will hold because it will expand in size as you add new values to it.
Signup and view all the answers
The range-based for loop may be used with arrays, but not with vectors.
The range-based for loop may be used with arrays, but not with vectors.
Signup and view all the answers
If employee
is an array of objects with a public member function named setHourlyWage
, the following statement correctly calls this method for employee[2]
: employee.setHourlyWage[2](20.00);
If employee
is an array of objects with a public member function named setHourlyWage
, the following statement correctly calls this method for employee[2]
: employee.setHourlyWage[2](20.00);
Signup and view all the answers
An array can store multiple values, but the values must be
An array can store multiple values, but the values must be
Signup and view all the answers
The amount of memory used by an array depends upon the array's data type and how many elements it can hold.
The amount of memory used by an array depends upon the array's data type and how many elements it can hold.
Signup and view all the answers
The size of an array is the number of elements that have data stored in them.
The size of an array is the number of elements that have data stored in them.
Signup and view all the answers
Subscript numbering in C++
Subscript numbering in C++
Signup and view all the answers
The following statement is a valid C++ array definition: double money[25.00];
The following statement is a valid C++ array definition: double money[25.00];
Signup and view all the answers
Each individual element of an array can be accessed by the array name and an element number, called a subscript.
Each individual element of an array can be accessed by the array name and an element number, called a subscript.
Signup and view all the answers
An individual array element can be processed or passed to a function just like a regular C++ variable.
An individual array element can be processed or passed to a function just like a regular C++ variable.
Signup and view all the answers
The following array definition is legal because C++ allows arrays to be implicitly sized. int grades[ ];
The following array definition is legal because C++ allows arrays to be implicitly sized. int grades[ ];
Signup and view all the answers
You can assign the contents of one array to another by using
You can assign the contents of one array to another by using
Signup and view all the answers
When an array is passed to a function, it is actually ______ the array that is/are passed.
When an array is passed to a function, it is actually ______ the array that is/are passed.
Signup and view all the answers
An array can be returned by a function as well as passed to a function.
An array can be returned by a function as well as passed to a function.
Signup and view all the answers
After carrying out the following two statements, sales
will have been created as a one-dimensional array that can hold 20 double values. typedef salesArray double[20]; salesArray sales;
After carrying out the following two statements, sales
will have been created as a one-dimensional array that can hold 20 double values. typedef salesArray double[20]; salesArray sales;
Signup and view all the answers
If the scores
array is defined like this: int scores[] = {4, 7, 4, 8, 9};
, what will the following statement display: cout << scores[4];
If the scores
array is defined like this: int scores[] = {4, 7, 4, 8, 9};
, what will the following statement display: cout << scores[4];
Signup and view all the answers
To add up all the values in a two-dimensional array it would be best to use
To add up all the values in a two-dimensional array it would be best to use
Signup and view all the answers
In C++, if you attempt to store more data in an array than it can hold, the compiler will issue an error.
In C++, if you attempt to store more data in an array than it can hold, the compiler will issue an error.
Signup and view all the answers
Any of the following statements can be used to initialize the integer variable num
to 7: int num = 7; int num(7); int num{7};
Any of the following statements can be used to initialize the integer variable num
to 7: int num = 7; int num(7); int num{7};
Signup and view all the answers
On each iteration of the following range-based for loop for (int element : myArray) cout << element << endl;
, the variable element
holds
On each iteration of the following range-based for loop for (int element : myArray) cout << element << endl;
, the variable element
holds
Signup and view all the answers
The following two arrays string deptName[3] = {"Manufacturing", "Sales", "Business Office"};
and double deptBudget[3] = {200000.0, 60000.0, 50000.0};
are an example of _____ arrays.
The following two arrays string deptName[3] = {"Manufacturing", "Sales", "Business Office"};
and double deptBudget[3] = {200000.0, 60000.0, 50000.0};
are an example of _____ arrays.
Signup and view all the answers
Elements of vectors can be accessed by using the vector name and a subscript, similarly to how array elements are accessed.
Elements of vectors can be accessed by using the vector name and a subscript, similarly to how array elements are accessed.
Signup and view all the answers
If employee
is an array of objects with a public member function named setHoursWorked
, which of the following statements correctly calls that function for the employee object in array element 5?
If employee
is an array of objects with a public member function named setHoursWorked
, which of the following statements correctly calls that function for the employee object in array element 5?
Signup and view all the answers
Study Notes
Chapter 8 Test 1
- Arrays hold multiple values of the same data type.
- Array elements are accessed by their position (subscript).
- Unlike regular variables, arrays hold multiple values of the same data type, values, and variables.
- The amount of memory used by an array depends on the number of elements it can hold, not the values stored in them.
- If an array is defined as
int score[10];
thenscore[1]=100;
will not store 100 in the first element, but in the second element
Chapter 8 Test 2
- Arrays store values of the same data type.
- Subscript numbering in C++ starts at 0.
- An element of a 2D array is referenced by row number then column number.
- Arrays can be processed and passed to functions.
- Arrays can be passed to functions to function can modify the contents.
- You create a vector, you do not specify the size, it expands as you add values.
- Using the assignment operator, the contents of one array can be assigned to another array.
General C++ Array Concepts
- Arrays hold multiple values of the same data type.
- Accessing array elements using subscripts (an index).
- When passing an array to a function the address of the first element is passed.
- Arrays can be initialized with values at declaration time
- Array element values can be changed individually
- Arrays can be used to store sequences of related data.
- Copying elements from one array to another is possible
- Arrays can store primitive data types such as characters, integers, or doubles
- Arrays can store structured data like objects (structs/classes).
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your understanding of arrays in C++ with this Chapter 8 quiz. It covers fundamental concepts including array initialization, accessing elements, and the differences between arrays and regular variables. Challenge yourself with questions on both one-dimensional and two-dimensional arrays.