One-Dimensional Arrays in C Programming (Complete Guide with Examples)
This tutorial explains one-dimensional arrays in C, which store multiple elements of the same data type in a single variable. It covers declaration, initialization, accessing elements, and practical examples to help beginners handle collections of data efficiently.
1. What is a One-Dimensional Array
- An array is a collection of elements of the same data type.
- One-dimensional arrays store elements in a single row.
- Elements are accessed using an index, starting from
0.
2. Syntax
data_type– type of elements (int,float,char, etc.)array_name– name of the arraysize– number of elements
Example: Declaration
3. Array Initialization
Method 1: During Declaration
Method 2: Assigning Later
Method 3: Partial Initialization
4. Accessing Array Elements
Use the index to access or modify an element:
5. Example Program: Input and Display Array Elements
Sample Output:
6. Example Program: Sum and Average of Array Elements
7. Key Points to Remember
- Array size must be a positive integer
- Indexing starts from 0
- Arrays can store only one data type
- Array elements can be input from user or initialized during declaration