Accessing value though pointer – c++

What it does:

In the program, value is changed twice. As you can see only ptr and howMany changed. This is because they are connected with each other and saving is not.

#include <iostream>
using namespace std;
int main()
{
  int number;
  int *ptr = &number;
  int howMany;
  *ptr = 6087;
  howMany = *ptr;
  cout << howMany << endl;
  *ptr = 7000;
  cout << *ptr << endl;
  cout << howMany << endl;
  return 0;
}//main

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s