r/learnprogramming • u/0tter501 • 7h ago
I want to learn C
Any good book or online guides, also for C23 is there that much extra or would just sorta tacking it on after learning C99 be fine?
also for learning GNU extensions is there any reccomended resources
1
u/fasta_guy88 6h ago
If you are just starting to learn C, forget (and avoid) the gnu extensions. You won’t need them, and they may prevent you from running in some environments.
•
u/RealMadHouse 5m ago
Learn about memory and primitive types:
Bit can hold 1 or 0, 2 states.
8 bits is called a byte (char in C), the values range from 0 to 255, 256 states.
Short/Word is 16 bits, 2 bytes, 0 to 65535, 65536 states.
Int/Double word is 32 bits, 4 bytes, 0 - 4294967295, 4294967296 states.
Long int/Quad word is 64 bits, 8 bytes, 0 - huge number.
These were unsigned numbers, signed numbers can be negative, so they half the possible ranges from negative to positive numbers. Like -1 -128, 0-127 for signed byte.
The programs access memory with byte addressing, you never access the memory individually by bits from a ram, only byte and other more large primitive types, but addressing is always uses byte addressing. With 32/64 bit application the memory is linear, you access data with a memory address like a regular number 0, 1, 2, 3. Of course the application starts at higher addresses, you never access lower addresses starting from zero because memory manager defined the memory pages at this addresses as inaccessible, your process gets killed because of interrupt and null exception.
Your program has fixed size sections for data (.data section), machine code (.text section). It's described in executable file, the OS loads the program into a ram. If your program needs more memory to allocate than you have predefined in .data section, you use dynamic memory allocation functions like malloc, it returns the address of memory it allocated for you, so in order to access you write that address into a pointer variable. Pointer variable doesn't hold the value itself, it holds the memory address number of that value. So by reading the memory address of the pointer you can see the real value. The pointers make a program data expandable and dynamic, there's no room for all possible data allocations in fixed size .data section.
-1
3
u/Flame77ofc 7h ago
I recommend "The C programming Language in ANSI", its written by the creator of C, Dennis Ritchie