Skip to content

Instantly share code, notes, and snippets.

@vguerra
Created October 30, 2014 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vguerra/2700a655499e510e9067 to your computer and use it in GitHub Desktop.
Save vguerra/2700a655499e510e9067 to your computer and use it in GitHub Desktop.
Modifying variables out of function scope via the stack
#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);
}
@vguerra
Copy link
Author

vguerra commented Oct 30, 2014

The output of this program is:
i = 30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment