Array in C
Array in C
What is Array in
C?
An array in C is a fixed-size
collection of similar data items
stored in contiguous memory
locations. It can be used to
store the collection of primitive
data types such as int, char,
float, etc., and also derived
and user-defined data types
such as pointers, structures,
etc.
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.
array_name [index];
array_name[i] = new_value;
C Array
Traversal
Traversal is the process in which
we visit every element of the data
structure. For C array traversal, we
use loops to iterate through each
element of the array.
How to use Array
in C ?
The following program
demonstrates how to use an
array in the C programming
language:
TYPES OF ARRAY IN
C
There are two types of arrays based on the number of dimensions it has. They are as
follows:
1. One Dimensional Arrays (1D Array)
2. Multidimensional Arrays
1. One
Dimensional
Array in C
The One-dimensional arrays,
also known as 1-D arrays in C
are those arrays that have only
one dimension.
Syntax of 1D Array in C
array_name [size];
Example of 1D Array in C
2. MULTIDIMENSIONAL ARRAY
IN C
Multi-dimensional Arrays in C are
those arrays that have more than one
dimension. Some of the popular
multidimensional arrays are 2D arrays
and 3D arrays. We can declare arrays
with more dimensions than 3d arrays
but they are avoided as they get very
complex and occupy a large amount of
space.
Two-
Dimensional
Array
in C is an arrayin Cexactly two
A Two-Dimensional array or 2D array
that has
dimensions. They can be visualized in
the form of rows and columns
organized in a two-dimensional plane.
Syntax of 2D Array in C
array_name[size1] [size2];
size1: Size of the first dimension.
size2: Size of the second
dimension.
Example of 2D Array in C
THANKS