C++ language › Array in C++ › Question #24496
Single Choice Moderate

QWhich of the following is a correct way to initialize an array?

ID: #24496 Array in C++ 45 views
Question Info
#24496Q ID
ModerateDifficulty
Array in C++Topic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A int a = {1,2,3}; ✔ ✖
  • B int a[3] = 1,2,3; ✔ ✖
  • C int a[3] = {1,2,3}; ✔ ✖
  • D int a(3) = {1,2,3}; ✔ ✖
Correct Answer

Explanation

In C++, an array must be declared with a size and initialized using curly braces { }.

int a[3] = {1, 2, 3};

This statement:

  • Declares an array of 3 integers

  • Correctly initializes all elements

Why other options are wrong

  • A) int a = {1,2,3}; ❌ → a is not an array

  • B) int a[3] = 1,2,3; ❌ → Missing { }

  • D) int a(3) = {1,2,3}; ❌ → Invalid array syntax

Correct Answer: C) int a[3] = {1,2,3};

Today: 0 answered · 0 correct
Save progress
Free account

Want to remember what you got wrong?

Create a free account in seconds to track your score, revisit mistakes and continue C++ language where you left off.

  • Save your progress & streak
  • Topic-wise quizzes & scores
  • Bookmark tricky questions
  • Printable MCQ sets
Practice smarterFree account · save progress
Sign up free

Share This Question

Challenge a friend or share with your study group.