Wednesday, October 21, 2015

Arrays in C programming language



                Hey fellas! Now, I still want to explain about C programming language. And for this time, I will explain about ARRAYS!!! Yeay! Check this out!
In C programming language, sometimes when we make a program, there is problem to handle similar type of data. We can solve that problem with arrays. Array is used to store collection of data in data structure. An array is a sequence of data item of the same type value. All arrays data consist of contiguous memory locations. The highest address corresponds to the last data and the lowest address corresponds to the first data.
Arrays have two types, there are:
1.       One-dimentional arrays
2.       Multi-dimentional arrays
One-dimentional arrays
Declaration of one-dimentional array is:
                Data_type array_name[array_size];
Array elements:
As I mentioned in beginning, size of the arrays defines the numbers of data in array.
This is way how to display array elements with addresses.

The output will show the values and the addresses of the array elements.

Initialization of one-dimentional arrays:
                Int i[5] = { 1, 2,  3, 4, 5}
Multi-dimentional arrays
Declaration of multi-dimentional arrays is:
                Type_name[size1][size2]...[sizeN];
Initialization of multi-dimentional arrays:
                Int c[1][2] = {{ 1, 2, 3}, { 4, 5, 6}};
                Int c[][2] = {{ 1, 2, 3}, { 4, 5, 6}};
                Int c[1][2] = { 1, 2, 3, 4, 5, 6};
                double cprogram [1][2][3] = {{ 1, 2, 3, 4}, { 5, 6, 7, 8}, { 9, 10, 11, 12}, { 13, 14, 15, 16}};
Okay! That’s all for array. Don’t forget to try it by yourself yaa ;) Have a great tim with coding, guys!