You can't, but you don't need to. When you declare a variable inside a function as you have it is called an automatic variable because it gets deleted (freeing its memory) automatically at the end of the function.
If you want to restrict the lifetime of an automatic variable you can introduce a scope using {}
like this:
void someFunc( void )
{
// do some stiff here ...
{ // <- introduce a temporary scope
char str[6] = {"Hello"}; // this is local to your new scope
// some processing here ...
} // <- your array str[] is destroyed here
// do some more stuff here, str[] has disappeared
}
Without the extra comments for clarity:
void someFunc( void )
{
// do some stiff here ...
{
char str[6] = {"Hello"};
// some processing here ...
}
// do some more stuff here ...
}
Introducing a new scope inside a function is a common idiom used to clean up the broader scope of extraneous variables (a potential source of bugs) but also to leverage the power of RAII.
For example when locking a mutex to synchronize a small portion of the function's code.