Sujet : Re: technology discussion → does the world need a "new" C ?
De : ben (at) *nospam* bsb.me.uk (Ben Bacarisse)
Groupes : comp.lang.cDate : 09. Jul 2024, 16:58:50
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <877cdur1z9.fsf@bsb.me.uk>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
User-Agent : Gnus/5.13 (Gnus v5.13)
bart <
bc@freeuk.com> writes:
Arrays are passed by reference:
>
void F(int a[20]) {}
>
int main(void) {
int x[20];
F(x);
}
This is the sort of thing that bad tutors say to students so that they
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.
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 than
int(*)[20].
No. a is of type int *.
-- Ben.