Using constant with Pointers - const qualifier
- Indicates that value of variable should not be modified
- const used when function does not need to change the variable’s value
- Example
- A function that prints the elements of an array, takes array and int indicating length
- Array contents are not changed – should be const
- Array length is not changed – should be const
- Four ways to pass pointer to function
- Non-constant pointer to non-constant data
- Non-constant pointer to constant data//we cannot set
- Constant pointer to non-constant data
- Constant pointer to constant data//A const pointer to a const value can not be set to point to another address, nor can the value it is pointing to be changed through the pointer.
Do'stlaringiz bilan baham: |