Arrays and Strings Fundamentals Quiz Quiz

Test your knowledge of basic arrays and strings manipulation concepts with these easy, practical questions. Ideal for beginners looking to reinforce key programming skills in working with sequences and text data.

  1. Finding Array Length

    What is the result of getting the length of the array [5, 9, 2, 7]?

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

    Explanation: The array [5, 9, 2, 7] contains four elements, so its length is 4. Choosing 3 would be counting one item less, and 5 would incorrectly assume an extra element. Option 7 is just one of the values in the array, not its length.

  2. String Indexing

    Given the string 'apple', what character is at index 2 if indexing starts at 0?

    1. a
    2. l
    3. p
    4. e

    Explanation: Indexing starts at 0, so 'a' is at index 0, the first 'p' at index 1, and the second 'p' at index 2. 'a' would be index 0, 'l' at index 3, and 'e' at index 4. Only 'p' at index 2 is correct.

  3. Array Element Access

    If colors = ['red', 'blue', 'green'], which value is returned by colors[1]?

    1. red
    2. yellow
    3. green
    4. blue

    Explanation: Array indices start at 0, so colors[1] refers to the second element, which is 'blue'. 'red' is the first element, 'green' is the third, and 'yellow' does not appear in the array.

  4. String Concatenation

    What is the result of concatenating 'sun' and 'flower' without any separator?

    1. sun-flower
    2. sunflower
    3. sunflower
    4. sun flower

    Explanation: Concatenating two strings without a separator joins them directly, resulting in 'sunflower'. 'sun-flower' and 'sun flower' include extra characters that were not in the original strings. 'sunflower ' incorrectly includes an extra space at the end.

  5. Reversing an Array

    What is the reverse of the array [1, 2, 3]?

    1. [1, 3, 2]
    2. [1, 2, 3, 1]
    3. [3, 2, 1]
    4. [2, 1, 3]

    Explanation: Reversing [1, 2, 3] changes the order to [3, 2, 1]. The other options present jumbled or extended arrays that do not represent a correct reversal. Only [3, 2, 1] maintains all original elements in exact reverse order.

  6. Substring Presence

    Does the word 'banana' contain the substring 'nan'?

    1. Maybe
    2. Yes
    3. No
    4. None of the above

    Explanation: 'banana' does contain 'nan' starting at the second letter. 'No' and 'Maybe' are incorrect, as the substring is clearly present. 'None of the above' is invalid given that 'Yes' is the correct answer.

  7. Finding Minimum in Array

    What is the smallest number in the array [7, 3, 5, 9]?

    1. 5
    2. 3
    3. 7
    4. 9

    Explanation: Among the array elements, 3 is the lowest value. Choosing 5, 7, or 9 ignores the minimum value present. Checking each value ensures 3 is correct beyond reasonable doubt.

  8. Splitting a String

    If you split the string 'cat,dog,mouse' by commas, how many elements will the resulting array have?

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

    Explanation: Splitting by commas divides the string into ['cat', 'dog', 'mouse'], which is three parts. Two elements would miss an item, four is too many, and one implies no splitting occurred. Three is the correct count.

  9. Joining an Array

    What is the string result of joining ['A', 'B', 'C'] with a hyphen as the separator?

    1. ABC
    2. A_B_C
    3. A-B-C
    4. A, B, C

    Explanation: Joining with a hyphen places '-' between each letter, resulting in 'A-B-C'. 'ABC' has no separators, 'A, B, C' includes spaces and commas not specified, and 'A_B_C' uses underscores instead of hyphens.

  10. Checking for Array Element

    Is the value 6 present in the array [4, 6, 8, 10]?

    1. Sometimes
    2. Not sure
    3. No
    4. Yes

    Explanation: The array [4, 6, 8, 10] clearly includes the value 6. 'No' is incorrect because it ignores the presence of 6. 'Not sure' and 'Sometimes' are not applicable, as the answer is clear from the array.