
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Characteristics and Operations of Arrays in C Language
An array is a homogeneous sequential collection of data items over a single variable name.
For example, int student[30];
Here, student is an array name holds 30 collection of data item, with a single variable name.
Characteristics
The characteristics of arrays are as follows −
An array is always stored in consecutive memory location.
It can store multiple value of similar type, which can be referred with single name.
The pointer points to the first location of memory block, which is allocated to the array name.
An array can either be an integer, character, or float data type that can be initialised only during the declaration.
The particular element of an array can be modified separately without changing the other elements.
All elements of an array can be distinguishing with the help of index number.
Operations
The operations of an array include −
Searching − It is used to find whether particular element is present or not.
Sorting − Helps in arranging the elements in an array either in an ascending or descending order.
Traversing − Processing every element in an array, sequentially.
Inserting − Helps in inserting elements in an array.
Deleting − helps in deleting the element in an array.
Example Program
Following is the C program for searching an element in an array −
#include <stdio.h> #define MAX 100 // Maximum array size int main(){ int array[MAX]; int size, i, search, found; printf("Enter size of array: "); scanf("%d", &size); printf("Enter elements in array: "); for(i=0; i<size; i++){ scanf("%d", &array[i]); } printf("
Enter element to search: "); scanf("%d", &search); found = 0; for(i=0; i<size; i++){ if(array[i] == search){ found = 1; break; } } if(found == 1){ printf("
%d is found at position %d", search, i + 1); } else { printf("
%d is not found in the array", search); } return 0; }
Output
The output is as follows −
Enter size of array: 5 Enter elements in array: 11 24 13 12 45 Enter element to search: 13 13 found at position 3found