[ad_1]
The function isn’t the pointer. The return value is
int *since it returns an array ofint.You need a pointer to access an array. If it’s not a pointer, then you are expecting a single
intvariable.If it’s not static, then the array will be deallocated and gone when the function reached to
return. The array is neither a global variable, nor an allocated memory in heap, so it will be deallocated when the function reached toreturn. If you make itstatic, it works like a global variable (not exactly) and will not be deallocated when the function reaches to the end.Read number 1.
Lastly, you get segmented fault because the function returned a dangling pointer because the array is not static therefore deallocated when the function reached to the end.
3
[ad_2]
solved why the array is static [closed]