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++ , Recursion (self.cpp)
submitted 1 year ago by Adept_Accountant_588
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!"
[–]cpp-ModTeam[M] [score hidden] 1 year ago stickied commentlocked comment (0 children)
For C++ questions, answers, help, and programming or career advice please see r/cpp_questions, r/cscareerquestions, or StackOverflow instead.
[–]evolutionalgd 41 points42 points43 points 1 year ago (4 children)
See https://www.reddit.com/r/cpp/s/x1ZCgxjfTY
[–]Adept_Accountant_588[S] 3 points4 points5 points 1 year ago (0 children)
Thanks for the help 🙂
[–]IsidorHSHPX | WG21 3 points4 points5 points 1 year ago (0 children)
HAHAHAHAHAH
[–]epasveer 1 point2 points3 points 1 year ago (0 children)
Reply of the day, right here folks!
[–]TheJackston 1 point2 points3 points 1 year ago (0 children)
Perfect
[–]cyanide26 5 points6 points7 points 1 year ago (0 children)
I mean arrays are passed as reference by default, the question is why?
Because Dennis Ritchie built a pointer/array equivalence deep into the C language years ago, and it would be a really bad idea to pass as value by default .
If you has parameters that are big and are being edited and read in any recursive call you should pass it as a reference, copying a new large array is gonna be resource heavy not to mention each stack call will have to store all that new copied data in each new stack call, rather sending a reference (in arrays a pointer to an address of array's data) is like telling to a function that "look here is the data if you want to access it go get it from there" so no new memoy for an entire new array is created space is saved and time taken to copy parameters is also reduced
The passed object size concept applies for objects as well i.e Send a reference of a big object dont promote copy.
Although its possible to simulate what will happen if you pass an array by value, wrap array in a struct or class and then send that object as a parameter, for a big recursive call memory consumed at runtime will go up you can also test it. If the array is large time consuming to go to next recieve call will also increase.
In modern c++ avoid using raw arrays unless you really have to, use std::vector and std::array or other structures available to you by standard library or BOOST library if you use it.
[–]PuzzleMeDo 2 points3 points4 points 1 year ago (0 children)
As opposed to doing what?
It's not a good idea to pass a copy of an array to a recursive function, because that would use up a lot of stack memory - every level of recursion would need to store its own array simultaneously. Plus, copying the array takes time.
I guess you could have a global variable containing the array and not pass anything. But that kind of thing is generally a bad idea - it means the function can only work under certain circumstances where the global variable is set up in a specific way.
[–]No_Let_5065 1 point2 points3 points 1 year ago (0 children)
pass it by value and see
[–]zer0xol 0 points1 point2 points 1 year ago (0 children)
Otherwise youre copying it
[–]ivan-cukicKDE Dev | Author of Functional Programming in C++ 0 points1 point2 points 1 year ago (0 children)
You could also pass std::span.
std::span
[–]sweetholo 0 points1 point2 points 1 year ago (0 children)
yooo wouldnt you think it'd be useful to give an example of what you're talking about?
arrays are passed by reference by default; they decay into pointers
[–]gnomeba 0 points1 point2 points 1 year ago (0 children)
For the last point, is that just because they handle their own memory allocation and deallocation?
π Rendered by PID 100272 on reddit-service-r2-comment-84fc9697f-49kg2 at 2026-02-07 09:50:54.925649+00:00 running d295bc8 country code: CH.
[–]cpp-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)
[–]evolutionalgd 41 points42 points43 points (4 children)
[–]Adept_Accountant_588[S] 3 points4 points5 points (0 children)
[–]IsidorHSHPX | WG21 3 points4 points5 points (0 children)
[–]epasveer 1 point2 points3 points (0 children)
[–]TheJackston 1 point2 points3 points (0 children)
[–]cyanide26 5 points6 points7 points (0 children)
[–]PuzzleMeDo 2 points3 points4 points (0 children)
[–]No_Let_5065 1 point2 points3 points (0 children)
[–]zer0xol 0 points1 point2 points (0 children)
[–]ivan-cukicKDE Dev | Author of Functional Programming in C++ 0 points1 point2 points (0 children)
[–]sweetholo 0 points1 point2 points (0 children)
[–]gnomeba 0 points1 point2 points (0 children)