Array

An Array is a collection of homogeneous items, i.e. it stores data elements having sane data type. It stores elements in contiguous memory locations.
A specific element can be accessed by an index. 

element[0] element[1] element[2] element[4] element[5]

 

Here element[0] is the first element and element[5] is the last element.
Declaring Array
In C programming we can declare a single dimensional array as follows-

type array_name [ array_size ];

Note- array_size must be a positive integer greater than zero.
Example-

Int rollno[20];

Here rollno is a variable array that can hold 20 integer numbers.
 Initializing Array

Int rollno[5] = {1, 2, 3, 4, 5 };

 As we have specified the array limit as 5 enclosed in [ ], we can only have 5 elements in the array i.e. in { }.
If we keep the [ ] empty, it can hold a large number of elements.

Int rollno[ ] = {1, 2, 3};

We can also initialize a single element at a time.

Int rollno[2] = 4;

Example of an Array in C –Output –

also see

C Programming language
Go Programming language
Linked List Array
Stack Queue
Puzzle Reasoning
Aptitude HTML
Previous articleIntroduction to HTML
Next articleLinked List

LEAVE A REPLY

Please enter your comment!
Please enter your name here