Why does sizeof(array) give the total bytes, but sizeof(pointer) gives 8 (on 64-bit systems)?
In the pantheon of classic computer science literature, few books command the same reverence as the late Alan Feuer’s "Expert C Programming: Deep C Secrets." For decades, this book has sat on the desks of kernel developers, embedded engineers, and compiler writers. While many programmers cut their teeth on The C Programming Language (K&R), they graduate to Feuer’s work when they are ready to understand why C behaves the way it does—especially when it misbehaves. expert c programming deep c secrets pdf github
// File A: extern char *name; // File B: char name[] = "Secrets"; In File A, the linker resolves name to the address of the array. But the code treats that address as a pointer variable , reads the first 8 bytes of the array as if they were an address, and crashes. Feuer’s explanation, using memory diagrams, remains the definitive walkthrough of this linker issue. If you are a student or a self-taught programmer, finding a PDF on GitHub is tempting. While you might stumble upon a cached version or a personal drive link, the real value lies in the community study guides hosted there. Why does sizeof(array) give the total bytes, but
If you are searching for the string you are likely past the stage of printf and for loops. You are in the "lint" zone. You want to understand the difference between an array and a pointer, the mystery of const , and why a[i] is identical to i[a] . // File A: extern char *name; // File
When you declare char c[] = "deep"; , c is a constant address representing the array. The compiler knows the array's size at compile time. When you pass c to a function: void func(char *c) , the array "decays" into a pointer. Inside the function, the compiler only sees a pointer variable; it has no idea if it points to a single char or an array of 1000.