I'd like to note that C/C++ have both concepts, but usually refer to value constness.
T const * ptr = expr;
The T value is const here, not the pointer. This is usually what we want. Compare to:
T
const
T * const ptr = expr;
The pointer is constant but the value is not. This is what const appears to mean in JavaScript, which is misleading based on it's syntax.
You can have both at the same time in C/C++:
T const * const ptr = expr;
Read the type form right-to-left to understand where const applies (the syntax rules are a bit ugly for this in C).
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'd like to note that C/C++ have both concepts, but usually refer to value constness.
The
T
value isconst
here, not the pointer. This is usually what we want. Compare to:The pointer is constant but the value is not. This is what
const
appears to mean in JavaScript, which is misleading based on it's syntax.You can have both at the same time in C/C++:
Read the type form right-to-left to understand where
const
applies (the syntax rules are a bit ugly for this in C).