array Cpp code example
Example 1: how to make an array c++
int foo [] = { 16, 2, 77, 40, 12071 };
Example 2: array declaration c++
int foo [5];
Example 3: array in c++
int a[2][3]= {
{1, 2, 3},
{4, 5, 6}
};
cout << a[1][1];
int a[2][3][2]= {
{ {1, 2},
{2, 3},
{4, 5}
},
{ {6, 7},
{8, 9},
{10, 11}
}
};
cout << a[0][1][1];
Example 4: creare array con c++
#include <iostream>
int main()
{
int myArray[] {2, 4, 6, 8, 10};
for (int i=0; i<5; i++)
{
std::cout << "index: " << i << " - value: " << myArray[i] << "\n";
}
return 0;
}
Example 5: array c++
#include <iostream>
#include <array>
int main() {
std::array<int, 10> arr;
arr[0] = 5;
std::cout << arr[0] << std::endl;
std::cout << arr.at(0) << std::endl;
}
Example 6: declare static table filled cpp
int intergerTable[6] = {1, 2, 3, 4, 5, 6};