+ 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

21st Aug 2018, 7:42 PM
K Locher
K Locher - avatar
2 odpowiedzi
+ 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.
21st Aug 2018, 10:12 PM
Микола Федосєєв
Микола Федосєєв - avatar
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
11th Oct 2018, 2:29 AM
Evan B
Evan B - avatar