Introduction to Arrays in C Programming
Arrays in C Programming
Introduction to Arrays in C Programming
Arrays in C programming are used to store multiple values of the same data type in a single variable. Instead of creating many separate variables, arrays allow you to manage data efficiently.
Arrays are widely used in C programming for handling collections of data such as lists, marks, or numbers.
What is an Array in C Programming
An array is a collection of elements stored in contiguous memory locations. Each element is accessed using an index.
Syntax of Array Declaration
Example
This creates an array that can store 5 integers.
Initializing Arrays in C Programming
Method 1: Initialize at Declaration
Method 2: Partial Initialization
Remaining elements will be set to 0.
Method 3: Without Size
The compiler automatically determines the size.
Accessing Array Elements
Array elements are accessed using index values starting from 0.
Example
int main() {
int numbers[3] = {10, 20, 30};
printf(“%d\n”, numbers[0]);
printf(“%d\n”, numbers[1]);
printf(“%d\n”, numbers[2]);
return 0;
}
Using Loop with Arrays
Arrays are commonly used with loops to access all elements.
Example
int main() {
int numbers[5] = {1, 2, 3, 4, 5};
int i;
for(i = 0; i < 5; i++) {
printf(“%d\n”, numbers[i]);
}
return 0;
}
Taking Input in Arrays
int main() {
int arr[3], i;
for(i = 0; i < 3; i++) {
printf(“Enter value: “);
scanf(“%d”, &arr[i]);
}
for(i = 0; i < 3; i++) {
printf(“%d\n”, arr[i]);
}
return 0;
}
Advantages of Arrays in C Programming
Key Benefits
- Store multiple values in one variable
- Easy data management
- Efficient memory usage
- Simplifies code
Limitations of Arrays
Key Points
- Fixed size
- Same data type only
- Cannot dynamically resize
When to Use Arrays
Use arrays in C programming when:
- You need to store multiple values
- Data is of same type
- You want to use loops efficiently
Start Learning C Programming
Practice array programs to improve your understanding of data handling in C programming.
Summary
Arrays in C programming store multiple values of the same type. They are useful for handling large amounts of data efficiently.
FAQs
What is an array in C programming?
An array is a collection of elements stored in contiguous memory.
What is index in array?
Index is the position of an element starting from 0.
Can we change array size?
No, array size is fixed in C.
Why use arrays in C programming?
To store and manage multiple values efficiently.



