Changing a variable by using a pointer – C++

What it does:

A very simple program which will set a variable by using a pointer.

Points:

To declare a pointer you need to declare what type of variable it will point to.

Placing asterisk before the pointer is also called deferring the pointer.

#include <iosheader>
using namespace std;

int main()
{
    int numberOfChildren;
    int *ptr;

    ptr = &numberOfChildren;
    *ptr = 6098;
    cout << numberOfChildren << 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