Question: 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

 Fig. 8.11 Attempting to modify a constant pointer to nonconstant data

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!