Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fig. 8.11 Attempting to modify a constant pointer to nonconstant data Constant Pointer to Constant Data The minimum access privilege is granted by a constant

image text in transcribed
Fig. 8.11 Attempting to modify a constant pointer to nonconstant data Constant Pointer to Constant Data The minimum access privilege is granted by a constant pointer to constant data. Sacha pointer always points to the same memory location, and the data at that location cannot be 8.6 Selection Sort Using Pass-by-Reference modified via the pointer. This is how an array should be passed to a function that only needs the array, using array subscript notation, and does not modify the array. The program of Fig. 8.12 declares pointer variable ptr to be of type const int const (line 13). This dec laration is read from right to left as "ptr is a constant pointer to an integer constant." The figure shows the error messages generated when an attempt is made to modify the data to which ptr points (line 17) and when an attempt is made to modify the address stored in the pointer variable (line 18). No errors occur when the program attempts to dereference ptr (line 15), or when the program attempts to output the value to which per points, be cause neither the pointer not the data it points to is being modified in this statement 1 // Fig. 8.12: fi908 12.cpp 2 // Attempting to modify a constant pointer to constant data. 3 #include 4 using namespace std; 6 int main 7 8 int x - 5. Y: 9 10 // ptr is a constant pointer to a constant integer // ptr always points to the same location; the integer 12 I at that location cannot be modified. 13 const int *const ptr -&x: 14 15 cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions