What does this line exactly mean?
It is clear what define is, but I don’t understand why is passing the pointer of x at the denominator:
#define ArrayLength(x) (sizeof(x)/sizeof(*(x)))
thanks
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 denominator
is the length of the first element in the array in bytes. The variable
xis of an array type, and it decays to a pointer, pointing to the start of the array. The asterisk (*) is the dereference operator, so*(x)means “the data pointed to byx“.The numerator
applies the
sizeofoperator to an array type. This gives the length of the entire array in bytes.The macro could also be written as
which is perhaps easier to read.