Array Declaration and Initialization
📖 Scenario: You are working on a simple program that stores the ages of five friends. You want to keep these ages in an array so you can use them later for calculations or display.
🎯 Goal: Create an array to hold the ages of five friends, set a variable for the number of friends, then print all the ages in order.
📋 What You'll Learn
Declare an integer array called
ages with exactly 5 elementsInitialize the
ages array with the values 21, 25, 19, 30, and 22 in that orderCreate an integer variable called
num_friends and set it to 5Use a
for loop with the variable i to iterate from 0 to num_friends - 1Print each age followed by a space on the same line
💡 Why This Matters
🌍 Real World
Arrays are used to store lists of data like scores, ages, or measurements in many programs.
💼 Career
Understanding arrays is essential for programming jobs because they are a basic way to organize and access multiple values efficiently.
Progress0 / 4 steps
