Arrays in C++

Arrays in C++

An array is a group of comparable objects saved in contiguous reminiscence places. In programming, generally a easy variable is just not sufficient to carry all the info. For instance, let’s imagine we need to retailer the marks of 500 college students, having 500 completely different variables for this job is just not possible, we are able to outline an array with measurement 500 that may maintain the marks of all college students.
C++ arrays

Declaring an array in C++

There are couple of the way to declare an array.
Technique 1:

 

int arr[5];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
arr[3] = 40;
arr[4] = 50;

Technique 2:

int arr[] = {10, 20, 30, 40, 50};

Technique 3:
int arr[5] = {10, 20, 30, 40, 50};

Accessing Array Components

Array index begins with 0, which implies the primary array ingredient is at index 0, second is at index 1 and so forth. We are able to use this data to show the array parts. See the code beneath:


#embody 
utilizing namespace std;

int most important(){
   int arr[] = {11, 22, 33, 44, 55};
   cout<<arr[0]<<endl;
   cout<<arr[1]<<endl;
   cout<<arr[2]<<endl;
   cout<<arr[3]<<endl;
   cout<<arr[4]<<endl;
   return 0;
}

Output:

11
22
33
44
55