CPS 196 week 10

CPS 196 week 10 - Structures variable: one type, one value...

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

View Full Document Right Arrow Icon
Structures variable: one type, one value int i; int j; float x; float y; Array one type, multiple values int i[5] int j[10]; float x[4] float y[15] Want a variable to store a date? 10/31/11 month day year int int int int month, day, year What if you want to store 4 dates? Today, purchase, delivery, payment int toodayDay, todayMonth, todayYear; int purchaseDay, purchaseMonthl purchaseYear; int month [4], day[4], year[4]; int today=0; int purchase=1; int delivery =3; int payment= 3; printf(“%d %d %d”, month[today], day[today], year[today]); 10/31/10
Background image of page 1

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

View Full DocumentRight Arrow Icon
Structure Syntax name of structure components type name The “date” structure consists of 3 components 1. “month” type of integer 2. “day” type of integer 3. “year” type of integer new type How to use in C treat as variables name of variable of type of structure component Components of structure can have different type Initialize variable
Background image of page 2
int num=5; Initialize array float x[3]= {1.2, 2.5, 5.3}; Initialize structure struct date today= {10, 31, 2011};
Background image of page 3

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

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

Page1 / 6

CPS 196 week 10 - Structures variable: one type, one value...

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

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