Understanding Pointers 253
8
- What is the difference between the indirection operator and the address-of
operator? - What is the difference between const int ptrOneand int const ptrTwo?
Exercises ........................................................................................................
- What do these declarations do?
a. int pOne;
b. int vTwo;
c. int pThree = &vTwo; - If you have an unsigned shortvariable named yourAge, how would you declare a
pointer to manipulate yourAge? - Assign the value 50 to the variable yourAgeby using the pointer that you declared
in Exercise 2. - Write a small program that declares an integer and a pointer to integer. Assign the
address of the integer to the pointer. Use the pointer to set a value in the integer
variable. - BUG BUSTERS:What is wrong with this code?
#include
using namespace std;
int main()
{
int pInt;
pInt = 9;
cout << “The value at pInt: “ << pInt;
return 0;
}
6.BUG BUSTERS:What is wrong with this code?
#include pVar = & SomeVariable;
using namespace std;
int main()
{
int SomeVariable = 5;
cout << “SomeVariable: “ << SomeVariable << endl;
int
pVar = 9;
cout << “SomeVariable: “ << *pVar << endl;
return 0;
}