Arrays in C

📘 C 👁 28 views 📅 Dec 22, 2025
⏱ Estimated reading time: 2 min

An array is a collection of elements of the same data type stored in contiguous memory locations.


Advantages of Arrays

  • Stores multiple values using a single name

  • Easy access using index

  • Reduces code size

  • Efficient data handling


Types of Arrays

  1. One-Dimensional Array

  2. Two-Dimensional Array

  3. Multidimensional Array


One-Dimensional Array

Declaration

data_type array_name[size];

Example

int a[5];

Initialization

int a[5] = {10, 20, 30, 40, 50};

Accessing Array Elements

a[0] = 10; printf("%d", a[2]);

Example Program (1D Array)

#include int main() { int a[5], i; for (i = 0; i < 5; i++) { scanf("%d", &a[i]); } for (i = 0; i < 5; i++) { printf("%d ", a[i]); } return 0; }

Two-Dimensional Array

Declaration

data_type array_name[row][column];

Example

int a[2][3];

Initialization

int a[2][3] = {{1, 2, 3}, {4, 5, 6}};

Example Program (2D Array)

#include int main() { int a[2][3], i, j; for (i = 0; i < 2; i++) { for (j = 0; j < 3; j++) { scanf("%d", &a[i][j]); } } for (i = 0; i < 2; i++) { for (j = 0; j < 3; j++) { printf("%d ", a[i][j]); } printf("\n"); } return 0; }

Array Indexing

  • Array index starts from 0

  • Last index is size - 1


Passing Arrays to Functions

void display(int a[], int n);

Limitations of Arrays

  • Fixed size

  • Stores only similar data types

  • Insertion and deletion are difficult


Summary

  • Arrays store multiple values of same type

  • Index starts from 0

  • Supports one-dimensional and multidimensional arrays

  • Useful for handling large data sets


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes