Curriculum / C / Lesson 09

Arrays in C

An array stores multiple values of the same type in one contiguous block of memory, accessed using an index starting at 0.The size of a C array is fixed once it's declared — it can't grow or shrink at runtime..

9 of 11
beginner 📖 5 min read 🎯 1 question

Arrays

An array stores multiple values of the same type in one contiguous block of memory, accessed using an index starting at 0.

The size of a C array is fixed once it's declared — it can't grow or shrink at runtime.

💡 Key insight C does not check array bounds for you — reading or writing outside an array's size is undefined behavior, not a safe error.

Syntax

syntax
type arrayName[size];
type arrayName[size] = {value1, value2, ...};

Example

scores[0] is the first element, and scores[4] is the last of this 5-element array.

c
#include <stdio.h>

int main() {
    int scores[5] = {90, 85, 70, 60, 95};
    for (int i = 0; i < 5; i++) {
        printf("%d ", scores[i]);
    }
    printf("\n");
    return 0;
}
output90 85 70 60 95

Try it yourself

Copy this example into the C compiler and run it — try changing a value and see what happens.

Quick Quiz

1. What is the index of the first element in a C array?

Back to curriculum