Home > OOP344 > Pointers in C/C++

Pointers in C/C++

Pointers are sometimes confusing to C/C++ programmers at first, but they don’t have to be! Pointers are just like any other variable in C/C++ but instead of holding an actual value they hold an address. I will use some simple code to show you how pointers work. Take a look at the code below.


int number = 4;
int* pNumber = &number;

int* pNumber = &number creates an integer pointer and assigns number’s address to it. In C/C++ the character ‘&’ means the “address of”. The simple program below will give you a better understanding of addresses.


#include <stdio.h>

int main()
{
int number = 4;
int* pNumber = &number;
printf(“%u, %u\n”, &number, pNumber);

return 0;
}

The output would be:

3214459548, 3214459548

Categories: OOP344 Tags: ,
  1. February 2, 2010 at 12:05 pm

    There is obviously a lot to learn. There are some good points here.

  1. No trackbacks yet.

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

%d bloggers like this: