Liste des Groupes | Revenir à cl c |
On 09/07/2024 16:58, Ben Bacarisse wrote:bart <bc@freeuk.com> writes:>
Arrays are passed by reference:This is the sort of thing that bad tutors say to students so that they
>
void F(int a[20]) {}
>
int main(void) {
int x[20];
F(x);
}
never learn C properly. All parameter passing in C is by value. All of
it. You just have to know (a) what the syntax means and (b) what values
get passed.
The end result is that a parameter declared with value-array syntax is
passed using a reference rather than by value.
>
And it does so because the language says, not because the ABI requires
it. A 2-byte array is also passed by reference.
void F(int a[20]) ... declares a to be of type int *. Feel free to rail>
about that as much as you like but that is what that syntax means.
The x in F(x) is converted to a pointer to x[0] since the x is not an
operand of &, sizeof etc. F(x) passes a pointer by value. F receives a
pointer value in a.
Although the type of 'a' inside 'F' will be int* rather thanNo. a is of type int *.
int(*)[20].
And that is different 'int*' how, about from having an extra space which C
says is not signigicant in this context?
Les messages affichés proviennent d'usenet.