csc1254lect03

csc1254lect03 - CSc 1254: Lecture # 3 Pointers and Memory...

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

View Full Document Right Arrow Icon
CSc 1254: Lecture # 3 Pointers and Memory Allocations September 12, 2005 Pointers Declaring Pointer Variables Fundamental Pointer Operations Dereference Operator (*) Pointers and Arrays Pointers and Structs Pointers and Formal Parameters 1 Pointers Within the memory system, every byte is identi±ed by a numeric address . C++ inherits from C the fact that programmers should have as much access as possible to the facilities provided by the hardware itself. For this reason, C+ makes the fact that memory locations have addresses visible to the pro- grammer. A variable whose value is an address in memory is called a pointer . 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Important facts to remember about pointers: every variable has a memory address a pointer holds a memory address variable. the dereference operator (*) is used to obtain the value stored at the address a pointer variable holds. a pointer variable is declared by combining the type of the variable whose address the pointer variable is going to store with an additional asterisk (*). This is NOT the same as the DEREFERENCE operator. In C++, pointers serve several useful purposes. Most important of these are: Pointers allow you to refer to a large data structure in a compact way. Pointers facilitate sharing of data between di±erent parts of a program. Pointers make it possible to dynamically allocate memory during pro- gram execution. Pointers can be used to record relationship among data items. 2 Declaring Pointer Variables Like all C++ variables, you must declare a pointer variable before you can use them. To declare a pointer variable, you precede its name with an asterisk (*) in a standard declaration. For example, the lines: int *iptr; char *cptr; int **iptr2iptr;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

csc1254lect03 - CSc 1254: Lecture # 3 Pointers and Memory...

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

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