Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Recursive Function Calling Example with Stack Addresses
// clang 3.8.0 // Example from Lecture 6 in class on recursive functions // Showing addresses of arguments and data on stack // and values on the heap #include <iostream> using namespace std; int recursiveAdd(int n) { int returnValue; cout << "Calling recursiveAdd: n = " << n << " Address of n = " << &n << " Address of return = " << &returnValue << endl; if (n==1) { returnValue = 1; } else { returnValue = n + recursiveAdd(n-1); } return returnValue; } int main() { const int constValue = 3; int *iPtr = new int; (*iPtr) = 5; int *jPtr = new int; (*jPtr) = 5; int answer; cout << "Test Program" << endl; cout << "Pointer size is " << sizeof(iPtr) << " bytes, int size is " << sizeof(answer) << " bytes" << endl; cout << "Address of const value is " << &constValue << endl; cout << "Calling recursiveAdd: i = " << (*iPtr) << " Address of iPtr = " << iPtr << endl; answer = recursiveAdd((*iPtr)); cout << "Triangle sum of " << (*iPtr) << " = " << answer << endl; cout << "Calling recursiveAdd: j = " << (*jPtr) << " Address of jPtr = " << jPtr << endl; answer = recursiveAdd((*jPtr)); cout << "Triangle sum of " << (*jPtr) << " = " << answer << endl; return 0; }
run
|
edit
|
history
|
help
0
Throttle Example using a circular queue (Push all but 2 less than maxSize; then pop all but 2 of current size)
vf
UTF-8 in C++11
void pointer
MPL 2-1
Linker error while passing constexpr variable as const &
Segment Tree Impl
problem_name_2
Mi primer ejemplo con RexTester colgado en My wall
the usual name hiding rules do apply with using directives