c arrays tutorial

Bodhak c arrays tutorial in this chapter we will discuss What is an array?,  Adv and Dis Adv of arrays, Types of arrays, Working with Single Dimensional Array, Working with a numeric single dim array, Working with Multi-Dimensional arrays, 2- Dimensional Array and 3- Dimensional Array.

What is an array?

The c array is a continues memory block which can hold the data elements of the same data type. where all the elements can be referred with a common and unique name.

 

c arrays tutorial:-

Advantages :

  1. Avoiding declaration of no of variables
  2. Referring more than value with same name or grouping
  3. Increases speed of reading and writing
  4. Allows reading sequentially and randomly

Disadvantages :

  1. Fixed in size
  2. Wastage of memory

Array Properties:

Indexing of an array begins from zero (0).

The variable name of the array contains the base address of the memory block.

The array variables are created at the time of compilation and we can not alter its size during runtime.

The address held by the array variable is static.

A Single-dimensional array is a list of values of the same data type. A Single-dimensional array contains only one subscript.

A two-dimensional array contains two subscripts. Two-d arrays are stored in a row-column matrix, in the first index indicates the row & the second indicates the column.

Initializing a 2-Dimensional Array :

int num[5][2] = { {10,20},{30,40},{50,60},{70,80},{90,100} };

1)The row  left blank for a more flexible declaration. The compiler will automatically calculate the row dimension based on the number of values initialized.

2)The inner sets of curly braces are optional.

int num[ ][2] = { {10,20},{30,40},{50,60},{70,80},{90,100} };

int num[5][2] = { 10,20,30,40,50,60,70,80,90,100 };