CAN I DO THIS A[ ]=A[2][3] FOR EXAMPLE?
the signature:
float mat_add(float A[],float B[],float C[]);
Passes in pointers to three arrays. So the dimensions to the arrays must already be fixed before the call to this function.
You have not posted the declarations to those arrays so we cannot know (and as written, the code also cannot know) the dimensions to those arrays.
So when the code says:
A[]=A[x][y];
There is no way to know if the indexes X
and Y
are within the bounds of those arrays.
this part of the expression:
A[]
is taking the address of the array as the destination (L value) and assigning the contents of the entry in the array A[2][3]
and assigning that contents to ??? A[0][0] ???
This is NOT a secure assignment. Amongst other problems, what if there are not (at least 3 rows and at least 4 columns in the array)
Also, the compiler does not know how many columns are in each row of the array, so the compiler does not know how far to index through memory to access each row (beyond the 0
row)
The result is undefined behavior
Suggest changing the signature to:
float mat_add( int rows, int columns, float A[ rows ][ columns ], etc ;
then, before using x
and y
, check that those (input from the user) variables are >0 and for x
<rows and for y
<columns
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…