C++ Arrays Chapter 8 Quiz
40 Questions
8 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

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.

    False

    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;

    <p>False</p> Signup and view all the answers

    The statement int grades[ ] = {100, 90, 99, 80 }; is an example of

    <p>implicit array sizing.</p> Signup and view all the answers

    Which of the following statements correctly initialize the value variable?

    <p>All of the above.</p> Signup and view all the answers

    Which of the following statements will correctly carry out the operation stated in the comment to its right?

    <p>None of the above.</p> Signup and view all the answers

    By using the same _____, you can build relationships between data stored in two or more arrays.

    <p>subscript</p> 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.

    <p>a for</p> Signup and view all the answers

    Arrays can be passed to functions, but individual array elements cannot be.

    <p>False</p> Signup and view all the answers

    When an array is passed to a function, it is actually ______ the array that is passed.

    <p>the starting memory address of</p> 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.

    <p>True</p> Signup and view all the answers

    A two-dimensional array can be viewed as

    <p>any of the above.</p> Signup and view all the answers

    The elements of an array can be

    <p>any of the above.</p> 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.

    <p>True</p> Signup and view all the answers

    The following statement for(int val : myArray) cout << val << " "; is an example of a(n)

    <p>range-based for loop</p> Signup and view all the answers

    What does the following statement do? typedef int oneDArray[20];

    <p>It makes <code>oneDArray</code> an alias for a data type that holds 20 integers.</p> 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.

    <p>True</p> Signup and view all the answers

    The range-based for loop may be used with arrays, but not with vectors.

    <p>False</p> 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);

    <p>False</p> Signup and view all the answers

    An array can store multiple values, but the values must be

    <p>all the same data type.</p> 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.

    <p>True</p> Signup and view all the answers

    The size of an array is the number of elements that have data stored in them.

    <p>False</p> Signup and view all the answers

    Subscript numbering in C++

    <p>automatically begins with zero.</p> Signup and view all the answers

    The following statement is a valid C++ array definition: double money[25.00];

    <p>False</p> 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.

    <p>True</p> Signup and view all the answers

    An individual array element can be processed or passed to a function just like a regular C++ variable.

    <p>True</p> Signup and view all the answers

    The following array definition is legal because C++ allows arrays to be implicitly sized. int grades[ ];

    <p>False</p> Signup and view all the answers

    You can assign the contents of one array to another by using

    <p>none of the above.</p> Signup and view all the answers

    When an array is passed to a function, it is actually ______ the array that is/are passed.

    <p>False</p> Signup and view all the answers

    An array can be returned by a function as well as passed to a function.

    <p>True</p> 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;

    <p>False</p> 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];

    <p>9</p> Signup and view all the answers

    To add up all the values in a two-dimensional array it would be best to use

    <p>a nested for loop</p> 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.

    <p>False</p> 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};

    <p>True</p> 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

    <p>an array value.</p> 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.

    <p>parallel</p> 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.

    <p>True</p> 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?

    <p>employee[5].setHoursWorked(40);</p> 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]; then score[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.

    Quiz Team

    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.

    More Like This

    Use Quizgecko on...
    Browser
    Browser