Pointer to Constant. const int *ptr; int x = 5; int y = 10; ptr = &x; const int *ptr; int x = 5; int y = 10; ptr = &x; *ptr = 66;

Pointer to Constant ● Pointer points to a constant – It is a pointer through which one cannot change the value of variable it points is known as a ...
Author: Linda Mathews
5 downloads 0 Views 408KB Size
Pointer to Constant ●

Pointer points to a constant –

It is a pointer through which one cannot change the value of variable it points is known as a pointer to constant.

Pointer to Constant const int *ptr; int x = 5; int y = 10; ptr = &x; const int *ptr; int x = 5; int y = 10; ptr = &y; x = 6;

const int *ptr; int x = 5; int y = 10; ptr = &x; *ptr = 66;

Constant Pointer ●



It is a pointer that cannot change the address its holding. once a constant pointer points to a variable then it cannot point to any other variable. int x = 5; int *const ptr = &x; int y = 10; ptr = &y;

int x = 5; int *const ptr = &x; *ptr = 30; cout