C By Discovery (4th Edition)

Info icon This 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
Image of page 1

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern