Chapter9 - Dr. Serdar Kirli 1 Chapter 9 Pointers Dr. Serdar...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 . 2.5 x Dr. Serdar Kirli 5 The Address of Operator 2.5 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; 2.5 x 0x8f5cfff2 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; 3.4 Dr. Serdar Kirli 9 The Dereferencing Operator 3.7 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; 3.4 Dr. Serdar Kirli 10 The Dereferencing Operator 3.7 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; 3.4 Dr. Serdar Kirli 11 The Dereferencing Operator 3.7 x 0x8f5cfff2 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; 3.4 Dr. Serdar Kirli 12 The Dereferencing Operator 7.5 x 0x8f5cfff2 p The variable pointed to by p is assigned the new value y The * is the dereferencing operator....
View Full Document

Page1 / 77

Chapter9 - Dr. Serdar Kirli 1 Chapter 9 Pointers Dr. Serdar...

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

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