DSA Tutorial



ARRAYS IN DSA


πŸ“š Arrays in DSA

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.

πŸ› οΈ Array Declaration

int numbers[5];  // declares an array of 5 integers
    

Here, numbers can hold 5 integers, indexed from 0 to 4.

πŸ“¦ Initialization

int marks[3] = {90, 85, 75};
    

You can also initialize later like:

marks[0] = 90;
marks[1] = 85;
marks[2] = 75;
    

πŸ” Accessing Elements

You can access any element using its index:

printf("%d", marks[1]); // Outputs: 85
    

πŸ” Looping through Arrays

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.

⚠️ Limitations

  • Fixed size (can’t grow dynamically)
  • Wastes space if not fully used
  • Inserting and deleting can be costly

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review