Category : stack

In one of my programs I was using a for each loop that looked similar to this for(auto component : components) { doSomethingWithComponent(component); } and visual studio complained that this would cause the function to use more stack memory than the maximum, so I changed the loop to: for(int i = 0;i<components.size();i++) { doSomethingWithComponent(components[i]); } ..

Read more

What would be the function call mechanism for above code ? Draw the run-time stack for the following code snippet and comment on the activation record: # implemented in c++ link for visualization of code= https://pythontutor.com/visualize.html#code=%23include%20%3Ciostream%3E%0A%0Ausing%20namespace%20std%3B%0A%0A%0Avoid%20fun%28int%20n%29%0A%7B%0A%0A%20%20%20%20if%28n%20%3E%200%29%0A%0A%20%20%20%20%7B%0A%0A%20%20%20%20%20%20%20%20fun%28n-1%29%3B%0A%0A%20%20%20%20%20%20%20%20cout%20%3C%3C%20n%20%3C%3C%22%20%22%3B%0A%0A%20%20%20%20%20%20%20%20fun%28n-1%29%3B%0A%0A%20%20%20%20%7D%0A%7D%0A%0A%0Aint%20main%28%29%0A%7B%0A%0A%20%20%20%20fun%285%29%3B%0A%0A%20%20%20%20return%200%3B%0A%7D&cumulative=false&curInstr=1&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=cpp_g%2B%2B9.3.0&rawInputLstJSON=%5B%5D&textReferences=false #include <iostream> using namespace std; void fun(int n) { if(n > 0) { fun(n-1); cout << n <<" "; ..

Read more