Declaring variables in a function creates storage for those variables when the function is called.
This kind of storage only lasts until the function returns.
This is good! The variables are only used inside the function and the storage is automatically released when the function returns!
But this isn't always what a programmer needs.
For example, this makes it difficult to write a function:
double *makeArray(int n);
that would create an array of doubles with n elements and return a pointer to the first element of the the array.
Why? Well if the makeArray function declares a local array of size equal n and returns it, the storage for the array would disappear (be released) just as it was returned to the caller. Released (or free) memory is likely to be reused for another purpose and so any data stored in it could be overwritten very soon.