Skip to content

Instantly share code, notes, and snippets.

@SeanTRobinson
Last active August 29, 2015 14:01
Show Gist options
  • Save SeanTRobinson/53b38a832a96e23cbf97 to your computer and use it in GitHub Desktop.
Save SeanTRobinson/53b38a832a96e23cbf97 to your computer and use it in GitHub Desktop.
Determines whether the stack grows upwards or downwards.
#include <iostream>
class MethodCaller {
public:
static int getMemoryAddress() {
int var = 2;
return var;
}
};
void runLoop(int n);
int main() {
runLoop(10);
return 1;
}
void runLoop(int n) {
for (int i = 0; i < n; i++) {
int firstVar = 1;
printf("Memory of First: %i\n", &firstVar);
int secondVar = MethodCaller::getMemoryAddress();
printf("Memory of second: %i\n", &secondVar);
if (&secondVar > &firstVar) {
printf("Stack is growing up.\n");
}
else {
printf("Stack is growing down.\n");
}
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment