COMP 206 Lecture Notes - Lecture 11: Object-Oriented Programming, C Data Types, C Syntax

60 views10 pages

Document Summary

Introduce the c struct a handy way to organize many variables! typedef and the common struct syntax: allocating memory for structs. Today"s (cid:272)ore pro(cid:271)le(cid:373: suppose we want to organize a lot of data. If each element has the same type: we use an array: what if there data has a wide variety of types, example: student database, student id, name, age, major, gpa/term. In other languages: python, might think about using a dictionary, map the name of the field to its data, and as always python plays very loose with types. The c struct: group together many variables with the same type. Using a structure: to use a structure, you need to create a variable of the new type, you can then fill it with data, or this way: New syntax: the (cid:862)arro(cid:449)(cid:863) operator (cid:862)->(cid:863) is o(cid:374)ly for stru(cid:272)tures, de-references the pointer and accesses the field all at once: A (cid:272)allo(cid:272)"d array of stru(cid:272)tures fscanf a struct fread a struct.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents