Header Ads Widget

Ticker

6/recent/ticker-posts

How to initialize a one dimensional array in c

 Array is a finite collection of homogeneous elements in contiguous memory locations. Here finite means fixed and finite size (Finite number of elements).

Homogenous means all elements are of same datatype .
Contiguous memory location means consecutive memory locations. i.e. the elements will be store in sequence one after another in memory.
There are various way to initialize a one dimensional array in c.
1. Individually:-
                             Let's say we have to initialize int a[5]. so in individually initialization.

2. Along with declaration:-  
                                               we can initialize an array while we declare that array (along with declaration).
Example:-  int a[5]={5,10,45,4,5};

3. Using loops:-
                            We can also initialize an array by using loop . let values is given by the user then  initialization of int a[5] is as follow..

Accessing the Array elements:-
                                                 Each element of the array is accessed using name of array along with the index of the element.
Syntax:-   Array_name[ index ];


<<Pre-- What is array                                               Practice questions on 1D array-Next>>

Recommended Post:

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

Post a Comment

0 Comments