cannot be applied to expressions constants or

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Recall the unary operator &, that gives the address of an object: – & only applies to objects in memory, such as variables and array elements. – & cannot be applied to expressions, constants, or register variables. • So the statement: p = &c; assigns the address of c to the variable p. p is said to “point to” c. 5 Pointers and Addresses (cont’d) • The unary operator * is the indirec'on or dereferencing operator. • When applied to a pointer, it accesses the value the pointer points to. • See next example… 6 Pointers and Addresses (cont’d) • Example: int x = 1, y = 2, z[10]; int *ip; /* ip is a pointer to int */ ip = &x; y = *ip; *ip = 0; ip = &z[0]; /* /* /* /* ip now points to x */ y is now 1 */ x is now 0 */ ip now points to z[0] */ 7 Pointers and Func1on Arguments • Since C passes arguments to funcCons by value, there is no direct way to alter a variab...
View Full Document

This document was uploaded on 03/10/2014 for the course ENGINEER 2sh4 at McMaster University.

Ask a homework question - tutors are online