C Arrays

Store many values of one type.

✍️ 2 exercises in this lesson

An array stores a fixed number of values of the same type in a row in memory.

  • int marks[4] = {72, 95, 58, 88};
  • Indexes start at 0: marks[0].
  • Length: sizeof(marks) / sizeof(marks[0])
  • 2D arrays: int grid[2][3];
C does not check array bounds. Reading marks[10] compiles, but it reads random memory: a classic source of bugs and security holes.

Key Takeaways: C Arrays

Mastering C Arrays helps you write clean and reliable C code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

C Arrays Code Example

C
#include <stdio.h>

int main() {
    int marks[] = {72, 95, 58, 88};
    int n = sizeof(marks) / sizeof(marks[0]);
    int sum = 0, max = marks[0];

    for (int i = 0; i < n; i++) {
        sum += marks[i];
        if (marks[i] > max) max = marks[i];
    }
    printf("Count: %d, Sum: %d, Max: %d\n", n, sum, max);

    int grid[2][3] = {{1, 2, 3}, {4, 5, 6}};
    printf("grid[1][2] = %d\n", grid[1][2]);
    return 0;
}
Output
Count: 4, Sum: 313, Max: 95
grid[1][2] = 6
Run this example on your own computer. The "Get Started" lesson shows how to set it up.

C Arrays Practice Exercises

Check what you learned in “C Arrays”.

/ 2 solved
Fill in the blank

Calculate the number of elements in the array.

int n = sizeof(arr) / ;
✓ Correct! Not quite. Try again.
Multiple choice

Does C check array bounds automatically?

✓ Correct! Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services