Logan wrote:
/* My question is why the output of this program is not 2. Thank you in
advance. */
void recieve_array(char a[]);
`receive_array` takes a pointer-to-char: in an argument declaration,
an argument of type T[] is rewritten as an argument of type T*. This
is for compatibility with an actual array value being converted
to a pointer to it's first element when the array appears in a
[non-sizeof, non-&] expression.
int main() {
char array[2];
recieve_array(array);
}
void recieve_array(char a[]) {
printf("%d", sizeof(a)); // WTF!?!!? This outputs 4 which is strange.
}
On your machine, `sizeof (char*)` is 4, and hence so is `sizeof(a)`.
--
Sighs Hedgehog
"Who do you serve, and who do you trust?" /Crusade/