Array

https://drive.google.com/file/d/1U9sYX33X1tzGqnRMbrnUuXQB8uJjbJlk/view?usp=sharing

https://drive.google.com/file/d/1f1UYWItGjVoDHo9WeLqDm7nRWLRlVePB/view?usp=sharing

https://drive.google.com/file/d/1AwqJEzzMaoQL_F9ufOQExdYWtukgc430/view?usp=sharing

https://drive.google.com/file/d/1RAwKTsnjgfyRETxpiCMuNGkIFWZtfpSm/view?usp=sharing

https://drive.google.com/file/d/13fcVGyU0koFNKebqKrIw2EzuWNn_PawE/view?usp=sharing

 PST-pdf                    Instagram                              Twitter                        YouTube

{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{

}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}

--------------------------------------------------------------------------------------------------------------------

1. INTRODUCTION  PST-PDF

-------------------------------------------------------------------------------------------------------------------

2. OPERATORS   PST-pdf

-------------------------------------------------------------------------------------------------------------------

3. LOOPING  PST-pdf

------------------------------------------------------------------------------------------------------------------

4. CONDITIONAL  PST-pdf

------------------------------------------------------------------------------------------------------------------

5. JUMPING STATEMENTS PST-pdf

------------------------------------------------------------------------------------------------------------------

6. ARRAY

------------------------------------------------------------------------------------------------------------------

6.1 Array

In C language, arrays are referred to as structured data types. An array is defined as finite ordered collection of homogenous data, stored in contiguous memory locations.


Here the words,
✔ Finite means data range must be defined.
✔ Ordered means data must be stored in continuous memory addresses.
✔ Homogenous means data must be of similar data type.

Example where arrays are used,
✔ To store list of Employee or Student names,
✔ To store marks of students,
✔ To store list of numbers or characters etc.
✔ Since arrays provide an easy way to represent data, it is classified amongst the data structures in C. Other data structures in c are structure, lists, queues, trees etc. Array can be used to represent not only simple list of data but also table of data in two or three dimensions.

Declaring an Array
Like any other variable, arrays must be declared before they are used. General form of array declaration is,

data-type variable-name[size];

/* Example of array declaration */
int arr[10];
Here int is the data type, arr is the name of the array and 10 is the size of array. It means array arr can only contain 10 elements of int type.

Index of an array starts from 0 to size-1 i.e first element of arr array will be stored at arr[0] address and the last element will occupy arr[9].

For Programming Training:
DM me Instagram

6.2 Array Initialization

Initialization of an Array 
After an array is declared it must be initialized. Otherwise, it will contain garbage value(any random value). An array can be initialized at either compile time or at runtime.

Compile time Array initialization 
Compile time initialization of array elements is same as ordinary variable initialization. The general form of initialization of array is,

data-type array-name[size] = { list of values }; 

Here are a few examples 
int marks[4]={ 67, 87, 56, 77 }; 
// integer array initialization 

float area[5]={ 23.4, 6.8, 5.5 }; 
// float array initialization 

int marks[4]={ 67, 87, 56, 77, 59 }; 
// Compile time error 

One important thing to remember is that when you will give more initializer(array elements) than the declared array size than the compiler will give an error.

For Programming Training:
DM me Instagram

6.3 Runtime Array initialization
✔ An array can also be initialized at runtime using scanf() function.
✔ This approach is usually used for initializing large array, or to initialize array with user specified values.


For Programming Training:
DM me Instagram

6.4 2D Array
C language supports multidimensional arrays also. The simplest form of a multidimensional array is the two-dimensional array. Both the rows and columns index begins from 0.

Two-dimensional arrays are declared as follows,

data-type array-name[row-size][column-size] 

/* Example */
int a[3][4];

An array can also be declared and initialized together. For example,

int arr[][3] = {
{0,0,0},
{1,1,1}
};

Note: 
✔ We have not assigned any row value to our array in the above example. 
✔ It means we can initialize any number of rows. 
✔ But, we must always specify number of columns, else it will give a compile time error. 
✔ Here, a 2*3 multi-dimensional matrix is created.


For Programming Training:
DM me Instagram

6.5 Characteristics of an Array

Array Characteristics
An array is defined as the group of similar data types, which takes contiguous memory locations. Array stores same kind of data.

Its just normal definition, which you can find anywhere. Here, we are discussing some of the characteristics of an array data type.

✔ An array is a derived data type, which is defined using basic data types like int, char, float and even structures (which is called the array of structures).
✔ Array elements are stored in contiguous memory blocks/subsequent memory blocks in primary memory.
✔ Array name represents its base address. The base address is the address of the first element of the array.
✔ Array index starts with 0 and ends with N-1. Here, N stands for the number of elements. For Example, there is an integer array of 5 elements, then it’s indexing will be 0 to 4.
✔ Only constants and literal values (an integer value like 5, 10, 12,…) can be assigned the number of elements in an array.
✔ While declaring an array, we can also assign each element with 0 like this.

Like: int age[10]={0};

✔ There is no need to provide the number of elements while declaring an array, but we have to provide the values at the time of declaration. In this case, array size will be the number of values that you have provided.

Like: int age[]={21,22,25,45,56};

Here, size of the array will be 5, because there are 5 values.
✔ An array can be allocated anywhere in these memory permanents:
A) Data segment for static or globally declare array
B) Heap segment for dynamically allocated array
C) Stack segment for locally declare array


For Programming Training:
DM me Instagram

---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
BCA                                        PST & Programming C                                   Allrounder Sita Ram Sahu
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
>

No comments:

Post a Comment