-
Passing a const value
If I pass a constant value into a function is the memory allocated for the variable on the stack or heap? There is an example bellow.
void foo( const int value )
{
}
What i mean is, Is value declaired on the heap or stack? I am thinking the only values stored in the heap are pointers but I'm not sure about constants...
Thanks
Jeremy
-
> void foo( const int value )
The const in this context just means that foo will not modify the parameter. Nothing changes in the way functions are called.
This is especially important when you start passing pointers, and you want to stop the function from unintentionally modifying something outside it's immediate scope.
-
Thanks for the reply, but is the memory for "value" declaired on the stack or the heap??? I think it's allocated on the stack, but I can't find any documentation on this.
-
Passing a const value
It is on the stack. Allocating memory from the heap requires the use of the new operator.
The const is a modifier that tells the compiler that the data type is constant ( not modifiable ). Const has nothing to do with where the memory is allocate from.
dang
-
Thanks, That was what I was thinking but wasn't positive....
Thanks for the help...
Jeremy