I have defined an array:
float array[3][4][5];
then, what is the difference when
array, array[0], array[0][0], &array[0][0][0]
used as function argument?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The important thing to learn is that, in C, arrays aren’t passed as parameters in their entirety. Instead, the pointer to the first element of the array is passed.
So, given the definition
float array[3][4][5];…array(as a parameter) will be of typefloat (*)[4][5], a pointer to a two-dimensional array of floats (explanation: we can’t pass the array, we pass the pointer to its first element, which is a 4×5 array, hencefloat (*)[4][5]).array[0](as a parameter) will be of typefloat (*)[5], a pointer to a one-dimensional array of floats (explanation:array[0]is a 4×5 array, we can’t pass the array, we pass the pointer to the first element of it, the first element being an array of 5 elements, hencefloat (*)[5]).array[0][0](as a parameter) will be of typefloat *, a pointer to a float (explanation:array[0][0]is an array of 5 elements, we can’t pass the array, we pass the pointer to the first element of it, the first element being a float, hencefloat *).&array[0][0][0](as a parameter) will be of typefloat *, a pointer to a float (explanation:array[0][0][0]is afloat, we pass a pointer to it, hencefloat *).Perhaps, a more elaborate example:
Output (ideone):