1

can't understand the output of the simple c code about function call in linux

view story
linux-howto

http://stackoverflow.com – I write a simple code when I try to understand the function call. But I can't understand it's output. #include <stdio.h> int* foo(int n) { int *p = &n; return p; } int f(int m) { int n = 1; return 999; } int main(int argc, char *argv[]) { int num = 1; int *p = foo(num); int q = f(999); printf("[%d]\n[%d]\n", *p, q); /* printf("[%d]\n", *q); */ } Output: [999] [999] Why *p is 999? Then I modified my code like follows: #include <stdio.h> int* foo(int n) { int *p = &n; return p; } int f() { int n = 1; return 99 (HowTos)