Passing pointer to local variable to function: is it safe?

c, pointers, stack

Solution

The scope of `i` is `func1` and it outlives the call to `func2`. So it is perfectly safe.

Problem

For example: ``` void func1(){ int i = 123; func2(&i); } void func2(int *a){ *a = 456; } ``` When `func1` calling `func2`, a pointer to local variable is passed to `func2` -- the pointer is pointed to the stack. Is this safe for the rules of C? Thanks.

Original source

Related problems