Arrays and String Manipulation Essentials Quiz Quiz

Challenge your understanding of arrays and fundamental string manipulation concepts with this easy-level quiz featuring practical scenarios, common operations, and essential terminology. Perfect for learners seeking to strengthen their grasp of array structures, indexing, iteration, and basic string handling techniques.

  1. Accessing Array Elements

    In an array defined as [10, 15, 20, 25], which value is at index 2?

    1. 20
    2. 15
    3. 25
    4. 10

    Explanation: The value at index 2 in a zero-based array is 20, because indexing starts at 0. The values at indexes 0 and 1 are 10 and 15 respectively. Option 25 is at index 3, and 10 is at index 0, making them incorrect choices.

  2. String Length

    If the string is 'apple', what is its length?

    1. 8
    2. 4
    3. 5
    4. 6

    Explanation: The string 'apple' has 5 characters, so its length is 5. Option 4 would be correct if there were one less character. Option 6 and 8 are both too high for this simple word. Only '5' matches the correct character count.

  3. Combining Arrays

    What is the process of joining two arrays, such as [1, 2] and [3, 4], into one called?

    1. Looping
    2. Merging
    3. Splitting
    4. Sorting

    Explanation: Merging is the process of combining two arrays into one larger array. Splitting is the opposite, which divides an array. Looping means iterating over elements, while sorting rearranges values. Only merging correctly describes joining arrays.

  4. String Concatenation

    Which term describes joining the strings 'cat' and 'nap' to get 'catnap'?

    1. Shuffling
    2. Reversing
    3. Slicing
    4. Concatenation

    Explanation: Concatenation means joining two strings end-to-end, forming 'catnap' from 'cat' and 'nap'. Reversing would flip character order, and shuffling rearranges them randomly. Slicing refers to extracting a part of the string, so 'concatenation' is the correct answer.

  5. Finding Elements in Arrays

    Given the array [5, 7, 9], how would you identify if the number 7 is present?

    1. By merging
    2. By sorting
    3. By searching
    4. By slicing

    Explanation: To check if a value exists in an array, you search for it. Sorting changes order, slicing extracts a subarray, and merging combines arrays. Only searching is used for finding elements.

  6. Updating Array Elements

    How do you change the second value in [18, 22, 35] to 30?

    1. Replace index 2
    2. Replace index 0
    3. Replace index 3
    4. Replace index 1

    Explanation: The second value is at index 1 in a zero-based array. Index 0 changes the first value, index 2 alters the third, and index 3 is out of bounds. Therefore, you must replace the value at index 1.

  7. Splitting Strings

    What does splitting the string 'dog,cat,mouse' by the comma result in?

    1. A string of spaces
    2. A sorted array
    3. An array with three words
    4. A reversed string

    Explanation: Splitting by a comma divides the string into an array with three elements: 'dog', 'cat', and 'mouse'. A string of spaces would require replacing characters, not splitting. Reversing would flip the order of characters, and sorting needs an array, not a string.

  8. Removing Array Elements

    What is it called when you take out the last item from an array?

    1. Prepending
    2. Popping
    3. Appending
    4. Shifting

    Explanation: Popping removes the last element of an array. Appending adds to the end, prepending adds to the start, and shifting removes the first element. Only popping matches removing the last element.

  9. Strings Are Immutable

    Why can you not change the third letter of 'bird' directly?

    1. Arrays store numbers only
    2. Strings are immutable
    3. Characters cannot be accessed
    4. Strings have flexible size

    Explanation: Strings are immutable, so their characters can't be changed in place. Flexible size isn't the issue; arrays can store other types, not just numbers, and characters can be accessed but not altered directly. Mutability is the key property limiting changes.

  10. Array Length

    What is the length of the array ['x', 'y', 'z', 'a']?

    1. 4
    2. 2
    3. 3
    4. 5

    Explanation: There are four elements in the array, so its length is 4. The answers '2' and '3' are less than the actual count, while 5 is greater. Only '4' matches the total number of elements.

  11. String Indexing

    For the string 'math', what is the character at index 2?

    1. t
    2. a
    3. h
    4. m

    Explanation: Indexing starts at 0, so index 2 is the third character, which is 't'. 'm' is at index 0, 'a' is at index 1, and 'h' is at index 3. Only 't' matches.

  12. Joining Array Elements into a String

    Which operation combines ['red', 'blue'] into 'redblue'?

    1. Joining
    2. Splitting
    3. Mapping
    4. Filtering

    Explanation: Joining merges array elements into a single string. Splitting does the opposite, mapping changes items, and filtering removes some elements. Only joining results in 'redblue' from the original array.

  13. Array Slicing

    If you slice [4, 6, 8, 10] from index 1 to 3 (excluding 3), what is the result?

    1. [6, 8, 10]
    2. [4, 6]
    3. [8, 10]
    4. [6, 8]

    Explanation: Slicing from index 1 up to, but not including, index 3 produces [6, 8]. [4, 6] includes the first element, and [6, 8, 10] goes beyond index 3. [8, 10] starts too late. Only [6, 8] matches the specified range.

  14. Checking String Substrings

    Does 'basketball' contain the substring 'ball'?

    1. Only if changed to 'baseball'
    2. Only if reversed
    3. No
    4. Yes

    Explanation: 'ball' is found within 'basketball' without any modifications. The string doesn't need to be changed or reversed. The only correct answer is 'Yes', as the substring clearly exists.

  15. Array Iteration

    What do you call processing each value in an array one by one?

    1. Iterating
    2. Concatenating
    3. Merging
    4. Sorting

    Explanation: Iterating means going through each element individually. Merging combines arrays, sorting changes their order, and concatenating joins either arrays or strings. Only iterating correctly matches the action described.

  16. Case Changing in Strings

    What is the result of converting 'Train' to lowercase?

    1. TRAIN
    2. Train
    3. tRAIN
    4. train

    Explanation: 'Train' in lowercase becomes 'train', with all letters small. 'TRAIN' uses all uppercase, 'Train' preserves the original case, and 'tRAIN' is incorrect. Only 'train' accurately shows the transformation.