4 ms·
Make sure you explain pointers well, the additional level of indirection introduced by them is usually hard to grasp for beginners. Show the relation between p
by adambyrtek 16y ago
Make sure you explain pointers well, the additional level of indirection introduced by them is usually hard to grasp for beginners.
Show the relation between pointers and arrays. Offer some best practices on using pointers. Explain the most common caveats like buffer overflows, problems with null terminated strings or off by one errors.
- cperciva 16y agoEven better, make sure you explain function pointers well.
- alnayyir 16y agoEven better, I'll explain when and why to use function pointers (finite state automata are a common use case)
- edanm 16y agoI think a more common and more important use is callback functions.
- pasbesoin 16y agoSome years ago, I ran across and saved off a copy of a some-dozen page reference, in PDF format, titled something along the lines of 'everything you (will) ever need to know about pointers (in C)'. It appeared to be quite well regarded. But, that laptop was ripped off and the particular file appears not to have made it into backups. Does this description happen to ring a bell? Any references?
- JMStewy 16y agoMight it be this?: http://boredzo.org/pointers/ http://boredzo.org/pointers/ or possibly this (pdf warning): http://home.earthlink.net/~momotuk/pointers.pdf http://home.earthlink.net/~momotuk/pointers.pdf
- pasbesoin 16y agoThe second link, I think. Note that it's also available in an HTML version, at: http://pweb.netcom.com/~tjensen/ptr/pointers.htm http://pweb.netcom.com/~tjensen/ptr/pointers.htm
- loup-vaillant 16y agoI second the proper teaching of pointers. However, make sure you explain variables just as well, for they too introduce a level of indirection¹, which is almost always overlooked. C doesn't syntactically distinguish rvalues and lvalues, so this level of indirection often goes unnoticed. I strongly suspect this is why learning pointers is often hard: trying to grasp an additional level of indirection before having comprehended the first one is nearly hopeless. [1] Variables are containers for values. This is isomorphic to a constant pointer to a mutable cell.