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 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
