Pointers
eharetea

A primer for pointers in C++.

Pointers C++.

Date Created:Friday December 29th, 2006 03:41 AM
Date Modified:Wednesday July 30th, 2008 11:55 PM


#include <iostream>



using namespace std;



int main() {



    const int nMyArraySize 6// const makes it so this variable cannot change.

    int nMyArray[nMyArraySize]; // computer needs to know how big array is.

    

    for (int i 0nMyArraySizei++) {

    

        nMyArray[i] = rand()%100;

        

        cout << &nMyArray[i] << " is nMyArray[" << << "]'s location in Memory" << endl;

    }

    int y 54;

    int x 6;

    intpMyPointer;

    pMyPointer = &x;

    *pMyPointer 7// this changes x because its pointing to x

    pMyPointer = &y;

    *pMyPointer 7;

    

    cout << << " " << << " " << *pMyPointer << endl// data

    cout << pMyPointer << " " << &<< endl// data location

    return 0;



}



Downloads:
Download: pointers.cpp 749 B

Please login or Click Here to register for downloads
Creative Commons License
Pointers by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com