In this tutorial section we will learn what is array and 1 Dimensional array in C Language?.
What is array in C Language?
Array: Array in C Language is useful if we have to store similar types of elements.
For example, if we want to store the marks obtained by a student in 5 different subjects, then we need to use array variable to hold the marks obtained.
If we don't use array to store the marks then we need to use five different variables to store the marks obtained by a students in different subject.
Array store the values in contiguous memory locations, Hence the array store the
the marks obtained by a student in each subject at the contiguous memory locations.
Definition: An array is defined as a group of similar elements or data items of the same type stored at contiguous memory locations.
In simple we can say that in C programming, arrays are generally used to organize the same type of data.In the C programming Language Arrays are derived data type which can store primitive data type values such as int,float,char,doble etc.
The elements in a array can be accessed randomly by using its index number.
It also used to store the collection of derived data types, such as structure,pointers etc.
By using the array, we can access the elements easily. Only a few lines of code are required to access the elements of the array.
1 D Array: One Dimensional Array in C Programming is a variable that store group of values of a single or same data type in contiguous memory location.
1-Dimensional arrays in C Programming are those arrays that have only one dimension.
In C programming, the 1d Array is a variable that can store group of values of a same data type or single data type, such as char,int, double, float, etc.
e.g.
1. List of Marks obtained by student in different subjects
marks---> 60, 70, 99, 83, 12, 56, 73, 45, 65, 44
2. Serial Number of the stuents.
srno----> 11, 34, 12, 33, 12, 15, 14, 17, 18, 19
3. Salaries of employees.
salary---> 85000, 45600.54, 87098.45, 23445, 888767.98, 4556.78 etc.
Following are some real examples/use case of Arrays
1.The arrays can be used in Matrix Operations.
2. Many RDBMS databases (small and large) are made up of Arrays i.e one-dimensional and multi-dimensional arrays.
3. Lookup table: Array can be used to create lookup table.
4.Arrays are used to sort and search data elements.
5.Arrays are used in data structure to implement stack and queues.
6.In Computer Science arrays are used to represent graphs.
7. Arrays are used to represent large data set in data mining.
8.In Robotics arrays are used o represent position and orientation of a object in 3D space.
9. Arrays are versitile enough to store a wide range of data types, including integers, characters,floating-point numbers, and even complex data structures such as pointers and objects.