I recently came back to C after a long time (about 12+ years).
For one thing pointers seem a lot less complicated than I remember, in fact they’re pretty easy to understand. Besides this I’ve found a like the simplicity of the language and the closeness to the machine.
I think what changed from my college days regarding pointers is a better understanding of the stack and exposure to languages like C# with reference and value types.
I’ve written a short program that creates a tree data structure and that allows to navigate it in three different ways:
Depth first pre-order
Depth first post-order
Depth first just means starting from one node and going as deep as possible until you find a leaf node (a node with no children) and then backtracking. You can do this in an iterative way but for me this is so much simpler to understand using recursion.
The difference between pre-order and post-order is when you apply your operation on the tree node, before or after continuing traversal of the tree. You can look at the example below.
Breadth first on the other hand is easier done in an iterative way. The key here is keeping a second data structure, a queue to store the nodes. After you visit a node you enqueue it’s children and visit them in turn, printing their value and enqueuing they’re children in turn.
It’s all pretty simple stuff but I needed a refresher on this topic and also something simple to start writing C code again.
The function to create the data uses the tree from the Wikipedia article on Tree.
Here is the output from traversing the tree depth first pre-order: 2, 7, 2, 6, 5, 11, 5, 9, 4
And here is the output from traversing the tree breadth first: 2, 7, 5, 2, 6, 9, 5, 11, 4
If you have any suggestions to improve the code or see any mistakes don’t hesitate to point them out in the comments.
I will probably look into doing some basic compression in C next and then as a further project I might end up converting these in Rust for the experience of comparing the two languages. Hopefully I might get some insights into Rust at the same time.
Today I’ve found a great extension for Visual Studio. I often hit the toggle that changes the mouse wheel from scrolling text to zooming text. For me that’s a really annoying interruption to my workflow and one of my Visual Studio pet peeve.
I tend to use the keyboard a lot with a bit of mouse on the side. This means one of my finger is often on or near the Ctrl key. The toggle is
`Ctrl + the scroll wheel` so I frequently end up hitting it.
Apparently I’m not the only one because someone made an extension to disable this very feature: Disable Mouse Wheel Zoom.
I can’t recommend it enough ;). There are other ways to change the zoom level and I really don’t need to toggle this feature (I’m scrolling and using Ctrl chords much more often than I need to change the text size).