CS 11 SHIT QUIZ8

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/18

encourage image

There are no tags or description

Looks like no tags are added yet.

19 Terms

1
New cards

Know the definition of a structured data type.

A structured data type is a data type that is a collection of individual components. An array is a structured data type with a fixed number of components, all of which are of the same data type.

2
New cards

Know the definition of an n-dimensional array.

An n-dimensional array is a collection of a fixed number of elements arranged in n dimensions (n ≥ 1).

3
New cards

Know all the ways a one-dimensional array and two-dimensional array can be declared and initialized in C++.

1D Declaration: dataType arrayName[size]; Example: int numbers[5]; 1D Initialization: int numbers[5] = {1, 2, 3, 4, 5}; The size can also be omitted when initializing: int numbers[] = {1, 2, 3, 4, 5}; 2D Declaration: dataType arrayName[rows][columns]; Example: int board[2][3]; 2D Initialization: int board[2][3] = {{1, 2, 3}, {4, 5, 6}};. The first dimension can be omitted when initializing a 2D array, but the second dimension must be specified. Unspecified numeric elements are initialized to 0.

4
New cards

Given the number of elements in an array, know the correct range of index values of the array.

An array index starts at 0 and ends at N - 1, where N is the total number of elements. Example: An array with 5 elements has valid indices 0, 1, 2, 3, and 4.

5
New cards

Given the declaration of an array, be able to determine how many elements (components) are in the array.

1D Array: The number of elements equals its declared size. 2D Array: Multiply the number of rows by the number of columns. Example: int board[4][3]; contains 4 × 3 = 12 elements.

6
New cards

Know how to access a particular element of both a one-dimensional array and a two-dimensional array.

1D Array: Use one index: arrayName[index]. Example: numbers[2]. 2D Array: Use two indices: arrayName[row][column]. Example: board[1][2]. The first index represents the row, and the second represents the column.

7
New cards

Know what symbols are used to contain an index value of an array.

Square brackets [ ] are used to contain array index values. Example: numbers[3].

8
New cards

Know what happens to a C++ program when an array index goes out of bounds.

An out-of-bounds index accesses an element outside the valid array range. This causes undefined behavior in C++, meaning the program may produce incorrect results, crash, or behave unpredictably. C++ does not automatically check array bounds.

9
New cards

Know what is actually passed to the formal parameter when an array is passed to a function in C++.

The base address (memory address of the first element) of the array is passed. The array name typically decays into a pointer to its first element. For a 2D array, the number of columns must be specified in the formal parameter.

10
New cards

Know if arrays can be passed by value or by reference to a function.

Built-in C++ arrays cannot be passed by value as whole arrays. When passed to a function, they decay into pointers to their first elements. Changes made through the parameter can affect the original array. Arrays can also be passed by reference using reference parameter syntax.

11
New cards

Know if a function can return a value of type array in C++.

No, a C++ function cannot directly return a built-in array type. However, it can return an array indirectly using alternatives such as a std::array, std::vector, or a pointer.

12
New cards

Know how to prevent a C++ function from modifying an array passed to it as a parameter.

Use the const keyword in the formal parameter. Example: void printArray(const int list[], int size). The const keyword prevents the function from modifying the array elements through that parameter.

13
New cards

Know how to use a range-based for loop to initialize an array in C++.

A range-based for loop accesses each element of an array without using an index. Example: for (int &x : numbers) { cin >> x; }. The reference (&) allows each element of the original array to be modified or initialized.

14
New cards

Know how to use the strcpy, strcmp, and strlen function with C-strings.

C-strings are stored in character arrays and end with a null character (\0). strcpy(destination, source): Copies one C-string into another. strcmp(string1, string2): Compares two C-strings and returns 0 if they are equal, a negative value if the first is smaller, or a positive value if the first is greater. strlen(string): Returns the number of characters in a C-string, excluding the null character. These functions are available through the header.

15
New cards

Know when C++ allows aggregate operations.

Basic aggregate operations such as assignment, comparison, and input/output are allowed on standard C++ string objects. Built-in arrays do not support direct whole-array assignment or comparison. Their elements must be processed individually or using appropriate functions.

16
New cards

Know how to use the get function to read C-strings.

cin.get(arrayName, size) reads characters into a character array, including spaces, until a newline is encountered or the size limit is reached. The newline is not stored, and a null character (\0) is added to terminate the C-string. Example: cin.get(name, 50);

17
New cards

Know what the null character is.

The null character (\0) is used to terminate C-strings in character arrays. It indicates the end of the string.

18
New cards

Know what is meant by row-order form.

Two-dimensional arrays are stored in memory in row-order form (row-major order). This means all elements of the first row are stored sequentially, followed by all elements of the second row, and so on.

19
New cards

Know how to simplify accessing all members of a namespace.

Use the using namespace directive. Example: using namespace std; This allows you to access all members of the std namespace without repeatedly writing std:: before each member. Alternatively, using std::cout; allows you to access only cout without the namespace prefix.