lecture20-mar9 - Announcements Lecture 20 Read Chapter 14...

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

View Full Document Right Arrow Icon
Announcements Lecture 20 • Read Chapter 14 for after break • Assignment 4 –Due F r iday – Write down your stats: SLOC , hrs., logic defects • Friday lecture and recitations cancelled • Topics for today (Ch. 16) –S t ruc tu res –B i t f ie lds – Unions – Enumerations Structures Aggregation of heterogeneous variables (elements) under one name The declaration forms a template (a new data type) that can be used to create variables of that type, e.g. struct Person /* Define a structure type */ { char firstName[32]; char lastName[32]; int age; Now use the above type to create variables of that type struct Person student1; /* define struct variable of that type */ struct Person student2; /* define struct variable of that type */ Now assign values to the elements of a struct variable - use Dot notation strcpy ( student1 . firstName , ”Harry" ); student1.lastName = “Hacker”; student1 . age = 19; student ; /* declare a variable another way */ Arrays of Structures #define CLASS_SIZE 142 struct Person_record { char firstName[32]; char lastName[32]; int age; }; typedef Person struct Person_record ; /* Define Person type alias */ Person students [ CLASS_SIZE ] ; /* define an array of Persons */ . . . /* assign a particular student’s attribute values */ strcpy( students [3] . firstName, "John" ); strcpy( students [3] . lastName, "Doe" ); students [3] . age = 20; /* or similarly */ int i =3; strcpy( students [i] . firstName, "John" ); strcpy( students [i] . lastName, "Doe" ); students [i] . age = 20; Arrays of Structures Person students [ CLASS_SIZE ] ; . . . /* fill up the students array from user input */
Background image of page 1

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

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

This note was uploaded on 01/24/2010 for the course EE 312 taught by Professor Shafer during the Spring '08 term at University of Texas at Austin.

Page1 / 3

lecture20-mar9 - Announcements Lecture 20 Read Chapter 14...

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