Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Advantages of array in c programming

+7 votes
asked Mar 18, 2023 by Sumiran (190 points)

5 Answers

0 votes
answered Mar 19, 2023 by Anshul Sati (140 points)
  • They provide easy access to all the elements at once and the order of accessing any element does not matter.
  • You do not need to worry about the allocation of memory when creating an array, as all elements are allocated memory in contiguous memory locations of the array.
0 votes
answered Mar 19, 2023 by Manish Wakodikar (140 points)

We Can Save The Same Element Of Same Data Type .

0 votes
answered Mar 20, 2023 by Jithendra Upendram (140 points)
Advantages of arrays:

Arrays are used to store the value dynamically while running a program and also returns the values in output dynamically after some operations like comparing of two are more values.
0 votes
answered Mar 20, 2023 by MARY ANN LADA (150 points)

Advantages of Arrays In C Programming

In arrays, the elements can be accessed randomly by using the index number. Arrays allocate memory in contiguous memory locations for all its elements. Hence there is no chance of extra memory being allocated in the case of arrays. This avoids memory overflow or shortage of memory in arrays.

0 votes
answered Mar 20, 2023 by Peter Minarik (82,920 points)

An array is a contiguous area in memory; the stack to be specific.

int myArray[16];

creates an array of integers with 16 elements. The elements are quick to access via indexing or pointers.

int third = myArray[2]; // 0, 1, 2 <-- 0-based indexing

If you need to store similar elements and you know how many such elements you have, an array is a handy solution.

E.g. if you know that there aren't more than 30 students in a class, you can store them like this:

typedef struct
{
    // student name, address, DoB, etc
} Student;

Student mathClass[30];
unsigned int numStudents = 27;

You can also store how many students you actually have filled up in the mathClass.

I hope this helps to understand what arrays can be used for.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...