Computer Science 1037A/B Lecture 22: Structures

19 views5 pages

Document Summary

Structure: programmer-defined data type that allows multiple variables to be grouped together. Example: struct declaration struct names commonly begin with an uppercase letter. The structure name is also called the tag. Multiple fields of same type can be in a comma-separated list string name, address; Fields in a structure are all public by default. Defining structure variables struct declaration does not allocate memory or create variables. To define variables, use structure tag as type name. Use the dot (. ) operator to refer to members of struct variables getline(cin, s1. name); cin >> s1. studentid; s1. gpa = 3. 75; To display the contents of a struct variable, you must display each field separately, using the dot operator. Right cout << s1; cout << s1. studentid << endl; cout << s1. name << endl; cout << s1. year << endl; cout << s1. gpa; Similar to displaying a struct, you cannot compare two struct variables directly if (s1 >= s2) won"t work!

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents