82.0k views
2 votes
What is the output of the code snippet given below?string s = "abcde";int i = 1;while (i < 5){ cout << s.substr (i, 1); i++;}a. no outputb. abcdc. abcde d. bcde

User Mohitt
by
5.6k points

1 Answer

2 votes

Answer:

The answer is "Option d".

Step-by-step explanation:

In the given C++ program code, two-variable is defined, that is "s and i", in which variable s is a string type that holds a value, that is "abcde", and variable i is an integer type, that holds a value '1'.

  • In the next line, a while loop is declared, that uses integer variable which value is less than 5, inside a loop a substring function is used, that specifies the number of character and return its value.
  • In array and string indexing starts from 0, and that variable i starts from 1, that is used in substring function, that's why it will print only "bcde".
User Yam Marcovic
by
6.4k points