array created on stack can not be returned from function in C programming

Опубликовано: 02 Октябрь 2024
на канале: CppNuts
3,036
like

Returning an array from a function is kind of a daily job of a software engineer, but if you are beginner then you might do it wrong.
You can't just return the array from the function because it was created on stack and the moment function is returned the memory will be claimed and receiver end will try to access freed memory which is not good.

So the solution to this problem is that you can use the static array and then return that array that will not have any memory issue because static variable or array or object just get created once and will remain there till the program exist.

JOIN ME
   / @cppnuts  
  / cppnuts  

#cprogramming #interview #softwareengineer