Array Manipulation in Cpp

/******************************************************************************
 * Array Stuff                                                       main.cpp *
 *                                                                            *
 * Author:                                                      *
 *                                                                            *
 *                                                                            *
 * Abstract: This project illustrates techniques for manipulating arrays.     *
 *                                                                            *
 * 1. An array indexes from zero.                                             *
 * 2. The compiler doesn't care if your index is out of range.                *
 * 3. When stored in RAM, an array is guaranteed to be contiguous.            *
 * 4. Rule to remember: an array reference without an index generates the     *
 *     address of the first element of the array. Memorize this rule.         *
 *                                                                            *
 *                                                                            *
 *                                                                            *
 *                                                                            *
 *                                                                            *
 ******************************************************************************/
#include <iostream>

using namespace std;

void main()
{
//    A local variable, therefore it's not in a known state.
    char intAlpha[10];    // We have intAlpha[0] through intAlpha[9]

//    Enumerate the array with a loop. Note that the array is UNinitialized.
    for (int i = 0; i < 10; i++) cout << intAlpha[i];

//    What happens if we go beyond the dimensions of the array?
//    intAlpha[10] = 42;    // oops. Will this compile?

//    Array notation
    intAlpha;        // This is the address of the first element of the array
    intAlpha[0];    // This is the value of the first element in the array
    *intAlpha;        // This is also the value of the first element in the array
                    //  The * is called the 'dereference' operator, when used in this context

}


More by this Author


Comments

No comments yet.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working