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.

what is array ?

+4 votes
asked Sep 8, 2020 by john barsad (160 points)

i am new to cpp and i see the word array a lot, so i wanna know it's meaning pls.

5 Answers

0 votes
answered Sep 9, 2020 by Afif Balde (160 points)
An Array is a collection of data of similar elements.This similar elements could be percentage mark of 100 student,or salariesof 300 employees etc.What is important is that the elements must be "similar'.We cannot have an Array of 10 numbers, of which 5 are ints and 5 are floats.Usually,the array of characters is called 'string',whereas an array of floats or ints is called simply an array
commented Sep 10, 2020 by Peter Minarik (84,720 points)
Actually, you can have various elements in an array if you really want to.

You can use the type void * to store any pointer there. Also, if the size of the variables in the memory is the same, you can also store them there as values (not pointers) and cast them.

But this is a bit bending the rules .
+2 votes
answered Sep 10, 2020 by Peter Minarik (84,720 points)

Array is a collection of the same type (as I commented below, this rule can be bent though). With the use of array, you can place similar elements next to each other in the memory, handle them together, iterate through the elements in the array. It makes handling them easier and also can consume less memory than simply just declaring them one by one. (This is due to memory alignment and padding.)

Please note C and C++ are not exactly the same.

For arrays in C you would typically do

int numbers[10];

oo create an array of 10 integral numbers. This works just as fine in C++, but C++ has various collections available that makes life easier. For instance the vector:

std::vector<int> numbers;

And here is a tutorial on C arrays: https://www.programiz.com/c-programming/c-arrays

0 votes
answered Sep 19, 2020 by Arti Ahirwar (180 points)
Array is collection of variables of the same type.Array is a data structure,which can store a fixed size collection of elements of the same data type.
0 votes
answered Sep 20, 2020 by sujithgoogler (140 points)
Simply, array is collection of elememts

a[]

a[1,2,3,4,5]
here a[] is an array with some elements 1,2,3,,4,
0 votes
answered Sep 21, 2020 by Praveen Kumar (260 points)

Array Stores Many values of same data type.

Value Of the Array Can be Accessed By The Index 0 to n-1

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.
...