Here is this code:
#include <iostream> void toZero(int *mass, int length) { int res[7]; for (int i = 0; i < length; ++i) { res[i] = 0; } mass = res; } int main() { int mass[] = {1, 2, 3, 4, 5, 6, 7}; toZero(mass, 7); for (int i = 0; i < 7; ++i) { std::cout << *(mass + i) << " "; } return 0; } Result of performance:
1 2 3 4 5 6 7 Question: In the toZero function toZero first element of the mass array after the line mass = res; must (?) refer to the first element of the res array. But this does not happen, why?
toZero, a local variablemassis created, into which themassvalue from themainfunction (that is, the address of the first element of the array) is placed. After exiting thetoZerofunctiontoZerothis local variable is destroyed, and themassfrommainis obviously not changed. - user194374massis a local variable, you change itmass = res, but don't use it anywhere else - Vladimir Gamalyanresdeclaration from a function, since it is also a local variable. 2) To transfer totoZeronotint*, butint**. - user194374