4 ms·
Not a simple general intro to pointers A useful gentle intro to the C type feature of pointers to arrays. The C language has more than one way of accessing a
by prosaic-hacker 6y ago
Not a simple general intro to pointers
A useful gentle intro to the C type feature of pointers to arrays.
The C language has more than one way of accessing arrays. Other languages don't.
In the classic 80s teaching language Pascal if you started with pointers it was because you where working with linked lists.
Most people I have taught programming to conflated the pointer access in C and the linked list concepts to their disadvantage.
I taught linked lists first and left the point abstraction intact. Later I crossed the the layer of abstraction to explain memory access details.
I have had more success (less learning difficulties) this way.
- jpm48 6y agoTo quote K & R "In C, there is a strong relationship between pointers and arrays, strong enough that pointers and arrays should be discussed simultaneously" ... however they also say "Pointers have been lumped with the goto statement as a marvelous way to create impossible to understand programs". I use both these quotes in my lectures.
- pjmlp 6y ago> The C language has more than one way of accessing arrays. Other languages don't. Like this? procedure ArrayDemo; var data : array [1..20] of Integer; ptr : ^Integer; i : Integer; begin ptr := @data[low(data)]; for i:=low(data) to high(data) do begin WriteLn(ptr^); ptr := ptr + Sizeof(Integer) end end;