-2
int fr[10]{}

I seen this declaration in C++ is this 1-D array or it is 2-D. Which type of declaration it is?

usaka
  • 11
  • 3
  • Should be easy enough to find out if compile this code? – Pranav Hosangadi Nov 12 '22 at 18:03
  • @PranavHosangadi I found it to be 2-D but don't know about such declaration. – usaka Nov 12 '22 at 18:05
  • 2
    It's same as `int fr[10];`, but with the elements zeroed. `{...}` or `= {...}` can contain a list of initializers for individual elements, and the remaining elements are zeroed (since the list is empty, all elements are zeroed here). – HolyBlackCat Nov 12 '22 at 18:10
  • 1
    @usaka *I found it to be 2D* Not sure how you decided that, because it's 1D. E.g. `fr[0]` is OK, but `fr[0][0]` is an error. – john Nov 12 '22 at 18:13
  • Same as `int fr[10]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };` – Eljay Nov 12 '22 at 19:37

1 Answers1

0

C++ since its version 11 has introduced in its standard the use of curly brackets for the initialization of objects.

Here are some examples:

MyObjects obj {};
MyObjects obj {firstParameter};
int array[10] {};

In the latter case, it refers to the fact that it will contain 10 elements initialized as zero in it. In the case of the standard types you will see what was written in the memory cell first

Here you will find a precise explanation of all this

StellarClown
  • 160
  • 8