lecture06 - Last time Introduction to Low-Level Programming...

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

View Full Document Right Arrow Icon
Introduction to Low-Level Programming Concepts CMSC 212 ecture 6 1 CMSC 212 Lecture 6 September 17, 2009 Last time Chapter 8, Arrays – multidimensional arrays as parameters and arguments – symbolic constants Chapter 10, Structures and unions – structure basics ypedef 2 CMSC 212 typedef – assigning and comparing structures – nested structures – structure initialization Chapter 10, Structures and Unions, con't. 3 CMSC 212 Pointers to structures Use to get the memory address of a variable of any type The -> operator dereferences a pointer to a structure, eaning it refers one field typedef struct { Month month; int day; int year; } Date; .. 4 CMSC 212 meaning it refers to one field of the structure the pointer points to * and . can both be used instead, but be careful: – in the example, p->day is equivalent to (*p).day – why are the parentheses needed? ... Date x= {NOV, 3, 2009}; Date *p; p= &x; printf("%d\n", p->day); p->year += 3;
Background image of page 1

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

View Full DocumentRight Arrow Icon
Pointers to fields A pointer of appropriate type can point to a single structure field typedef struct { Month month; int day; int year; Date; Bill b; Date d, *dp; int *ip; ip= &d.day; 5 CMSC 212 } Date; typedef struct { Date payment_date; Money amount; int paid; /* 0 or 1 */ } Bill; *ip= 17; ip= &b.paid; *ip= 1; dp= &bill.payment_date; *dp= d; ip= &bill.payment_date; typedef struct { char product_name[200]; int quantity; float unit_price; float total_value; } Transaction; void update_quantity(Transaction *trans, int num_to_add) { Passing a pointer to a structure indicates a pointer type parameter
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 / 5

lecture06 - Last time Introduction to Low-Level Programming...

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