+ 2
Why is func(buf) equal func(&buf)
Please, can somebody explain why line 15 and 16 are equal in result (and also in assembler)? Why does it compile only as long as the function parameter is void* ? Beside this, don’t blame me ‘bout the code quality. It is legacy code and shortened to show the essential part. https://code.sololearn.com/cwE4r7D69AHa/?ref=app
2 ответов
+ 3
It is a very interesting thing. While buf and &buf have different types, physical address value is the same for both. The address of the first byte is the same as the address of the whole string.
Thanks for a good question.
0
In the C tutorial they explain that an array (buf, in this case) is actually syntactic sugar for a pointer to the first element in the array, so &buf points to the first character, and so does buf