bgc icon indicating copy to clipboard operation
bgc copied to clipboard

5.7: Missing "printf()" (and some parentheses)?

Open acid-bong opened this issue 2 years ago • 0 comments

The example program is written this way:

sizeof(int); // Returns size of an `int`
sizeof p     // p is type int*, so returns size of `int*`
sizeof *p    // *p is type int, so returns size of `int`

Shouldn't it use printf() instead, so that readers can observe themselves what is getting returned (especially those who copypaste and then troubleshoot)? And shouldn't sizeof() always accept arguments in parentheses?

printf("%zu\n", sizeof(int)); // Returns size of an `int`
printf("%zu\n", sizeof(p));   // p is type int*, so returns size of `int*`
printf("%zu\n", sizeof(*p));  // *p is type int, so returns size of `int`

acid-bong avatar Aug 09 '22 21:08 acid-bong