To access array elements in C++ using index, you can use square brackets notation.
In this example,
numbers
with integer values.2
using indexing numbers[1]
.#include <iostream>
using namespace std;
int main() {
int numbers[] = {1, 2, 3, 4, 5};
cout << numbers[1] << endl;
return 0;
}
2
In this example,
chars
with character values.3
using indexing chars[2]
.#include <iostream>
using namespace std;
int main() {
char chars[] = {'a', 'b', 'c', 'd', 'e'};
cout << chars[2] << endl;
return 0;
}
c
In this tutorial, we learned How to Access Array Elements using Index in C++ language with well detailed examples.