Computer Science 1037A/B Lecture Notes - Lecture 10: Local Variable

11 views1 pages

Document Summary

It works like a reference parameter to allow changes to argument from within a function. A pointer parameter must be explicitly dereferenced to access the contents at that address. 1. asterisk * on parameter in prototype and heading void getnum(int *ptr); 2. asterisk * in body to dereference the pointer cin >> *ptr; 3. address as argument to the function in the call getnum(&num); Example void swap(int *x, int *y) int temp; temp = *x; *y = temp; int num1 = 2, num2 = -3; swap(&num1, &num2); Functions can return pointers, but you must be sure that the item the pointer references still exists int *squares(int n) Allocate an array of size n int *sqarray = new int[n]; Fill the array with squares for (int k=0; k

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