C++: Array

This entry is part 41 of 61 in the series C++

Now that we have Netbeans for C++ properly installed, we start off with a simple example on Array.

An array declaration has the form Name[D] where Name is the name being defined and D is the dimension of the array.

The dimension specifies the number of elements and must be greater than zero.  And the dimension must be known at compile time.

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char** argv) {
    double height[] = {170, 172, 185};
    cout << height[0] << endl;
    cout << height[2];

    return 0;

In line 8, we are naming the array as height and it’s dimension is 3.  The first array value is accessible by height[0] as an array index will always start from 0.


Series Navigation<< C++: Compiling a simple C++ program on Netbeans
C++: Public, private and protected >>