
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
How to access an array element in C language?
An array is a group of related data items that share a common name. A particular value in an array is identified by using its "index number" or "subscript".
The advantage of an array is as follows −
The ability to use a single name to represent a collection of items and to refer to an item by specifying the item number enables the user to develop concise and efficient programs.
The syntax for declaring array is as follows −
datatype array_name [size];
For example,
float height [50]
This declares ‘height’ to be an array containing 50 float elements.
int group[10]
This declares the ‘group’ as an array to contain a maximum of 10 integer constants.
Individual elements are identified using "array subscripts". While complete set of values are referred to as an array, individual values are called "elements".
Accessing the array elements is easy by using an array index.
Example
Following is the C program for accessing an array −
#include<stdio.h> int main(){ int array[5],i ; array[3]=12; array[1]=35; array[0]=46; printf("Array elements are: "); for(i=0;i<5;i++){ printf("%d ",array[i]); } return 0; }
Output
When the above program is executed, it produces the following result −
Array elements are: 46 35 38 12 9704368 Array[2] and array[4] prints garbage values because we didn’t enter any values in that locations
- Related Articles
- How to find minimum element in an array using linear search in C language?
- How to find minimum element in an array using binary search in C language?
- How to access elements from an array in C#?
- How to get Synchronize access to an Array in C#?
- How to access the pointer to structure in C language?
- How to send an entire array as an argument in C language?
- How to access index of an element in jQuery?
- How to access elements of an array using pointer notation in C#?
- Access an Element in Type Script
- How to remove an element from Array List in C#?
- Inserting elements in an array using C Language
- How to access elements from jagged array in C#?
- How to pass entire array as an argument to a function in C language?
- MongoDB query to access an object in an array
- How to pass individual elements in an array as argument to function in C language?
