Last active
August 29, 2015 14:01
-
-
Save SeanTRobinson/53b38a832a96e23cbf97 to your computer and use it in GitHub Desktop.
Determines whether the stack grows upwards or downwards.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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