Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++

Question: 1 / 565

For struct X with a character, an integer, and a float member, which constructor call correctly initializes it using aggregate initialization?

X x1 = { 'a', 2, 3.0 }

Option B is incorrect because it uses the constructor syntax before the object name, which is not how aggregate initialization works. Option C is also incorrect because it uses the constructor syntax without an equals sign, which is not valid for aggregate initialization. Option D is incorrect because it uses the "new" keyword, which is used for dynamic allocation and not for aggregate initialization. Option A correctly initializes the struct X using aggregate initialization, which consists of using curly brackets to enclose the values for each member.

Get further explanation with Examzify DeepDiveBeta

X x1 = X('a', 2, 3.0)

X x1('a', 2, 3.0)

X x1 = new X('a', 2, 3.0)

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy