Computer has one memory - array of bytes
bytes indexed by addresses
C0 address is 2^64 bytes
Memory diagram
THE Heap (allocated memory): Grow from down to top
THE Stack (local memory): Grow from top to down
stack-overflow: when these Stack and Heap collide
Accessing OS Memory: segmentation fault
NULL: has segfault, NULL is address 0x0
Code: functions
Strings: separate memory
We can use
address of an array
address of struct
NULL
address of a string
address of a function pointer
&
address-of operator
a function called key_hash
, we get the address by calling &key_hash
(a function's pointer)
type declare typedef int what-to-what-fn(int a, int b);
type store string_to_in* F = &key_hash;*
call function int h = (*F)("hello");'
safety: F != NULL;
, &
ensures \result != NULL
use: pass function pointer on creation time of a struct (object oriented programming)
contracts
YOU HAVE TO DEREFERENCE BEFORE CALLING: (*F)(variable)
Table of Content