Arrays cannot be returned in C ++! That is to say, in C ++, arrays cannot be treated as the return value of the function; otherwise, an error is returned during compilation!
If you want to return the data, you can return the data in the pointer format ~
Now you have to ask, in C ++, the array can be passed to the function as a real parameter. Why cannot the array be returned ?!!!
In C ++, when an array is passed to a function as a real parameter, the real parameter array is not copied to the form parameter, but is converted to a pointer, then, the "That Pointer" is initialized with the real parameter. That is to say, the array parameter variable points to the same memory space as the real parameter variable (which can explain why sizeof (form parameter array) in the function) it is always equal to 4 ", because the form parameter is converted into a pointer! Sizeof (form parameter array) is equivalent to sizeof (a pointer )!), That is to say, you can pass an array real parameter to the function, and then modify the value in the array through the form parameter in the function, then the value in the real parameter group outside the function is modified! Amazing, right ?!
See: C ++ primer Chinese (Fourth Edition) P206-P208
Since the pointer is passed, it is meaningless to return an array created in the function ~ Because the array created inside the function will be destructed after the function is executed, even if it is returned, the data will be lost!
If you still don't give up and argue like me, I can pass in an external array created by a function, and then I will return this external array. Isn't that true? In this case, the structure will not be analyzed!
Even so, you need to know that the array outside the function does not need to be returned, you can directly modify its value inside the function.
To sum up, weigh the balance, so the C ++ medium pressure root will not let the returned array ~