Array Basics
Array Manipulation
Functions
Array Operations
Advanced Array Concepts
100

What is the index of the first element in a C++ array

 0

100

What is the term for accessing an array element beyond its bounds?

Out-of-bounds access

array index out of bounds 

Anything out of bounds works. 

100

 What is the purpose of a function in C++?

 To group a block of code that performs a specific task 

Any of these valid:

Modularity 

Reusability

Managment of Code

etc.

100

Given an array int arr[] = {1, 5, 2, 8, 3};, what is the sum of the first and last elements?

4

100

 What is a static array?

An array whose size is fixed at compile time.

200

Declare a C++ array named numbers that can hold 5 integers

int numbers[5];
200

 Initialize a C++ array named evens with the first 5 even positive integers.

Then show me how to access the third element in the array.

int evens[5] = {2, 4, 6, 8, 10}; 

evens[3];

200

What does a function declaration specify, what is the syntax of a function declartion?

return type, The function's name,  and parameters

200

What is the value of the third element in the array float values[] = {2.5, 1.0, 7.3, 9.0};

7.3

200

What happens if you try to access an array element with an index that is out of bounds?

 It leads to undefined behavior

300

What is the index of the last element in a C++ array of size n?

Answer: n-1

300

How do you access the last element of the array int data[15];

data[14];

300

 What is the difference between a function declaration and a function definition?  

 A declaration provides the function's signature (name, return type, parameters), while a definition provides the actual code that the function executes.

300

Given the array int scores[5] = {60, 70, 80, 90, 100};, write the C++ code to change the value of the third element to 85.

scores[2] = 85;

300

int numbers[5] = {1, 2, 3, 4, 5};

numbers[2] = "hello";  

You are trying to assign a string to an integer array element.

400

True or False: When declaring an array, you must specify its size at compile time.

True

400

What is the value of numbers[2] after the following code:

 int numbers[4] = {1, 2, 3, 4};

 numbers[2] = numbers[0] + numbers[3];?

400

 What keyword is used to return a value from a function?

Answer: return

400

 Arrays can store elements of different data types.

Answer: False

400

What is the purpose of a null terminator character in a character array?

It marks the end of the string stored in the character array.

500

Write code to declare an integer array of size 5, initialize it with the values 10, 20, 30, 40, and 50, and then print each element of the array to the console, one element per line.

int myArray[5] = {10, 20, 30, 40, 50};

for (int i = 0; i < 5; i ++) {

 cout << myArray[i];

}


500

Write code to declare an integer array of size 5, initialize it with the values 1, 2, 3, 4, and 5,  Print a reversed array. (Manipulate a new array (Harder) OR just print the numbers in reverse (Easier) ).

    int originalArray[] = {10, 20, 30, 40, 50};

    const int SIZE = 5;

    int reversedArray[SIZE];

    int j = 0;

    for (int i = SIZE - 1; i >= 0; --i) {

        reversedArray[j] = originalArray[i];

        j++;

    }

500

Write a function that takes two integer arguments and returns their product.

int productFunction(int num1, int num2) {

return num1 * num2

}

500

Write code to declare an integer array of size 5, initialize it with 5 numbers and find the largest number in the array.  Print the largest number to the console.

int arr[5] = {31, 4, 20, 1, 30}

int currLargestNumber = 0;

for (int i = 0; i < 5; i++) {

if(curLargestNumber < arr[i]) {

    curLargestNumber = arr[i];

}

cout << curLargestNumber << endl;

}

500

Write code to declare two integer arrays of size 5.  Initialize the first array with the values 1, 2, 3, 4, 5, and the second array with the values 6, 7, 8, 9, 10.  Then, create a third array of size 5, and store the sum of the corresponding elements from the first two arrays in the third array.  Print the elements of the third array to the console.  For example, the first element of the third array should be 1 + 6 = 7.

~Show in Class~