maxresdefault

An array is a collection of similar data type value in a single variable. It is a derived data type in C, which is constructed from fundamental data type of C language.

screenshot_13

Advantages of Array

  • Code Optimization: Less code is required, one variable can store numbers of value.

  • Easy to traverse data: By using array easily retrieve the data of array.

  • Easy to sort data: Easily short the data using swapping technique

  • Random Access: With the help of array index you can randomly access any elements from array.

Dis-Advantage of Array

Fixed Size: Whatever size, we define at the time of declaration of array, we can not change their size, if you need more memory in that time you can not increase memory size, and if you need less memory in that case also wastage of memory.

different-types-of-the-array-in-c-programming-language

Single Dimensional Array

Declaring Array

To declare an array in C you need to declare datatype and size of an array.

Syntax

screenshot_14

Example

screenshot_15

Initializing Array

Initializing is a process to initialize the value in array variable. This is happen in two ways, initialize array one by one or all elements are initializing once.

screenshot_17

Accessing Array Elements

We can access array elements with the help of index value of element.

Example

screenshot_16

Program For One Dimensional Array

one-d-array-program

Output

one-d-array-output

Multi Dimensional Array

  • ->In 2-dimentional elements are arranged in row and column format.

  • ->When we are working with 2-dimentional array we require to refer 2-subscript operator which indicates row and column sizes.

  • ->The main memory of 2-dimentional array is rows and sub-memory is columns.

  • ->On 2-dimentional array when we are referring one-subscript operator then if gives row address, 2-subscript operator will gives element.

  • ->On 2-dimentional array arrayName always gives main memory that is 1st row base address, arrayName will gives next row base address.

Syntax

screenshot_18

two-d-chart

two-d-chart-2

Program

two-d-program

Output

two-d-program