An Array is a collection of elements stored in contiguous memory locations. It allows you to store multiple values of the same type in a single variable.
π§ Think of an array as a row of containersβeach holds a value, and each has an index starting from 0.
int numbers[5]; // declares an array of 5 integers
Here, numbers
can hold 5 integers, indexed from 0 to 4.
int marks[3] = {90, 85, 75};
You can also initialize later like:
marks[0] = 90; marks[1] = 85; marks[2] = 75;
You can access any element using its index:
printf("%d", marks[1]); // Outputs: 85
for (int i = 0; i < 5; i++) { printf("%d ", numbers[i]); }
This will print all 5 elements.
β Advantages: Easy to access and update elements using index, useful for static data storage.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!