Array size and bounds
📖 Scenario: You are working on a simple program that stores the ages of a small group of friends. You want to make sure you create an array with the right size and access its elements safely.
🎯 Goal: Create an array to hold exactly 5 ages, set a limit variable for the array size, use a loop to print each age, and display the ages one by one.
📋 What You'll Learn
Create an integer array called
ages with exactly 5 elements: 21, 25, 30, 22, 28Create an integer variable called
size and set it to the number of elements in agesUse a
for loop with an index variable i from 0 to size - 1 to access each element in agesPrint each age inside the loop using
printf💡 Why This Matters
🌍 Real World
Arrays are used to store lists of data like ages, scores, or measurements in many programs.
💼 Career
Understanding array size and bounds is essential for writing safe and efficient code in software development.
Progress0 / 4 steps