One Dimensional Array in C Programming
One Dimensional Array in C Programming
Introduction to One Dimensional Array in C Programming
A one dimensional array in C programming is the simplest form of an array. It is used to store a list of elements in a single row or sequence.
One dimensional arrays in C programming are widely used for storing and processing data like marks, numbers, and lists.
What is One Dimensional Array
A one dimensional array is a collection of elements of the same data type stored in contiguous memory locations and accessed using a single index.
Syntax of One Dimensional Array
Example
Initialization of One Dimensional Array
Method 1: Initialization at Declaration
Method 2: Without Size
Method 3: Partial Initialization
Remaining elements are initialized to 0.
Accessing Elements in One Dimensional Array
Each element is accessed using its index (starting from 0).
Example
int main() {
int arr[3] = {5, 10, 15};
printf(“%d\n”, arr[0]);
printf(“%d\n”, arr[1]);
printf(“%d\n”, arr[2]);
return 0;
}
Using Loop with One Dimensional Array
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int i;
for(i = 0; i < 5; i++) {
printf(“%d\n”, arr[i]);
}
return 0;
}
Input and Output in One Dimensional Array
int main() {
int arr[5], i;
for(i = 0; i < 5; i++) {
printf(“Enter element: “);
scanf(“%d”, &arr[i]);
}
printf(“Array elements are:\n”);
for(i = 0; i < 5; i++) {
printf(“%d\n”, arr[i]);
}
return 0;
}
Example: Sum of Array Elements
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int i, sum = 0;
for(i = 0; i < 5; i++) {
sum += arr[i];
}
printf(“Sum = %d”, sum);
return 0;
}
Example: Find Maximum Element
int main() {
int arr[5] = {10, 25, 5, 40, 15};
int i, max = arr[0];
for(i = 1; i < 5; i++) {
if(arr[i] > max) {
max = arr[i];
}
}
printf(“Maximum = %d”, max);
return 0;
}
Advantages of One Dimensional Array
Key Benefits
- Easy to use and implement
- Efficient data storage
- Works well with loops
- Reduces code complexity
Limitations of One Dimensional Array
Key Points
- Fixed size
- Cannot store different data types
- No dynamic resizing
When to Use One Dimensional Array
Use one dimensional array in C programming when:
- Data is linear
- You need to store similar data
- Working with lists and sequences
Start Learning C Programming
Practice one dimensional array programs to improve your data handling skills in C programming.
Summary
One dimensional array in C programming stores elements in a single sequence. It is useful for handling lists of data efficiently.
FAQs
What is one dimensional array in C programming?
It is an array that stores elements in a single row.
What is index in array?
Index represents the position of elements starting from 0.
How to find sum of array elements?
By using loop and adding all elements.
Can array store different data types?
No, arrays store same data type.



