AP CSA arrays key terms

Essential key terms related to arrays for AP Computer Science A, designed for quick study and review.

OtterSophia5·23 flashcards·21 vragen
APcomputer_scienceprogramming
0
Ken ik
1 / 23
0
Aan het leren
Voorkant

What is an array?

Tik om om te draaien
Achterkant

An array is a collection of elements, all of the same type, stored at contiguous memory locations.

Tik om om te draaien
Ken ik
Aan het leren

Quiz(21 vragen)

Vraag 1 van 21

1. What is the default value of a boolean array element?

Termen in deze set(23)

What is an array?

An array is a collection of elements, all of the same type, stored at contiguous memory locations.

True or false: Arrays can store different data types.

False, because arrays are homogeneous and must contain elements of the same type.

Define the index of an array.

The index refers to the position of an element in an array, starting from 0.

Difference between 1D and 2D arrays.

1D arrays are linear lists, while 2D arrays are grids (rows and columns).

What is the length property of an array?

The length property returns the number of elements in an array.

Fill in the blank: An array is initialized using ________.

Array literal syntax or the 'new' keyword.

Accessing an element at index 3 of an array?

Use arrayName[3] to access the fourth element.

What does 'arrayName.length' return?

It returns the total number of elements in the array.

True or false: Arrays can be resized after creation.

False, because arrays have a fixed size once initialized.

What happens when you access an out-of-bounds index?

It throws an ArrayIndexOutOfBoundsException at runtime.

Difference between an array and an ArrayList.

Arrays have a fixed size; ArrayLists can dynamically resize.

What is a multi-dimensional array?

An array that contains arrays as its elements, e.g., a 2D array.

How to declare an integer array?

int[] arrayName = new int[size]; or int[] arrayName = {value1, value2};

What is the default value of an uninitialized int array?

All elements are initialized to 0 by default.

Fill in the blank: The first element of an array is at index ________.

0.

How do you loop through an array?

Use a for loop: for (int i = 0; i < array.length; i++) {...}

True or false: Arrays can hold primitive data types.

True, because arrays can store any type, including primitives.

What is an array initializer?

Syntax used to initialize an array at the time of declaration.

What is the output of array[0] if array = new int[]{1,2,3}?

The output will be 1, the first element of the array.

Describe how to pass an array to a method.

Declare the parameter as the same type: 'void methodName(int[] array)'.

What is a jagged array?

An array of arrays where each sub-array can have different lengths.

Difference between static and dynamic arrays.

Static arrays have fixed sizes; dynamic arrays can change size.

Fill in the blank: An array's elements can be accessed using the ________ operator.

Index operator [].

Vragen in deze set(21)

1. What is the default value of a boolean array element?

A.true
B.false
C.null
D.0

2. Which of the following correctly declares a 2D array?

A.int[][] array;
B.int array[][];
C.Both A and B
D.int array[];

3. What will happen if you try to access array[5] in an array of size 5?

A.Returns 0
B.Throws an exception
C.Returns null
D.Returns an error message

4. What statement initializes an array with values?

A.int[] arr = new int[5];
B.int[] arr = {1, 2, 3};
C.int arr[];
D.int arr = new int[5]{1, 2, 3};

5. Which method can change the size of an array?

A.resize()
B.setSize()
C.changeSize()
D.None of the above

6. In which scenario would you use an ArrayList instead of an array?

A.When size is constant
B.When size is unknown
C.When elements are all of the same type
D.When performance is critical

7. What will be the output of array[1] if array = new int[]{5, 10, 15}?

A.5
B.10
C.15
D.ArrayIndexOutOfBoundsException

8. Which keyword is used to create a new array?

A.new
B.array
C.create
D.init

9. What is the main advantage of a jagged array?

A.Easier to manage
B.Less memory usage
C.Flexible sizing of sub-arrays
D.Faster access speed

10. Which of the following is NOT a way to initialize an array?

A.int[] arr = new int[5];
B.int arr[] = new int[5]{1, 2};
C.int[] arr = {1, 2};
D.int[] arr = new int[]{1, 2};

11. What does array.length represent?

A.The last index
B.The number of elements
C.The first element
D.None of the above

12. How do you call a method that takes an array as a parameter?

A.methodName(int array)
B.methodName(int[] array)
C.methodName(array)
D.methodName(int array[])

13. Which array declaration is correct?

A.int arr[];
B.int[] arr;
C.Both A and B
D.None of the above

14. What is a common use of arrays in programming?

A.Storing multiple values
B.Creating classes
C.Managing threads
D.None of the above

15. What would array[0] return in a String array with 'hello', 'world'?

A.hello
B.world
C.ArrayIndexOutOfBoundsException
D.null

16. Which statement is true about arrays?

A.They can change size
B.They can store multiple data types
C.They are indexed from 1
D.They are zero-based indexed

17. What is the output of array[2] for array = new int[]{3, 6, 9}?

A.3
B.6
C.9
D.ArrayIndexOutOfBoundsException

18. How do you create a jagged array?

A.int[][] jagged = new int[3][];
B.int jagged[][];
C.int jagged[] = new int[3][4];
D.None of the above

19. Which statement correctly initializes a 1D array?

A.int arr[5];
B.int[] arr = new int(5);
C.int[] arr = new int[5];
D.None of the above

20. What is the result of trying to access array[-1]?

A.Returns 0
B.Returns null
C.Throws an ArrayIndexOutOfBoundsException
D.Returns an error message

21. When would you use an array instead of a List?

A.When the number of elements is fixed
B.When performance is critical
C.Both A and B
D.Never

Gerelateerde sets

Maak je eigen studieset

Upload een PDF, plak je notities of beschrijf een onderwerp – AI genereert flashcards, quizzen en meer in seconden.