SYSC 2006 Lecture 4: Structures

69 views2 pages

Document Summary

Definition: one or more variables grouped together under a single name. Allows a group of related variables to be treated as a unit. A structure declaration doesn"t allocate memory point is a structure tag, not a variable name. A structure declaration defines a type struct point point1, point2; declares variables point1 and point2 as instances of type struct point struct point struct point point1 point2. } point_t point_t point1; point1 = (point_t) {320, 200}; Structures can be copied and assigned point1. x = 320; point1. y = 200; point2 = point1; Structures can be passed as arguments to functions. Concise makepoint function point_t makepoint(int x, int y) { return (point_t) {x, y}; Concise addpoints function point_t addpoints(point_t pt1, point_t pt2) { pt1. x = pt1. x + pt2. x; pt1. y = pt1. y + pt2. y; return pt1" // modifying pt1 does not modify corresponding argument point_t addpoints(point_t pt1, point_t pt2) { return (point_t) {pt1. x + pt2. x, pt1. y + pt2. y};

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