Array size and bounds
📖 Scenario: You are helping a small store keep track of the number of items sold each day in a week. You will use an array to store these numbers.
🎯 Goal: Create an array to hold daily sales for 7 days, set a limit for the array size, and print the sales for each day without going out of bounds.
📋 What You'll Learn
Create an integer array named
dailySales with exactly 7 elements.Create an integer variable named
size and set it to 7.Use a
for loop with an index variable i to access each element of dailySales safely.Print each day's sales using
std::cout.💡 Why This Matters
🌍 Real World
Arrays are used to store lists of data like daily sales, temperatures, or scores. Knowing the size helps avoid errors when reading or writing data.
💼 Career
Understanding array size and bounds is essential for safe programming in many jobs, including software development, data analysis, and embedded systems.
Progress0 / 4 steps