当前位置:网站首页>Initialize the one-dimensional array a correctly

Initialize the one-dimensional array a correctly

2022-06-11 02:00:00 Jihai

double arr[0];

1. There should be at least one element in the array [] Should be greater than or equal to 1;

int N=6,str[N];

2. For details, see

​​​​​​ Is it correct to declare an array like this ?int n=10,a[n]; If so ?const int n =10;int a[n];_ Ji Hai's blog -CSDN Blog
 

int a[10]=(0,0,0); 


3. You should use curly braces

int a[10]={};

4.,

Although grammatically correct , But we don't usually write that , Because of poor readability , Some people don't know , You may think it is a grammatical error , So it is generally written as follows :

int a[10]={ 0 }; / / It's an array a All elements in are assigned initial values 0.

Of course , If you write like this int a[10]={ 1 }; / / He just assigns a value to the first element of the array 1 nothing more , Other values are 0. This is a C/C++ A mechanism problem of , There is no need to delve into .

int a[10]={10*1};

5.

原网站

版权声明
本文为[Jihai]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020622358344.html