beejjorgensen / bgc

Beej's Guide to C Programming source
Other
470 stars 88 forks source link

A code line that breaks the flow of following the guide for beginners #148

Closed Sonotoki-da closed 4 months ago

Sonotoki-da commented 4 months ago

I've been curiously and intently reading up to the pointers part, but been abruptly introduced to an unknown line of code:

#include <stdio.h>

int main(void)
{
    int i = 10;

    printf("The value of i is %d\n", i);
    printf("And its address is %p\n", (void *)&i); // <<< HERE

    // %p expects the argument to be a pointer to void
    // so we cast it to make the compiler happy.
}

Well, while I can't say I don't know casting at all, I'm still not quite familiar with it. So, as a beginner, suddenly getting an unexplained line of code of casting was a bit out of place, because all the other new terms up to this point had been flagged for later explanation. It would be great to fill in the gaps and be a little verbose for the sake of fullness.

Anyways, I appreciate the effort! And I'm gonna say this is such a good guide, I got all my questions answered!

beejjorgensen commented 4 months ago

I've added a note to help clarify it since this is literally the first time the word "cast" appears in the guide. Thanks for the suggestion!