C By Discovery (4th Edition)

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

View Full Document Right Arrow Icon
1 Intermediate Programming CSE 1320 Lecture 12 Chapter 7: 7.1-7.3 Aggregate Types • Designed to hold multiple data values – Arrays: same type – Structures: different types #define ID_SIZE 8 struct auto_part { char id[ID_SIZE]; float price; int cur_inventory; }; Struct Variables struct auto_part a_part; struct auto_part a_part = {“J-145D”, 4.79, 12}; struct auto_part a_part = {“J-145D”}; /* price and cur_inventory are set to 0 */ struct { char id[ID_SIZE]; float price; int cur_inventory; } part1, part2; /* Could not declare additional variables later */ Struct Members • May not be a function • May not have type void • May not nest a structure of its own type – May have structures of other types – May have pointers to a structure of the same type struct node { struct node1 { struct node2 { int data; int data1; struct auto_part data; struct node y; struct node2 data2; struct node2 *next; }; }; }; Access Fields variable_name.member_name part1.id part1.price part1.cur_inventory
Background image of page 1

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

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

Unformatted text preview: Member Operations part1.id[3] *(part1.id + 3) 2 Operations on Structures Selection operator (access members) Assignment operator Address operator sizeof() operator Arrays of Structures struct auto_part inventory[4]; inventory: address of first structure cell inventory[2]: accesses third structure inventory[2].cur_inventory inventory[2].id[3] struct auto_part inventory[4] = { {3bJ-4F, 1.35, 20}, {4 tH-2J, 0.89, 45}, {89J-3K, 2.78, 12} }; Pointers to Structures struct auto_part *partptr; (*partptr).price partptr->price atof and atoi (stdlib.h) atof: takes a string containing the ASCII representation of a floating point number and converts the string into the corresponding value of type float atoi: takes a string containing the ASCII representation of an integer and converts the string into the corresponding value of type int...
View Full Document

Page1 / 2

Lecture12 - Member Operations part1.id[3] *(part1.id + 3) 2...

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

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