various methods for array initialization in c 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: create n number of arrray in c

int n,i;

//enter n

int **array = malloc(sizeof(int*)*n);

for(i=0;i<n;i++)
  array[i] = malloc(sizeof(int)*64);

 /* Do Stuffs*/


/* Free Memory */  
for(i=0;i<n;i++)
  free(array[i]);

free(array);

Tags:

Java Example