All mock tests are FREE till 31 December — register to save your progress
Unit 3 · Programming Languages and Computer Graphics Paper 2 CS · December 2022 Shift 1

Which of the following are correct uses of std::string constructors?
A. string s1;
B. string s2(s1);
C. string s3{7};
D. string s4{'a'};
E. string s5{7, 'a'};
Choose the most appropriate answer from the options given below:

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: A. A, B, D, E only

Explanation

Default construction, copy construction and brace-initialisation with characters ({'a'}, and {7, 'a'} as an initializer list of chars) are standard uses. s3{7} creates a one-character string with code 7, which is not the intended 'length 7', so it is excluded in the keyed answer.

More Programming Languages and Computer Graphics questions