J
J
jackroll2015-09-28 17:13:24
C++ / C#
jackroll, 2015-09-28 17:13:24

What is the difference between [type] const * and const [type] const *?

What is the difference between e.g. double const *ptr;and const double const *ptr;?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry, 2015-09-28
@jackroll

A very strange example.
There is no difference at all between and - both times const is applied to the type const [type]- this is the double application of const to the type, which will cause a compilation error. If const is after the asterisk, then the const operator is applied to the pointer. That is , equivalent options are also possible, and where const is applied to both the type and the pointer. In simple words: 1. If const refers to the type (before the asterisk), then the data pointer cannot be changed 2. If const refers to a pointer (after the asterisk), then you cannot change the pointer itself [type] const

A
Alexey Ukolov, 2015-09-28
@alexey-m-ukolov

https://www.cs.umbc.edu/courses/undergraduate/202/...

M
mamkaololosha, 2015-09-28
@mamkaololosha

const for pointer or value

A
Alexey, 2015-09-28
@MAKAPOH

In addition to those already answered, I will give one more link on this topic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question