Podcast
Questions and Answers
Unlike regular variables, arrays can hold multiple
Unlike regular variables, arrays can hold multiple
- variables.
- data types.
- values. (correct)
- named constants.
- operators.
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 (B)
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
- value.
- subscript. (correct)
- size declarator.
- data type.
- name.
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;
The statement int grades[ ] = {100, 90, 99, 80 };
is an example of
The statement int grades[ ] = {100, 90, 99, 80 };
is an example of
Which of the following statements correctly initialize the value variable?
Which of the following statements correctly initialize the value variable?
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?
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.
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.
Arrays can be passed to functions, but individual array elements cannot be.
Arrays can be passed to functions, but individual array elements cannot be.
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.
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.
A two-dimensional array can be viewed as
A two-dimensional array can be viewed as
The elements of an array can be
The elements of an array can be
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.
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)
What does the following statement do? typedef int oneDArray[20];
What does the following statement do? typedef int oneDArray[20];
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.
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.
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);
An array can store multiple values, but the values must be
An array can store multiple values, but the values must be
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.
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.
Subscript numbering in C++
Subscript numbering in C++
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];
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.
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.
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[ ];
You can assign the contents of one array to another by using
You can assign the contents of one array to another by using
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.
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.
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;
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];
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
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.
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};
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
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.
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.
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?
Flashcards
Array vs. Regular Variables
Array vs. Regular Variables
Arrays store multiple values of the same data type, while regular variables store single values.
Array Memory Usage
Array Memory Usage
The amount of memory an array uses depends on the number of elements, not just their type.
Accessing Array Elements
Accessing Array Elements
You access array elements using their position (subscript), not their names.
Array Declaration and Initialization
Array Declaration and Initialization
Signup and view all the flashcards
Implicit Array Sizing
Implicit Array Sizing
Signup and view all the flashcards
Array Initialization Techniques
Array Initialization Techniques
Signup and view all the flashcards
Initializing Variables
Initializing Variables
Signup and view all the flashcards
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.