Thursday, November 3, 2011

Pointer Example 1

#include <iostream>
#include <string>
using namespace std;

int main()
{

  int andy = 25;
  int fred = andy;
  int* ted = &andy;
  cout << andy << endl;
  cout << fred << endl;
  cout << *ted << endl;
  cout << ted << endl;

    // declare the variables:

    int nNumber;
    int *pPointer;

    // now, give a value to them:

    nNumber = 15;
    pPointer = &nNumber;

    cout << "nNumber is equal to :" << nNumber << endl;
    *pPointer = 25;

    cout << "nNumber is equal to :" << nNumber << endl;
  return 0;
}

No comments:

Post a Comment