I know only one case
when arrays passed to a function they decay into a pointer.Can anybody elaborate all the cases in which arrays decay to pointers.
I know only one case when arrays passed to a function they decay into
Share
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.
C 2011 6.3.2.1 3:
In other words, arrays usually decay to pointers. The standard lists the cases when they do not.
One might think that arrays act as arrays when you use them with subscripts, such as
a[3]. However, what happens here is actually:ais converted to a pointer.a[3]is evaluated as*((a)+(3)). That is,ais converted to a pointer, 3 is added to the pointer, and the ***** operator is applied.)Note: The C 2011 text includes “the _Alignof operator.” This was corrected in the C 2018 version of the standard, and I have elided it from the quote above. The operand of
_Alignofis always a type; you cannot actually apply it to an object. So it was a mistake for the C 2011 standard to include it in 6.3.2.1 3.