pointers - Dr. David A. Gaitros dgaitros@admin.fsu.edu...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Dr. David A. Gaitros dgaitros@admin.fsu.edu
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Pointers are variables that contain memory addresses instead of values. A variable directly references a value A pointer indirectly references a value Referencing a value through a pointer is called indirection The reason why we still have pointers is because internal to the machine this is how items are referenced.
Background image of page 2
Pointers can be declared to point to any object of any type including class objects. You may initialize a pointer to zero (0), NULL, or to an address. A pointer with the value of zero (0) or NULL points to nothing Trying to reference or assign something to a pointer with an address of zero (0) or NULL will cause your program to be abnormally terminated (ABEND).
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example: int y=5; int *yPtr; yPtr = &y; cout << *yPtr << endl; The unary operator “*”, or indirection operator returns the value of the object. The unary operator “&” returns the address of an object.
Background image of page 4
Example int *countptr, count; float *xPtr, *yPtr; The above declares countptr to hold an address that points to an integer. count on the other hand holds the value of an integer. Both xPtr and yPtr hold address that pointo to a floating point number.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
int main(void) { int a; int *aPtr; a = 7; aPtr = &a; cout << “Address of a is “<< (&a) << endl;
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 22

pointers - Dr. David A. Gaitros dgaitros@admin.fsu.edu...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online