|
Let's try using pointers in a small program. Take a look at this piece of code:
void main(void)
{
int *nacho; /* Declare the pointer-to-int */
nacho = new int; /* Give nacho something to point at */
*nacho = 42; /* Assign what nacho points to 42 */
cout << "I feel like I could eat " << *nacho << " nachos!" << endl;
}
Let's go over what each line does. First, we say " new(nacho);
Now that nacho has the location of the new integer we've created, we can
start assigning it values. The third line, "
The last line is another example of working with the value that's pointed at.
Notice that we're printing |