eecs280.discussion.week6

eecs280.discussion.week6 - EECS 280 – Week 6 Structs,...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: EECS 280 – Week 6 Structs, Program Arguments, I/O, Templates Structs • What are structs? • Why would we want to use them? Struct Declaration • Keyword: struct • Name of struct • Body ▫ One or more attributes (“members”) Now, “product” can be used like any other type. Members are accessed with the “.” operator struct product { double price; double weight; char name[32]; } product apple; product orange, banana; orange.price = 2.19; apple.name = “Honeycrisp”; Struct Declaration There’s a shortcut if you want one or more instances of a struct immediately after you declare it. We can now access members of bob and janet without having to declare them separately. struct person { char name[32]; int age; bool is_friend; } bob, janet; bob.name = “Robert”; janet.age = 23; Structs in Structs Since they behave as any other data type, structs can be members of other structs. Likewise, you can also have arrays of structs. struct pixel { unsigned char red; unsigned char blue; unsigned char green; } struct image { char name[32]; pixel data[800 x 600]; } Structs & Functions...
View Full Document

This note was uploaded on 12/14/2010 for the course EECS 280 taught by Professor Noble during the Fall '08 term at University of Michigan.

Page1 / 20

eecs280.discussion.week6 - EECS 280 – Week 6 Structs,...

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

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