int int_array[10] ; // A normal one dimensional array int int_array2d[10][10] ; // A two dimensional array
Two-dimensional array can be initialized as follows.
int array[2][2] = {{ 1, 2} , {3, 4}} ;
Here, in this example, the elements of two rows and two columns are initialized. The internal pairs of braces are not obligatory. The same array can be initialized as under.
#include <stdio.h> void printarr(int a[][]); void printdetail(int a[][]); void print_usingptr(int a[][]); main() { int a[3][2]; \ A for(int i = 0;i<3;i++) for(int j=0;j<2 ;j++) { { a[i]=i; } } printdetail(a); } void printarr(int a[][]) { for(int i = 0;i<3;i++) for(int j=0;j<2;j++) { { printf("value in array %d,a[i][j]); } } } void printdetail(int a[][]) { for(int i = 0;i<3;i++) for(int j=0;j<2;j++) { { printf( "value in array %d and address is %8u, a[i][j],&a[i][j]); } } } void print_usingptr(int a[][]) { int *b; \ B b=a; \ C for(int i = 0;i<6;i++) \ D { printf("value in array %d and address is %16lu,*b,b); b++; // increase by 2 bytes \ E } }