r/computerscience • u/ShadowGuyinRealLife • May 22 '25
Discussion Why Are Recursive Functions Used?
Why are recursive functions sometimes used? If you want to do something multiple times, wouldn't a "while" loop in C and it's equivalent in other languages be enough? I am not talking about nested data structures like linked lists where each node has data and a pointed to another node, but a function which calls itself.
104
Upvotes
View all comments
Show parent comment
1
u/ilep May 22 '25 edited May 22 '25
"Functions" in machine level are just jumps to code segments. CPUs don't have same concept of functions as higher level languages so that is a moot point.
Note that some CPUs do have instructions for saving call location to stack and jumping to another address. Some like MIPS are much simpler and leave that explicitly to be done by program itself.