In: Computer Science
please summarize the basic concept of how data can be contained and manipulated effectively in an array
Here is the solution. Please do upvote thank you.
An array is defined to be an index sequence of values of the same type.
So here's an example of an array, it's 52 playing cards in a deck. That's the example that we're going to work with for a lot here So, some cards in the first position, other cards in the second position, the ace of hearts in the third position, and so forth.
Given an index then we can immediately get to the card that's in that position in the deck. But there's many other ideas where you might use an array.
So, you might have a lot of students in an online class, and again, you can get to each one quickly through an index. We're going to look at digital images. There might be a billion pixels in a digital image, and we want to be able to quickly get to each one of them. Or Biologists studying DNA, there might be nucleotides in the DNA strand. Many other examples showing that you've got data, elements of the same type, and you have a huge amount of them, and you need to structure them so that you can process them efficiently.
Syntax
Data type arrayname[ranger] ;
Example
int student_marks 100];
So, our main purpose of the array is to facilitate the storage and the manipulation of this kind of data. So, what does it mean about processing many values of the same type? So here's an example that we could write without using arrays at all. In this case, maybe we have 10 items of data, and we just named them a zero through a nine. If we want to refer to the fifth one, we can say a4 equals 3.0, or the ninth one a8 equals 8.0, and so forth, and even use them in arithmetic expressions. Now, but after a while, you can see that it would be very tedious and error-prone to have code of this sort.
A much simpler way to do it, is using an array. Instead of declaring all those things of the same type separately, we just declare in one statement that we're going to access Then if we want to refer to the fifth one, we just put that index inside square brackets, or the eighth one whichever one we want, and we can use those that array name followed by an index in square brackets just the same way we use any other variable of that type.
int r=student_marks [6];
Since they're all the same type, the compiler can keep track of them and check the type. That's convenient enough with 10 values, but what this does immediately, is it scales say to a million values. We have a huge amount of data. It would be indeed tedious to give them each one of them a different name. With an array, we have the shorthand where we just use the brackets to refer to individual pieces of the data. It scales to handle huge amounts of data.
A simple example of manipulating data in an array of n elements. Increase every element in array by 4.
for (int i=0;i<n;i++)
{
student_marks[i] +=4;
}