Created
October 30, 2014 14:10
-
-
Save vguerra/2700a655499e510e9067 to your computer and use it in GitHub Desktop.
Modifying variables out of function scope via the stack
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 <stdio.h> | |
int fun() { | |
int a = 1; | |
int *p = &a; | |
while (*p != 10) {p++;} | |
*p = 30; | |
return 0; | |
} | |
int main() { | |
int i = 10; | |
fun(); | |
printf("i = %d\n", i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output of this program is:
i = 30