CSE1320Ch4Notes

CSE1320Ch4Notes - Ch. 4 notes : Pointers and Arrays I. A...

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

View Full Document Right Arrow Icon
1 Ch. 4 notes : Pointers and Arrays I. A pointer : A. is a scalar type B. holds one value at a time C. contains the address of another value (of the same type) as its own value II. The address of a variable is referenced with the operator A. ex. 4-1, p. 187 B. ex. 4-2, p. 189 III. Declaration of a pointer is done by A. int *intptr; which can mean: 1. 'intptr' is the name of a variable which points to a variable of type int (integer) 2. 'intptr' is defined to contain the address of a variable of type int B. char *charptr; which can mean: 1. 'charptr' is the name of a variable which points to a variable of type char 2. 'charptr' is defined to contain the address of a variable of type char C. ex. 4-2, p. 189 D. ex. 4-3, p. 191 E. If 'floatptr' is defined to be a pointer of type float , then the statement ++floatptr; would mean that 'floatptr' now contains the address of the memory location 4 bytes after its previous value, if sizeof(floatptr) returns a value of 4 (bytes). F. Unless you specifically initialize a pointer's value, it will contain garbage (whatever was left in those memory locations from the last program which used that location). In- itialization can be done by 1. intptr = &number; ('intptr' now contains the address of 'number', which must have been defined to be of type int 2. intptr = NULL; ('intptr' now specifically does not point to anything, and contains the value assigned to NULL by the operating system(usually 0) G. If 'intptr' is declared as a pointer to an integer, then the syntax *intptr when used in any expression other than a declaration refers to the contents of the current address in 'intptr', and is referred to as "dereferencing" the pointer 1. ex. 4-4, p. 196 2. ex. 4-5, pp. 199-200
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

CSE1320Ch4Notes - Ch. 4 notes : Pointers and Arrays I. A...

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

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