Home > SparkNotes > Computer Science Study Guides > Why Use Pointers? >

sparknotes

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?