
1
1
1
CMSC 212 –F07 (lect 8)
Announcements
Project #2
– Available on the web
Reading
– Chapter 6 (today)
– Chapter 11 (Thursday)
2
CMSC 212 –F07 (lect 8)
Pointers Defined
Can declare a pointer to any type of variable
– are similar to references in Java
– use * before variable name to create a pointer to the type
• int *foo;
• myTypeDef *myPtr;
• float *bar;
– The type determines both:
• what is pointed to
• the size of the object being pointed to
Initialization
– creating a pointer doesn't create the space it points to
– int *foo; /*these two lines will often cause an error here */
*foo = 3; /* because you haven't specified what space it points to*/
– int *bar=3; /*won’t cause an error here but likely will later*/
– int a[5], b; /* these two lines are the way initialization */
int *p = a, *q=&b; /* should be done */