Computer Science, asked by harshmehto1247, 1 year ago

What is right way to Initialize array?
A.int num[6] = { 2, 4, 12, 5, 45, 5 };
B.int n{} = { 2, 4, 12, 5, 45, 5 };
C.int n{6} = { 2, 4, 12 };
D.int n(6) = { 2, 4, 12, 5, 45, 5 };

Answers

Answered by Anonymous
30
D. int n(6) = { 2,4,12,5,45,5};

Hope it helps u
Answered by dreamrob
0

Correct option is option(a) int num[6] = { 2, 4, 12, 5, 45, 5 };

  • The correct way to declare an array is that the first word is the data types of the array then the second word is the name of the array followed by the square brackets.
  • In the square brackets, we have to specify the length of our array.
  • In option(b), (c) and (d) square brackets are mission.So they are an incorrect way of initializing the array.
  • Square brackets must be used to initialize an array as in option(a).

Similar questions