Word Count: 208
  • Post category:C
  • Post last modified:2023-01-03

Reference

Tutorial Point – C Tutorial

Array

Basically a collection of variables of the same type.

All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.

Declaring Arrays

Specifies the type of the elements and the number of elements required by an array as follows −

type arrayName [ arraySize ];

This is a single-dimensional array.

Initializing Arrays

Array can be initialized

  • one by one element,
  • or using a single statement –
double balance[] = {1000.0, 2.0, 3.4, 7.0, 50.0};  //note: curely brackets are used here

Accessing Array Elements

An element is accessed by indexing the array name. This is done by placing the index of the element within square brackets after the name of the array. For example −

double salary = balance[9];

Array in Detail

Sr.No.Concept & Description
1Multi-dimensional arrays

C supports multidimensional arrays. The simplest form of the multidimensional array is the two-dimensional array.
2Passing arrays to functions

You can pass to the function a pointer to an array by specifying the array’s name without an index.
3Return array from a function

C allows a function to return an array.
4Pointer to an array

You can generate a pointer to the first element of an array by simply specifying the array name, without any index.