Computer Science 1037A/B Lecture 7: Pointers to Constants and Constant Pointers

6 views2 pages

Document Summary

Pointer to a constant: cannot change the value that is pointed at. Must use const keyword in pointer definition: const double taxrates[] = {0. 65, 0. 8, 0. 75}; const double *rateptr; Use const keyword for pointers in function headers to protect data from modification from within function rates is a pointer to a constant that is a double. Constant pointer: the address in the pointer cannot change after the pointer is initialized. Defined with const keyword adjacent to variable name: int classsize = 24; int * const classptr = &classsize; Can be used without initialization as a function parameter. Function can receive different arguments on different calls. While the address in the pointer cannot change, the data at that address may be changed ptr is a constant pointer to an int. Can combine pointer to constants and constant pointers int size = 10; const int * const ptr = &size;

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