Strings MCQ Practice

Question 1 of 10

The function substring(s, start, end) returns the characters of s from index start through index end inclusive. Indexing starts at 1. What is substring("COMPUTER", 1, 4)?

  1. A. COMP
  2. B. COM
  3. C. OMPU
  4. D. C

Question 2 of 10

What is the value of "AP" + "CSP"?

  1. A. AP + CSP
  2. B. APCSP
  3. C. APC SP
  4. D. CSPAP

Question 3 of 10

Using inclusive 1-based substring(s, start, end), what does the segment display?

word ← "ORANGE"
DISPLAY (substring(word, 2, 4))
  1. A. RA
  2. B. ORA
  3. C. RAN
  4. D. ANG

Question 4 of 10

substring is inclusive on both ends with index 1 at the first character. Which call returns "CAT" from animal ← "CATALOG"?

  1. A. substring(animal, 0, 3)
  2. B. substring(animal, 2, 4)
  3. C. substring(animal, 1, 2)
  4. D. substring(animal, 1, 3)

Question 5 of 10

Trace the segment. substring is inclusive and 1-based.

a ← "SUN"
b ← "FLOWER"
c ← a + substring(b, 1, 4)
DISPLAY (c)
  1. A. SUNFLOW
  2. B. SUNFLOWER
  3. C. SUNFLO
  4. D. FLOWERSUN

Question 6 of 10

substring(s, start, end) returns the characters from index start through index end, inclusive, with the first character at index 1. For s ← "BANANA", substring(s, 4, 6) equals which string?

Index 1 2 3 4 5 6
Char B A N A N A
  1. A. NA
  2. B. ANA
  3. C. NAN
  4. D. BAN

Question 7 of 10

What does "hi" + "" + "there" evaluate to?

  1. A. hi""there
  2. B. therehi
  3. C. hithere
  4. D. hi there

Question 8 of 10

A student wants the last three characters of code ← "XY9B12" using inclusive substring. Which call is correct?

  1. A. substring(code, 5, 6)
  2. B. substring(code, 4, 5)
  3. C. substring(code, 3, 6)
  4. D. substring(code, 4, 6)

Question 9 of 10

substring(s, start, end) returns the characters from index start through index end, inclusive, with the first character at index 1. What is displayed?

p ← "blue"
q ← "berry"
DISPLAY (substring(p, 1, 3) + q)
  1. A. bluberry
  2. B. ueberry
  3. C. blueberry
  4. D. blu berry

Question 10 of 10

Using inclusive 1-based substring, substring("EXAM", 2, 2) equals:

  1. A. EX
  2. B. X
  3. C. XA
  4. D. E