Skip to content

Instantly share code, notes, and snippets.

@cshtdd
Created February 25, 2020 15:32
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 cshtdd/65b8fd36c32ca42867592fec2e11f804 to your computer and use it in GitHub Desktop.
Save cshtdd/65b8fd36c32ca42867592fec2e11f804 to your computer and use it in GitHub Desktop.
This is a sample C program. It proves what happens when referencing the memory address of a stack variable declared inside a function
/*
# This is a sample C program
# It proves what happens when referencing the
# memory address of a stack variable declared inside a function
# compile and run the program
gcc -o program1 p.c && ./program1
*/
#include <stdio.h>
int* f1(){
int r = 10;
return &r;
}
int main(){
int* p = f1();
printf("Value: %d \n", *p);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment