If C does not support passing a variable by reference, why does this work?
#include
void f(int *j) {
(*j)++;
}
int main() {
int i = 20;
pointers and references are two different thigngs.
A couple of things I have not seen mentioned.
A pointer is the address of something. A pointer can be stored and copied like any other variable. It thus have a size.
A reference should be seen as an ALIAS of something. It does not have a size and cannot be stored. It MUST reference something, ie. it cannot be null or changed. Well, sometimes the compiler needs to store the reference as a pointer, but that is an implementation detail.
With references you don't have the issues with pointers, like ownership handling, null checking, de-referencing on use.