-
-
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 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
/* | |
# 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