arrays en c++ code example

Example 1: how to make an array c++

int foo [] = { 16, 2, 77, 40, 12071 };

Example 2: create array c++

int foo[5] = {0};

Example 3: array c++

// An example of using std::array
// Basic syntax: std::array<TYPE, SIZE> NAME;
// Note that the size must be a constant

#include <iostream>
#include <array> // Use std::array

int main() {
	std::array<int, 10> arr;
  	arr[0] = 5; // Setting an element
  	std::cout << arr[0] << std::endl; // Element access
  	std::cout << arr.at(0) << std::endl; // Element access with bounds checking
}

Example 4: array syntax in c++

int bar [5] = { 10, 20, 30 };

Tags:

Cpp Example