Why Use Pointers?


Problems

Problem : Write a function that takes pointers to two integers and swaps the values stored at those addresses.


Problem : Why doesn't this function swap the values correctly?


void swap(int a, int b)
{
	int temp = a;
	a = b;
	b = temp;
}


Problem : Write a function which takes an array of 5 integers and sets all the values to 0.


Problem : Write a function void set_to_NULL(char **ptr); which takes a pointer to a pointer to a character and sets the memory at that address to NULL.


Problem : CHALLENGE: Write a swap function that doesn't use a temporary variable for storage. Hint: use the XOR operator. Are there any cases in which this won't work?


Take a Study Break

Green YOUR SCHOOL!

Click here to get involved with dosomething.org!

John Krasinski's BIG MIRACLE

Click to watch the trailer and read exclusive star interviews!

Do you like Anna?

Read Dear Albert... from ANNA's perspective!

BATTLESHIP, the movie

Here's why we're super jazzed about it.

Do energy juices actually work?

Our blogger puts 'em to the test!


The Book

Cover image

Read What You Love, Anywhere You Like

Get Our FREE NOOK Reading Apps