Allen Allen - 2 months ago 5
C++ Question

Does call by value of a function change the original value of the parameters?

Would this function change the original values in the matrix that I use to call this function?
Thank you for the help.

void powerup(char mat[9][9])
{
for(int i=0;i<9;++i)
{
for(int j=0;j<9;++j)
{
mat[i][j]=su[i][j];
}
}
}

Answer

Yes, this function will change the original values in the matrix.

Call by value means the arguments to a function are copied onto the stack. The function can then modify these copies without changing the values outside. But this is never the case with arrays.

When you have an array as a parameter, it will always be converted to a pointer. This means

void powerup(char mat[9][9])

and

void powerup(char (*mat)[9])

are the same.

Comments