S
S
sabn1k2016-02-17 18:09:19
C++ / C#
sabn1k, 2016-02-17 18:09:19

Difference and purpose of const T *p and T *const p?

Why do we need pointers to a constant data type and a constant pointer to a data type, and what is the difference?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sdxq, 2016-02-17
@sabn1k

const T *p - the pointer can be changed, the data it points to is not.
T *const p - the pointer cannot be changed, but the data can be changed.
Usage - e.g. implementing the principle of least privilege

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question