Array indexes select one stored element, starting from zero.

zero-based index The first array element is at index `0`, the second at index `1`, and so on.
element access `scores[index]` reads the element stored at that position.

Array Indexing

index
array_indexing.c
Replay: real traced execution (multi-file project)
#include <stdio.h>

int main(void) {
    int scores[3] = {10, 20, 30};
    int index = 1;
    int value = scores[index];

    printf("score=%d\n", value);
    return 0;
}
#include <stdio.h>

int main(void) {
    int scores[3] = {10, 20, 30};
    int index = 0;
    int value = scores[index];

    printf("score=%d\n", value);
    return 0;
}
#include <stdio.h>

int main(void) {
    int scores[3] = {10, 20, 30};
    int index = 2;
    int value = scores[index];

    printf("score=%d\n", value);
    return 0;
}
  1. scores ← ⟨addr A⟩, index ← 1, value ← 20

    3int main(void) {4    int scores→ ⟨addr A⟩[3] = {10, 20, 30};5    int index→ 1 = 1; //@index=0, 26    int value→ 20 = scores[index]20;78    printf("score=%d\n", value20);9    return 0;10}
    outputscore=20
  1. scores ← ⟨addr A⟩, index ← 0, value ← 10

    3int main(void) {4    int scores→ ⟨addr A⟩[3] = {10, 20, 30};5    int index→ 0 = 0;6    int value→ 10 = scores[index]10;78    printf("score=%d\n", value10);9    return 0;10}
    outputscore=10
  1. scores ← ⟨addr A⟩, index ← 2, value ← 30

    3int main(void) {4    int scores→ ⟨addr A⟩[3] = {10, 20, 30};5    int index→ 2 = 2;6    int value→ 30 = scores[index]30;78    printf("score=%d\n", value30);9    return 0;10}
    outputscore=30