Home > Article > Backend Development > Explain the characteristics and operation methods of arrays in C language
An array is a homogeneous sequential collection of data items on a single variable name.
For example, int Student[30];
Here, student is an array name containing a collection of 30 data items with a single variable name.
The characteristics of arrays are as follows -
Arrays are always stored in contiguous memory locations.
It can store multiple values of similar type that can be referenced with a single name.
The pointer points to the first of the memory block position, which is assigned to Array name.
Arrays can be integer, character, or floating-point data types and can only be initialized during declaration.
Specific elements of an array can be modified individually without changing
All elements in the array can be distinguished by their index number.
Operations on arrays include -
Search - Used to find whether a specific element To exist or not.
Sort - Helps to sort the elements in an array in ascending or descending order.
Traverse - Process each element in the array sequentially.
Insert - Helps to insert elements in an array.
Delete - Helps to delete elements from an array.
The following is a C program for searching for elements in an array -
Real-time Demonstration
#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("</p><p>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("</p><p>%d is found at position %d", search, i + 1); } else { printf("</p><p>%d is not found in the array", search); } return 0; }
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
The above is the detailed content of Explain the characteristics and operation methods of arrays in C language. For more information, please follow other related articles on the PHP Chinese website!