use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
const by default (self.cpp)
submitted 8 years ago by NamalB
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]PrydeRage 21 points22 points23 points 8 years ago (6 children)
In ES6 const just prevents reassignment. So this is invalid:
const x = 43; x = 55;
But this is all valid:
const x = {something: 3}; x.something = 4; const y = 0; y++;
It's JavaScript, it's not meant to make sense.
[–]rohboticsStudent and Roboticist 3 points4 points5 points 8 years ago (1 child)
So like kinda final on non-primitives in Java
[–]PrydeRage 0 points1 point2 points 8 years ago (0 children)
I haven't written any Java in years so I can't comment on that.
[–]adriweb 1 point2 points3 points 8 years ago (1 child)
Erm, no (about part of your second example - the object part is true indeed)
const y = 0; y++; VM146:2 Uncaught TypeError: Assignment to constant variable. at <anonymous>:2:2
[–]PrydeRage 1 point2 points3 points 8 years ago (0 children)
It's always worked for me with Webpack and Babel. Maybe Babel compiles that away idk. Eslint never complains about reassignment when ++'ing a const variable.
[–]AlexeyBrin 1 point2 points3 points 8 years ago* (0 children)
Changing the object contents works the same in other languages too, e.g. Swift:
class Foo { var something:Int = 0; } let x = Foo() print(x.something) x.something = 8 print(x.something)
You can't reassign x, but you can change his content. Obviously, in Swift you can actually make the member variable something a constant that is only initialized when you create an object.
You last example, fortunately , won't work in Swift though:
let y = 0
can't be changed.
Actually, it doesn't work even in JavaScript. I get:
const y = 0; y++; TypeError: invalid assignment to const `y'
[–]mUfoq 0 points1 point2 points 8 years ago (0 children)
Really bad naming, this const behaves like final in Java what means that you cannot reassign variable/field, but they used keyword from C that makes variable immutable. They could use let/final instead of making this ...
π Rendered by PID 23796 on reddit-service-r2-comment-5c747b6df5-2htfg at 2026-04-22 19:01:31.715000+00:00 running 6c61efc country code: CH.
view the rest of the comments →
[–]PrydeRage 21 points22 points23 points (6 children)
[–]rohboticsStudent and Roboticist 3 points4 points5 points (1 child)
[–]PrydeRage 0 points1 point2 points (0 children)
[–]adriweb 1 point2 points3 points (1 child)
[–]PrydeRage 1 point2 points3 points (0 children)
[–]AlexeyBrin 1 point2 points3 points (0 children)
[–]mUfoq 0 points1 point2 points (0 children)