2.07 Protecting Pointers (ECE 150) PDF
Document Details
Uploaded by Deleted User
University of Waterloo
Douglas Wilhelm Harder
Tags
Summary
This document is about protecting pointers using const within a programming context. It details how variables can be changed directly or indirectly, touching on pointer reassignment and declaration using the const keyword. The document is from ECE 150, Fundamentals of Programming, likely course notes.
Full Transcript
2020-10-02 Protecting pointers...
2020-10-02 Protecting pointers 2 ECE 150 Fundamentals of Programming Outline In this lesson, we will: – Understand how to protect pointers using const Protecting pointers Douglas Wilhelm Harder, M.Math. LEL Prof. Hiren Patel, Ph.D., P.Eng. Prof. Werner Dietl, Ph.D. © 2018 by Douglas Wilhelm Harder and Hiren Patel. Some rights reserved. Protecting pointers Protecting pointers 3 4 Revisiting pointers Revisiting const A variable may be changed either directly or by changing what is at A variable declared const cannot be reassigned: the corresponding address: int main() { int main() { int m{42}; int x{42}; int const n{91}; int *p_x{&x}; ++m; std::cout