[Solved] why the array is static [closed]


  1. The function isn’t the pointer. The return value is int * since it returns an array of int.

  2. You need a pointer to access an array. If it’s not a pointer, then you are expecting a single int variable.

  3. 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 to return. If you make it static, it works like a global variable (not exactly) and will not be deallocated when the function reaches to the end.

  4. 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

solved why the array is static [closed]