Click here to Skip to main content
15,885,987 members
Articles / Programming Languages / C

A Beginner's Guide to Pointers

Rate me:
Please Sign up or sign in to vote.
4.80/5 (222 votes)
9 Jul 2002 1.7M   6.3K   509  
An article showing the use of pointers in C and C++
// This program does not free the memory it allocates.  It is used
// solely to demonstrate the use of the 'new' keyword.

#include <stdio.h>

int *pPointer;

void SomeFunction()
{
	// make pPointer point to a new integer
	pPointer = new int;
	*pPointer = 25;
}

void main()
{
	SomeFunction(); // make pPointer point to something
	printf("Value of *pPointer: %d\n", *pPointer);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
United Kingdom United Kingdom
Andrew is currently a student at the University of Cambridge, working towards a degree in Computer Science. The word 'working' is used here in a vague sense, with the hope that the reader will realise that the same sentence contained the word 'student'.

Aside from computing he has a strong interest in music, and enjoys the outdoors, particularly when the weather permits going out in them... To Andrew, cycling is fun, sailing is more fun, and the odd camping trip and walk is certainly what the doctor ordered.

In terms of programming experience, he first started writing programs for the Commodore Amiga using BASIC, after which he learned the joys of C and has never looked back. Since, he has added C++ and C# to his repotoire, along with a bunch of other crazy languages like ML that they like to teach in college.

Comments and Discussions