web123456

C++ tips (definition, initialization and assignment of arrays)

In C/C++, it can be initialized when the array is defined:

[cpp]  view plain  copy
  1. int a1[3] = {1, 2, 3};  
  2. int a2[3] = {0};                    // Assign each element of the array a2 to 0.  
  3. int a3[] = {1, 2, 3};  
  4. char s1[3] = {'a''b''c'};  
  5. char s2[] = "abc";  

  int arr[3];

arr = {10,16,8};

*Error during compilation: assigning to an array from animalizer list*/

 //You cannot assign values ​​to arrays, you can only initialize or assign values ​​to array elements.