Menu
Coddy logo textTech

Declaring Arrays

Part of the Fundamentals section of Coddy's C journey — lesson 53 of 63.

Arrays in C allow you to store multiple values of the same data type under a single variable name.

Declare an integer array with 5 elements:

int numbers[5];

This creates an array named numbers that can hold 5 integers.

You can also initialize an array with values when declaring it:

int numbers[5] = {10, 20, 30, 40, 50};

If you initialize all elements, you can let C determine the size:

int numbers[] = {10, 20, 30, 40, 50};

C will automatically create an array with 5 elements.

Arrays in C are zero-indexed, which means the first element is at index 0.

challenge icon

Challenge

Easy

Create a program that:

  1. Declares an integer array called scores with 3 elements
  2. Initializes the array with the values 75, 85, and 95
  3. Prints each element of the array on a new line using printf and "%d\n"

Cheat sheet

Arrays in C store multiple values of the same data type under a single variable name.

Declare an array:

int numbers[5];

Initialize an array with values:

int numbers[5] = {10, 20, 30, 40, 50};

Let C determine the size automatically:

int numbers[] = {10, 20, 30, 40, 50};

Arrays are zero-indexed - the first element is at index 0.

Try it yourself

#include <stdio.h>

int main() {
    // Write your code here
    
    return 0;
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals