Multiple choice technology programming languages

If \$string contains abcdabcd , what will the following call return? index (\$string, “cd”, 3);

  1. 6

  2. 4

  3. -1

  4. 2

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

index($string, "cd", 3) searches for cd starting from position 3 in abcdabcd. Positions 0-7: abcdabcd. From index 3, the next cd starts at index 6 (second cd). index returns the position where substring is found, making option A correct. Starting position 3 means it skips the first cd at position 2.