Site icon TestingDocs.com

C Array Syntax

Overview

In this tutorial, we will learn the C language Array syntax. First, let’s understand the definition of an array.

What is an array?

An array is a collection of elements of the same data type. It stores a collection/group of data values. All the elements of the arrays have the same data type and are stored in consecutive memory locations.  An array in the C language has the following characteristics:

Type:- The data type of the elements stored in the array. All the elements stored in the array should have the same data type.

Name:- This indicates the name of the array.

Array Size:- This indicates the maximum number of elements that can be stored using the array.

C Array Syntax

Before using an array, it has to be declared in the C program. The declarative statement provides the following information to the C compiler.

Syntax

datatype array_name [array_size];

Example:-

int arr[10];

Here we have declared an array arr of integer type and its size is 10 which means, it can hold 10 integer values in the array.

Declaring multiple arrays syntax:

int a[10], float marks[5];

Array Index

An array index is an integer value starting at 0. Thus if an array consists of n elements. The index can range from 0 to n-1

0,1,2,3,………,n-1

 

 

Exit mobile version