A language with string manipulation facilities uses the following operations.…
2018
A language with string manipulation facilities uses the following operations.
head(s)- returns the first character of the string s
tail(s)- returns all but the first character of the string s
concat(sl, s2)- concatenates string s1 with s2.
The output of concat(head(s), head(tail(tail(s)))), where s is acbc is
- A.
ab
- B.
ba
- C.
ac
- D.
as
Attempted by 185 students.
Show answer & explanation
Correct answer: A
First, evaluate tail(tail(s)). Since s = "acbc", tail(s) returns "cbc". Applying tail again gives "bc". Next, head(tail(tail(s))) returns the first character of "bc", which is 'b'. Then, head(s) returns the first character of "acbc", which is 'a'. Finally, concat('a', 'b') results in the string "ab".
A video solution is available for this question — log in and enroll to watch it.