C Arrays

C Tutorial

 C Arrays (Complete Tutorial: Beginner → Advanced)

In C language, an array is a collection of multiple values of the same data type stored in contiguous memory locations.
Arrays are fundamental for DSA, system programming, embedded systems, and interviews.


 What is an Array?

An array stores multiple values using a single variable name.

Example

  • marks → array name
  • 5 → number of elements
  •  Index starts from 0

Why Use Arrays?

  •  Store large data efficiently
  •  Easy data processing using loops
  •  Reduces code repetition
  •  Improves performance
  •  Basis of DSA (sorting, searching)

Array Declaration

Syntax

Examples


Array Initialization

Method_1: At Declaration

Method_2: Size Automatically Calculated

Method_3: Partial Initialization


Accessing Array Elements


 

  • Index range: 0 to size-1

Array Traversal Using Loop


 

  • Most common operation

 Taking User Input in Array


 

  •  Used in exams & interviews

 Types of Arrays

 One-Dimensional Array

int a[5];

 Two-Dimensional Array (2D)

int a[2][3];

 Multidimensional Array

int a[2][3][4];

Arrays and Functions

Passing Array to Function

  •  Array is passed by reference

Size of an Array (Important)

  •  Works only in the same scope
  • Not inside function

Arrays and Pointers


 

  •  Array name acts as pointer to first element

 Common Array Operations

Sum of Elements

Find Maximum

Reverse Array


 Limitations of Arrays

  •  Fixed size
  •  Cannot grow dynamically
  •  Stores only same data type

Solved using dynamic memory & structures


Common Mistakes

  •  Accessing out-of-bounds index
  • Forgetting array size
  •  Using wrong loop condition
  •  Not passing size to function

 Interview Questions (Must Prepare)

  1. What is an array?

  2. Index range of array?

  3. Difference between array and variable?

  4. How to find array size?

  5. How arrays are passed to functions?

  6. Difference between array and pointer?


 Real-Life Use Cases

  • Student marks list

  • Employee salary data

  • Sensor readings (embedded)

  • Game scores

  • Banking transactions


 Summary

  •  Arrays store multiple values efficiently
  •  Index starts from 0
  •  Traversal uses loops
  •  Passed by reference to functions
  •  Foundation for DSA, interviews & real projects

You may also like...