Everything you need to know about pointers in C
c-programmingpointersmemory-managementtutorial
Abstraction: Comprehensive C pointer tutorial covering declaration through function pointers
Key points:
- A pointer is a memory address; dereferencing with
*reads/writes the value at that address;&yields the address of a variable - Common pitfall:
int* ptr_a, ptr_bdeclares only ptr_a as a pointer; ptr_b is a plain int because the asterisk is per-variable, not per-type - Arrays decay to pointers to their first element in most contexts;
sizeof(array)is the exception that returns total array size - Subscript operator
[]is purely pointer arithmetic:array[i]is identical to*(array + i), scaled bysizeof(type) - Function pointer declaration syntax:
char (strcpy_ptr)(char dst, const char src); typedefs are recommended to reduce complexity - Strings in C are null-terminated char arrays with no native string type; all string.h functions operate on char pointers
Connections: C Programming · Memory Management · Pointers
Source: http://boredzo.org/pointers/