0% found this document useful (0 votes)
1 views

Array in C

The document provides an overview of arrays in C programming, detailing aspects such as declaration, initialization, and accessing elements. It explains the syntax for declaring arrays and emphasizes that indexing starts at 0. Additionally, it covers the use of initializer lists for initializing arrays and the memory allocation process by the compiler.

Uploaded by

Sindhu Raji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Array in C

The document provides an overview of arrays in C programming, detailing aspects such as declaration, initialization, and accessing elements. It explains the syntax for declaring arrays and emphasizes that indexing starts at 0. Additionally, it covers the use of initializer lists for initializing arrays and the memory allocation process by the compiler.

Uploaded by

Sindhu Raji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Array in C is one of the most used data structures in C programming.

It is
a simple and fast way of storing multiple values under a single name. In
this article, we will study the different aspects of array in C language such
as array declaration, definition, initialization, types of arrays, array syntax,
advantages and disadvantages, and many more.

C Array Declaration
In C, we have to declare the array like any other variable before using it.
We can declare an array by specifying its name, the type of its elements,
and the size of its dimensions. When we declare an array in C, the
compiler allocates the memory block of the specified size to the array
name.
Syntax of Array Declaration
data_type array_name [size];
or
data_type array_name [size1] [size2]...[sizeN];

where N is the number of dimensions.

Array Initialization with Declaration


In this method, we initialize the array along with its declaration. We use an
initializer list to initialize multiple elements of the array. An initializer list is
the list of values enclosed within braces { } separated b a comma.

data_type array_name [size] = {value1, value2, ... valueN};

Access Array Elements


We can access any element of an array in C using the array subscript
operator [ ] and the index value i of the element.

array_name [index];

One thing to note is that the indexing in the array always starts with 0, i.e.,
the first element is at index 0 and the last element is at N – 1 where N is
the number of elements in the array.

You might also like