COM SCI 32 Lecture 1: Lec 1, 2 - Pointers, Class Composition, Dynamic Memory Allocation

236 views3 pages

Document Summary

Cs 32 - lec 1, 2 - pointers, class composition, dynamic memory allocation. Pointers int main() int var = 1234; int *ptr; ptr = &var; //remember to set the value of a pointer variable before using the * operator cout << *ptr; // print the value stored in that address. *ptr = 5; //set 5 at the address ptr void swap (int *pa, int *pb) int temp; temp = *pa; Use c++ structs to define a new type to use one variable to store a student"s name, id, and. Example of a . h student. h struct student string name; //specify the members that our new type contains int id; float gpa; Student t, u; t. name = carey ; t. id = 113353948; t. gpa = 3. 99; u. name = david ; u. gpa = 1. 12; A constructor that inializes a csprof that has name and age (age should be default 39): class csprof public:

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