This preview shows pages 1–13. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Dr. Serdar Kirli 1 Chapter 9 Pointers Dr. Serdar Kirli 2 Pointer Fundamentals A pointer is a variable that holds an address of a memory location rather than a regular numeric value. To declare a pointer, use the syntax type *name; where name is the name of the pointer variable and type is the type of thing that the pointer will point to. For example: float *p; int *py; double *myArray ; Dr. Serdar Kirli 3 The Address of Operator The & is the address of operator. For example: p = &x; assigns the address of x to the pointer variable p . float x = 2.5 ; float *p; p = &x; Dr. Serdar Kirli 4 The Address of Operator float x = 2.5 ; float *p; p = &x; The & is the address of operator. For example: p = &x; assigns the address of x to the pointer variable p . x Dr. Serdar Kirli 5 The Address of Operator x p float x = 2.5 ; float *p; p = &x; The & is the address of operator. For example: p = &x; assigns the address of x to the pointer variable p . Dr. Serdar Kirli 6 The Address of Operator float x = 2.5 ; float *p; p = &x; x p p receives the address of x The & is the address of operator. For example: p = &x; assigns the address of x to the pointer variable p . Dr. Serdar Kirli 7 The Dereferencing Operator The * is the dereferencing operator. For example: y = *p; sets the value of y equal to the value pointed to by the pointer variable p . float y = 3.4 ; float x = 3.7 ; float *p; p = &x; *p = 7.5 ; y = *p; Dr. Serdar Kirli 8 The Dereferencing Operator The * is the dereferencing operator. For example: y = *p; sets the value of y equal to the value pointed to by the pointer variable p . y float y = 3.4 ; float x = 3.7 ; float *p; p = &x; *p = 7.5 ; y = *p; Dr. Serdar Kirli 9 The Dereferencing Operator x The * is the dereferencing operator. For example: y = *p; sets the value of y equal to the value pointed to by the pointer variable p . y float y = 3.4 ; float x = 3.7 ; float *p; p = &x; *p = 7.5 ; y = *p; Dr. Serdar Kirli 10 The Dereferencing Operator x p y The * is the dereferencing operator. For example: y = *p; sets the value of y equal to the value pointed to by the pointer variable p . float y = 3.4 ; float x = 3.7 ; float *p; p = &x; *p = 7.5 ; y = *p; Dr. Serdar Kirli 11 The Dereferencing Operator x p p receives the address of x y The * is the dereferencing operator. For example: y = *p; sets the value of y equal to the value pointed to by the pointer variable p . float y = 3.4 ; float x = 3.7 ; float *p; p = &x; *p = 7.5 ; y = *p; Dr. Serdar Kirli 12 The Dereferencing Operator x p The variable pointed to by p is assigned the new value y The * is the dereferencing operator....
View
Full
Document
 Fall '08
 Idonotknow

Click to edit the document details