c++ arrays

Sure! Here is a response without personal words or sentences at the beginning and end of the reply:

  1. Declaration of an array:
int arr[5];
  • Explanation: This declares an array named "arr" of size 5 to store integers.

  • Initialization of an array:

int arr[5] = {1, 2, 3, 4, 5};
  • Explanation: This initializes the array "arr" with the values 1, 2, 3, 4, and 5.

  • Accessing array elements:

int x = arr[2];
  • Explanation: This accesses the element at index 2 of the array "arr" and assigns it to the variable "x".

  • Modifying array elements:

arr[3] = 10;
  • Explanation: This modifies the value at index 3 of the array "arr" to be 10.

  • Iterating through an array:

for (int i = 0; i < 5; i++) {
    cout << arr[i] << " ";
}
  • Explanation: This loop iterates through the array "arr" and prints each element separated by a space.