Launch your tech mastery with us—your coding journey starts now!
Course Content
Basic Syntax and Data Types
0/2
Arrays and Strings
0/2
Structures in C
0/1
Dynamic Memory Management
0/1
Command Line Arguments
0/1
Preprocessor Directives
0/1
C Programming

What is an Array?

An array is a collection of similar data types stored in contiguous memory locations.

Example:

int marks[5] = {90, 85, 78, 92, 88};

  • Types of Arrays:
  1. One-Dimensional Array
  2. Two-Dimensional Array
  3. Multidimensional Array (rare in beginners)

 

1D Array Example:

int a[3] = {10, 20, 30};

printf(“%d”, a[1]); // Output: 20

 

  • Looping Through an Array:

for (int i = 0; i < 5; i++) {

   printf(“%d “, marks[i]);

}

  • 2D Array Example:

int matrix[2][2] = {

   {1, 2},

   {3, 4}

};

Access element:

printf(“%d”, matrix[0][1]); // Output: 2