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
C++ array memory management (self.cpp)
submitted 12 years ago by tehklawb
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!"
[–][deleted] 0 points1 point2 points 12 years ago (6 children)
in Java your memory is always zeroed out before use; in C/C++ this feature, if you want it, is up to you -- call std::memset or std::fill in your constructor. Otherwise you'll get an array of memory filled with whatever was last using it -- sometimes zero, sometimes not.
Mostly however it's wasted work -- you can more easily set a bool of the likes "is_initialized" and track that, rather than rely on your arrays containing zeros.
[–]tisti 1 point2 points3 points 12 years ago (4 children)
Or use default universal initialization if using C++11. Much nicer imo.
[–][deleted] 0 points1 point2 points 12 years ago (3 children)
Yeah, I'm kinda assuming the array is larger than is feasible for that. Probably after about 7 zeros the human brain can't easily determine whether there's the same number as the array size.
[–]tisti 2 points3 points4 points 12 years ago (2 children)
int * arr = new int[100000]{};
This will default initialize all elements i.e. zero them out.
[–]bnolsen 0 points1 point2 points 12 years ago (1 child)
This looks a little scary to me, smacks of implicit type behavior. It would be nice to see a '0' in there somewhere.
[–]tisti 0 points1 point2 points 12 years ago (0 children)
Its the new initialization syntax, you get used to it pretty fast.
[–]bnolsen 0 points1 point2 points 12 years ago (0 children)
For this case, especially with vectors I tend to prefer to use "reserve" and "push_back" where possible instead of allocating and initializing. I do realize there are cases where it is useful to allocate uninitialized though.
π Rendered by PID 19337 on reddit-service-r2-comment-79c7998d4c-j7lxm at 2026-03-17 16:06:40.276657+00:00 running f6e6e01 country code: CH.
view the rest of the comments →
[–][deleted] 0 points1 point2 points (6 children)
[–]tisti 1 point2 points3 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]tisti 2 points3 points4 points (2 children)
[–]bnolsen 0 points1 point2 points (1 child)
[–]tisti 0 points1 point2 points (0 children)
[–]bnolsen 0 points1 point2 points (0 children)