C pointer array scope and function calls
Posted
by juvenis
on Stack Overflow
See other posts from Stack Overflow
or by juvenis
Published on 2009-09-09T05:22:53Z
Indexed on
2010/03/28
7:43 UTC
Read the original article
Hit count: 222
I have this situation:
{
float foo[10];
for (int i = 0; i < 10; i++) {
foo[i] = 1.0f;
}
object.function1(foo); // stores the float pointer to a const void* member of object
}
object.function2(); // uses the stored void pointer
Are the contents of the float pointer unknown in the second function call? It seems that I get weird results when I run my program. But if I declare the float foo[10] to be const and initialize it in the declaration, I get correct results. Why is this happening?
© Stack Overflow or respective owner