array initialization code example

Example 1: c array initialization

int x[] = {1,2,3}; // x has type int[3] and holds 1,2,3
int y[5] = {1,2,3}; // y has type int[5] and holds 1,2,3,0,0
int z[3] = {0}; // z has type int[3] and holds all zeroes

Example 2: java array initialization

int[] data = {10,20,30,40,50,60,71,80,90,91};

// or

int[] data;
data = new int[] {10,20,30,40,50,60,71,80,90,91};

Example 3: c++ initialise array

int nCount[] = {1, 2, 3, 4, 5};

Example 4: how to initialize an array in c

double balance[5] = {1000.0, 2.0, 3.4, 7.0, 50.0};

Tags: