I was browsing for finding a way to find number of rows and columns in of a given matrix without any additional information and I came around this answer.
Given a matrix, find number of rows and columns
This is the code snippet from the second answer of the question above :
There are no pointers used anywhere in the code posted. Arrays do not decay to a pointer-to-first-element when passed as operand to
ais a 2D array, of type
ais the first item in this 2D array, which is a 1D array of type
sizeof(a)gives the size of the 2D array, equivalent to
sizeof(float) * 9 * 2.
sizeof(a)gives the size of the 1D array, equivalent to
sizeof(float) * 2.
floatis apparently 4 bytes on your system, 4 * 2 = 8.
(1) See the specification of the sizeof operator in ISO 9899:2011 220.127.116.11:
When applied to an operand that has array type, the result is the total number of bytes in the array.
The rule of "array decay" is found in 18.104.22.168/3:
Except when it is the operand of the sizeof operator, or the unary & operator, or is a string literal used to initialize an array, an expression that has type ‘‘array of type’’ is converted to an expression with type ‘‘pointer to type’’ that points to the initial element of the array object and is not an lvalue.