<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
      <title></title>
      <link>https://danieltam.com</link>
      <description></description>
      <generator>Zola</generator>
      <language>en</language>
      <atom:link href="https://danieltam.com/rss.xml" rel="self" type="application/rss+xml"/>
      <lastBuildDate>Thu, 03 Sep 2026 00:00:00 +0000</lastBuildDate>
      <item>
          <title>Emergent Abilities of Large Language Models - Paper Summary</title>
          <pubDate>Thu, 03 Sep 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/emergent-abilities-summary/</link>
          <guid>https://danieltam.com/posts/emergent-abilities-summary/</guid>
          <description xml:base="https://danieltam.com/posts/emergent-abilities-summary/">&lt;p&gt;A summary of &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;doi.org&#x2F;10.48550&#x2F;arXiv.2206.07682&quot;&gt;Emergent Abilities of Large Language Models&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;introduction&quot;&gt;Introduction&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;Emergent abilities arise &lt;strong&gt;unpredictably&lt;&#x2F;strong&gt;, i.e. it cannot be predicted simply by extrapolating the performance of smaller models.&lt;&#x2F;li&gt;
&lt;li&gt;Scaling laws can be used to predict the effect of scale on the performance of a language model.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Important Definition&lt;&#x2F;strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Emergence is when quantitative changes in a system result in qualitative changes in behaviour.&lt;&#x2F;em&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;The paper explores emergence with respect to model scale&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;emergent-abilities-definition&quot;&gt;Emergent Abilities Definition&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;Plotting scale ($x$-axis) against performance ($y$-axis) show that there is a &lt;em&gt;phase transition&lt;&#x2F;em&gt; point, a change that occurs only when a certain threshold of scale is crossed.&lt;&#x2F;li&gt;
&lt;li&gt;It is wise to view emergence as a function of many correlated variables, such as number of parameters, training computation, etc.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;few-shot-prompted-tasks&quot;&gt;Few-Shot Prompted Tasks&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;This is an ability of the prompting paradigm.&lt;&#x2F;li&gt;
&lt;li&gt;Involves providing input-output examples in the model&#x27;s context (input) before asking it to perform the actual task at hand.&lt;&#x2F;li&gt;
&lt;li&gt;We can observe a model&#x27;s phase transition for this ability by plotting its output accuracy for the task against its compute scale. There is an obvious sharp turn where its performance goes well-above random at a certain threshold of scale.&lt;&#x2F;li&gt;
&lt;li&gt;Example of few-shot prompted task: Recovering a word from its scrambled letters, part of the BIG-Bench benchmark.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;augmented-prompting-strategies&quot;&gt;Augmented Prompting Strategies&lt;&#x2F;h1&gt;
&lt;p&gt;This section discusses other prompting&#x2F;fine-tuning strategies that augment abilities.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Multi-step reasoning (Chain-of-Thought prompting)
&lt;ul&gt;
&lt;li&gt;Prompting that guides them to produce a sequence of intermediate steps before its final output, especially for tasks that require reasoning.&lt;&#x2F;li&gt;
&lt;li&gt;Why is it emergent? It only becomes effective with a sufficiently large scale.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;blockquote&gt;
&lt;p&gt;This is often automated in reasoning models these days&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Instruction following
&lt;ul&gt;
&lt;li&gt;Fine-tune a model on some tasks phrased as instructions.&lt;&#x2F;li&gt;
&lt;li&gt;It is then shown that models are able to respond to follow instructions describing a task more appropriately&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Program execution
&lt;ul&gt;
&lt;li&gt;Fine-tuning the models to predict intermediate outputs and remember it for multi-step computations. (&lt;em&gt;scratchpad&lt;&#x2F;em&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Model calibration&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;These are many more emergent abilities that we can find out there.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;potential-explanations-of-emergence&quot;&gt;Potential Explanations of Emergence&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;Sequential computations that correlate to the number of layers&lt;&#x2F;li&gt;
&lt;li&gt;More parameters $\implies$ better memorisation&lt;&#x2F;li&gt;
&lt;li&gt;Imperfection with evaluation metrics
&lt;ul&gt;
&lt;li&gt;Evaluating based purely off of the final product without giving credit to the improvement in intermediate steps may disguise that gradual improvement as a sudden and unpredictable jump in final answer accuracy. (e.g. evaluating exact string match)&lt;&#x2F;li&gt;
&lt;li&gt;Issue with explanation
&lt;ul&gt;
&lt;li&gt;Emergent abilities are still observed with classification problems&lt;&#x2F;li&gt;
&lt;li&gt;Does not explain the jump in the quality of &lt;strong&gt;intermediate&lt;&#x2F;strong&gt; steps that have been observed as well&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;An alternative evaluation: cross-entropy loss
&lt;ul&gt;
&lt;li&gt;It is shown that cross-entropy loss improves even for smaller models where the downstream metrics (exact match, BLEU, and accuracy of output) are close to random&#x2F;do not improve. This implies that downstream metrics are masking underlying improvements.&lt;&#x2F;li&gt;
&lt;li&gt;Issue: This new analysis still does not explain why downstream metrics are emergent, nor does it enable any form of prediction of emergence&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;beyond-scaling&quot;&gt;Beyond scaling&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;Abilities may be achieved at smaller scales with improvements in other aspects, not just model scale (e.g. model architecture, high-quality data, training procedure).&lt;&#x2F;li&gt;
&lt;li&gt;This is an important research path for finding ways to make these abilities more accessible.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;emergent-risks&quot;&gt;Emergent risks&lt;&#x2F;h1&gt;
&lt;p&gt;LLMs carry societal risks such as truthfulness, bias, and toxicity. It&#x27;s important we consider whether or not these risks are emergent as well.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;sociological-changes&quot;&gt;Sociological changes&lt;&#x2F;h1&gt;
&lt;p&gt;We should also consider how scale affects not just the model, but the community surrounding it, how it&#x27;s used, and social perception.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;directions-of-future-work&quot;&gt;Directions of Future Work&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;Further model scaling&lt;&#x2F;li&gt;
&lt;li&gt;Improved model architecture and training&lt;&#x2F;li&gt;
&lt;li&gt;Data scaling&lt;&#x2F;li&gt;
&lt;li&gt;Better techniques for and understanding of prompting&lt;&#x2F;li&gt;
&lt;li&gt;Frontier tasks (tasks on which performance remains lacklustre)&lt;&#x2F;li&gt;
&lt;li&gt;Understanding emergence&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;glossary&quot;&gt;Glossary&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;em&gt;Emergent&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;An ability is &lt;em&gt;emergent&lt;&#x2F;em&gt; if it is not present in smaller models, but only in larger models.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;em&gt;upstream&#x2F;downstream tasks&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Upstream tasks are the tasks that are used for pre-training. They are general problems that the model solves to learn and improve. It&#x27;s how the language model learns the language, its grammar, syntax, etc.&lt;&#x2F;li&gt;
&lt;li&gt;Downstream tasks are the practical, specialised tasks that a pre-trained model has to undertake. This is either used for fine-tuning or for practical usage.&lt;&#x2F;li&gt;
&lt;li&gt;Upstream -&amp;gt; Downstream, it&#x27;s a pipeline. Downstream tasks are the tasks that are further down the pipeline.&lt;&#x2F;li&gt;
&lt;li&gt;The idea of pre-training models on upstream tasks and fine-tuning on downstream tasks is also known as transfer learning&lt;&#x2F;li&gt;
&lt;li&gt;Examples
&lt;ul&gt;
&lt;li&gt;Training GPT to perform sentiment analysis, or text classification, etc.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Scaling laws are less reliable on downstream tasks&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;em&gt;perplexity (of a model)&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Measure of how well a language model predicts a sample of text (from a statistical perspective, not a factual standpoint)&lt;&#x2F;li&gt;
&lt;li&gt;How well the model mimics human language patterns and predicts a specific sequence of words.&lt;&#x2F;li&gt;
&lt;li&gt;Perplexity of $1 \implies$ the model is absolutely certain&lt;&#x2F;li&gt;
&lt;li&gt;Perplexity $=$ vocabulary size $\implies$ the model is very confused, and every token in the vocabulary is equally likely.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;em&gt;In-Context Learning&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;The process of enabling a pre-trained model to learn dynamically through prompting without any re-training, simply by providing input&#x2F;output examples.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;em&gt;Context Window&#x2F;Length&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;The number of tokens that the model can &quot;remember&quot;, and take into consideration when generating its output. It includes not just the current prompt, but the conversation history.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>If P then Q (Material Implication) Explained</title>
          <pubDate>Thu, 03 Sep 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/implication-explained/</link>
          <guid>https://danieltam.com/posts/implication-explained/</guid>
          <description xml:base="https://danieltam.com/posts/implication-explained/">&lt;h1 id=&quot;introducing-material-implication&quot;&gt;Introducing material implication&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;code&gt;If &quot;Johnny ate 5 apples&quot;, then &quot;Johnny is fat&quot;&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Above is known as a conditional statement, or an implication. In math, we may assign the premise (or hypothesis) &lt;code&gt;&quot;Johnny ate 5 apples&quot;&lt;&#x2F;code&gt; to a variable &lt;code&gt;P&lt;&#x2F;code&gt;, and the conclusion (or consequent) &lt;code&gt;&quot;Johnny is fat&quot;&lt;&#x2F;code&gt; to a variable &lt;code&gt;Q&lt;&#x2F;code&gt; .&lt;&#x2F;p&gt;
&lt;p&gt;We may rewrite this in mathematical notation, $P \implies Q$ .&lt;&#x2F;p&gt;
&lt;p&gt;We may find the truth table for this statement here:&lt;&#x2F;p&gt;
&lt;p&gt;$\vdots$&lt;&#x2F;p&gt;
&lt;p&gt;Now, one of the most unintuitive things about this is that when &lt;code&gt;P&lt;&#x2F;code&gt; is false, and &lt;code&gt;Q&lt;&#x2F;code&gt; is true, the conditional statement is still regarded as true, known as vacuously true. Why is that?&lt;&#x2F;p&gt;
&lt;h1 id=&quot;explanation&quot;&gt;Explanation&lt;&#x2F;h1&gt;
&lt;p&gt;The statement is still true because &lt;code&gt;P&lt;&#x2F;code&gt; is false. When $P$ is false, that means the premise, or the &quot;cause&quot; of the consequence never occurred in the first place. Johnny never eats the five apples. Because of that, Johnny may &lt;em&gt;&lt;strong&gt;or&lt;&#x2F;strong&gt;&lt;&#x2F;em&gt; may not be fat. Let&#x27;s say he is fat. This however, does not falsify the idea that if Johnny ate 5 apples, he would become fat. The statement is only concerned about the consequence of Johnny eating exactly 5 apples. It doesn&#x27;t make any claim about when Johnny &lt;strong&gt;doesn&#x27;t&lt;&#x2F;strong&gt; eat 5 apples. Perhaps he eats 6 apples.&lt;&#x2F;p&gt;
&lt;p&gt;We have to think of &lt;code&gt;P&lt;&#x2F;code&gt; and &lt;code&gt;Q&lt;&#x2F;code&gt; as independent events, and $P \implies Q$ as a statement that claims a causal relationship between the two independent events. $P$ is not the only means of $Q$ being true. Perhaps Johnny ate 10 apples, or an entire cow, and that made him fat. Who knows? The important thing to note is that if $P$ doesn&#x27;t occur in the first place, we cannot falsify $Q$.&lt;&#x2F;p&gt;
&lt;p&gt;Read also:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;legacy.earlham.edu&#x2F;%7Epeters&#x2F;courses&#x2F;log&#x2F;mat-imp.htm&quot;&gt;Paradoxes of material implication&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Principle of explosion&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Monty Hall Problem Explained</title>
          <pubDate>Thu, 03 Sep 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/monty-hall-problem/</link>
          <guid>https://danieltam.com/posts/monty-hall-problem/</guid>
          <description xml:base="https://danieltam.com/posts/monty-hall-problem/">&lt;h1 id=&quot;introducing-the-problem&quot;&gt;Introducing the problem&lt;&#x2F;h1&gt;
&lt;p&gt;Imagine having three doors. One of which holds a sports car, and the other two, donkeys. Monty Hall is the host of this game show. He knows the contents that lie behind each door. Your goal here is to choose a door that you think holds the sports car. You make an initial choice. It&#x27;s clear that the probability of your initial choice being right, is $\frac{1}{3}$. He opens another door for you, and it is known that the door he opens will always have a donkey behind it. Now, you may choose to either switch from your initial choice, or stay.&lt;&#x2F;p&gt;
&lt;p&gt;Well, math tells us that the probability of you getting the car if you switch now will be $\frac{2}{3}$. Hence, based on statistics, your choice should always be to switch.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;explanation&quot;&gt;Explanation&lt;&#x2F;h1&gt;
&lt;p&gt;Let&#x27;s discuss the intuition behind this.&lt;&#x2F;p&gt;
&lt;p&gt;We know that the probability that our initial choice holds the sports car is $\frac{1}{3}$. This never changes. However, once he opens a donkey door, he eliminates a possibility. Hence, the probability has to go somewhere; it has to concentrate towards the remaining door. That&#x27;s why the remaining door has a higher chance of holding the sports car.&lt;&#x2F;p&gt;
&lt;p&gt;The intuition becomes much more obvious when we extend this scenario to a series of 100 doors. Our initial choice would carry a probability of $\frac{1}{100}$ of being the door with the sports car. Once he opens 98 donkey doors, only two doors remain: our initial choice, and the remaining closed door. In this scenario, it is clear that we should choose to switch, because our initial choice was made from a pool of 100 closed doors. As such, it is more likely that we made an incorrect initial choice, and that the remaining door holds the sports car.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s now summarise that idea:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;If we switch doors, we win only if we initially picked wrong ($\frac{2}{3}$)&lt;&#x2F;li&gt;
&lt;li&gt;If we choose not to switch, we win only if we initially picked correctly ($\frac{1}{3}$)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Hence, we switch because we bet on the fact that we had a higher chance of picking the wrong door as compared to the right door in our initial choice.&lt;&#x2F;p&gt;
&lt;p&gt;The key insight is that Monty always opens a donkey door. This makes switching the more advantageous route.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Controlling a Differential-Drive Robot with a Virtual Joystick</title>
          <pubDate>Fri, 21 Aug 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/diff-drive-webots-sim-virtual-joystick/</link>
          <guid>https://danieltam.com/posts/diff-drive-webots-sim-virtual-joystick/</guid>
          <description xml:base="https://danieltam.com/posts/diff-drive-webots-sim-virtual-joystick/">&lt;h1 id=&quot;introduction&quot;&gt;Introduction&lt;&#x2F;h1&gt;
&lt;p&gt;In this post, I document my learning experience with robot simulation. For the simulation, I created a virtual joystick with Qt, and used it to control the differential-drive robot. Then, I used zenoh-cpp as the middleware, using it to allow the simulation to communicate with the Qt app.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Recursive Self-Improvement (RSI)</title>
          <pubDate>Mon, 03 Aug 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/recursive-self-improvement/</link>
          <guid>https://danieltam.com/posts/recursive-self-improvement/</guid>
          <description xml:base="https://danieltam.com/posts/recursive-self-improvement/">&lt;h1 id=&quot;introduction&quot;&gt;Introduction&lt;&#x2F;h1&gt;
&lt;p&gt;This is a process in which a machine learning model operates on an autonomous loop, rewriting itself in a way that improves itself, and this new improvement will allow for more efficient improvements, resulting in a kind of recursive growth.&lt;&#x2F;p&gt;
&lt;p&gt;RSI exists on a spectrum; different levels of RSI demands varying levels of human intervention. Complete RSI is a goal we have yet to achieve, where an AI completely builds the next improved version of itself without any human involvement.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;self-improvement-vs-recursive-self-improvement&quot;&gt;Self-Improvement vs Recursive Self-Improvement&lt;&#x2F;h1&gt;
&lt;p&gt;A typical modern AI model already self-improves by learning from large datasets. Its self-improvement is enabled by methods such as gradient-descent and backpropagation.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Recursive&lt;&#x2F;em&gt; self-improvement on the other hand, is the idea of a model improving the &lt;strong&gt;rate&lt;&#x2F;strong&gt; at which it improves. This creates a compounding effect, that leads to exponential growth, and a &quot;foom&quot; that propels us to superintelligence.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;forms-of-rsi&quot;&gt;Forms of RSI&lt;&#x2F;h1&gt;
&lt;p&gt;There are a few ways in which this can be achieved:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Using an LLM to generate code for an improved version of the LLM
&lt;ul&gt;
&lt;li&gt;This is an existing form of RSI, because many AI engineers already do make use of AI to code. Hence, the AI generates code that builds the next improved version of itself.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Getting AI to improve its own model architecture&lt;&#x2F;li&gt;
&lt;li&gt;Kaparthy Loop&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>The Role of CMake in Building Libraries - Zenoh Series</title>
          <pubDate>Sun, 26 Jul 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/zenoh-introduction-installation-breakdown/</link>
          <guid>https://danieltam.com/posts/zenoh-introduction-installation-breakdown/</guid>
          <description xml:base="https://danieltam.com/posts/zenoh-introduction-installation-breakdown/">&lt;p&gt;I dove into installation not knowing much about CMake. Hence, I&#x27;d actually placed some blind faith in the documentation. That turned out fine, but here&#x27;s a breakdown for those who need it.&lt;&#x2F;p&gt;
&lt;p&gt;CMake is a meta-build system. It is &lt;em&gt;meta&lt;&#x2F;em&gt; because it doesn&#x27;t actually compile your code, rather, it acts as a middleman between your code and a compiler&#x2F;lower-level build system (like GNU Make). It dynamically provides detailed instructions to your compiler on how it should convert your source code into a binary executable. You guide CMake on how it can do this using a CMakeLists.txt file.&lt;&#x2F;p&gt;
&lt;p&gt;In the CMakeLists.txt, you specify things like:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Project Name&lt;&#x2F;li&gt;
&lt;li&gt;Project Dependencies (include and link directories)&lt;&#x2F;li&gt;
&lt;li&gt;Project Files&#x2F;Organisation (very useful when it comes to larger projects)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This way, instead of running the same long set of commands to your build system&#x2F;compiler, CMake creates a layer of abstraction for developers.&lt;&#x2F;p&gt;
&lt;p&gt;Now that we understand this basic fact, we can break down what&#x27;s happening in step 3.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;First, we create a &lt;code&gt;build&lt;&#x2F;code&gt; directory that sits outside the source directory (the repository we cloned). (it&#x27;s good practice to separate the build and source)&lt;&#x2F;li&gt;
&lt;li&gt;Once we &lt;code&gt;cd&lt;&#x2F;code&gt; to the build directory, we are calling &lt;code&gt;cmake&lt;&#x2F;code&gt; onto the &lt;code&gt;zenoh-c&lt;&#x2F;code&gt; source directory, where sits a &lt;code&gt;CMakeLists.txt&lt;&#x2F;code&gt; file.&lt;&#x2F;li&gt;
&lt;li&gt;Based on this file, CMake will carry out its duty in generating configuration files.&lt;&#x2F;li&gt;
&lt;li&gt;Then, we tell it to build the project within our build directory&lt;&#x2F;li&gt;
&lt;li&gt;Lastly, we install the built program into our system, i.e. copy the built files and configure it such that it becomes more globally accessible.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
</description>
      </item>
      <item>
          <title>Zenoh Installation and Introduction</title>
          <pubDate>Sun, 26 Jul 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/zenoh-introduction-installation/</link>
          <guid>https://danieltam.com/posts/zenoh-introduction-installation/</guid>
          <description xml:base="https://danieltam.com/posts/zenoh-introduction-installation/">&lt;h1 id=&quot;about-zenoh&quot;&gt;About Zenoh&lt;&#x2F;h1&gt;
&lt;p&gt;Zenoh is a lightweight protocol that integrates &lt;em&gt;pub&#x2F;sub&lt;&#x2F;em&gt; (data in motion) and &lt;em&gt;distributed query&lt;&#x2F;em&gt; (data at rest) features into a single place. Its elegance lies in the amount of flexibility and efficiency it provides in return for its minimal overhead.&lt;&#x2F;p&gt;
&lt;p&gt;Zenoh can be deployed in a wide range of scenarios. However, my goal is to use it for robotics. It will allow different components within a robotic system to communicate with each other. For example, a sensor and a controller.&lt;&#x2F;p&gt;
&lt;p&gt;This post will cover the installation of the zenoh-cpp library, which is a header-only &lt;em&gt;binding&lt;&#x2F;em&gt; around the zenoh-c API (or zenoh-pico, but that has a more niche use-case). Since most code samples out there are written in Rust, the language zenoh was originally built in, I thought it&#x27;d be nice to write a more complete introduction to zenoh-cpp, and shine a light on it. With that said, this will be a more beginner-friendly tutorial. Seasoned veterans may want to skip ahead to some code samples.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;installation&quot;&gt;Installation&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;windows&quot;&gt;Windows&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;cmake.org&#x2F;download&#x2F;&quot;&gt;CMake&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.mingw-w64.org&#x2F;getting-started&#x2F;msys2&#x2F;&quot;&gt;GCC&lt;&#x2F;a&gt;
&lt;ul&gt;
&lt;li&gt;Has to be C++17-compliant&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;rust-lang.org&#x2F;tools&#x2F;install&#x2F;&quot;&gt;rustup&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Besides installing it on Windows itself, you have the option of using WSL for development and installation instead. You run into a lot less errors there because there&#x27;s often less uncertainty with development on Linux.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h3 id=&quot;building-from-source-and-installation&quot;&gt;Building from Source and Installation&lt;&#x2F;h3&gt;
&lt;p&gt;In order to install zenoh-cpp, we first need to build and install zenoh-c (since zenoh-cpp is a binding around zenoh-c as mentioned above). So crack open a terminal, and run these commands!&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;rustup-update&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Clone the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;eclipse-zenoh&#x2F;zenoh-c.git&quot;&gt;zenoh-c repo&lt;&#x2F;a&gt; into a new workspace folder of your choice
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git clone https:&#x2F;&#x2F;github.com&#x2F;eclipse-zenoh&#x2F;zenoh-c.git&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;We will build zenoh-c in a dedicated build directory, which will be kept separate from the source directory.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;mkdir -p build &amp;amp;&amp;amp; cd build&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;cmake ..&#x2F;zenoh-c&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;cmake --build . --config Release&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Install the library into our system
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;cmake --build . --target install&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;On Windows, our default installation path is &lt;code&gt;C:&#x2F;Program Files&#x2F;${INSTALLATION}&lt;&#x2F;code&gt;, so you will find it there. If you want to install it into a dedicated local directory, run:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;cmake ..&#x2F;zenoh-c -DCMAKE_INSTALL_PREFIX=&quot;path&#x2F;to&#x2F;installation&quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;blockquote&gt;
&lt;p&gt;Do note that you will then have to point your CMake to the library accordingly&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Now that we&#x27;ve built zenoh-c, we can begin building zenoh-cpp.&lt;&#x2F;p&gt;
&lt;ol start=&quot;5&quot;&gt;
&lt;li&gt;Create a fresh new folder for zenoh-cpp, just to keep things organised.&lt;&#x2F;li&gt;
&lt;li&gt;Clone the zenoh-cpp repository directly into that folder.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git clone https:&#x2F;&#x2F;github.com&#x2F;eclipse-zenoh&#x2F;zenoh-cpp.git&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Install zenoh-cpp with a very similar procedure
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;mkdir -p build &amp;amp;&amp;amp; cd build&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;cmake ..&#x2F;zenoh-cpp&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;cmake .. -DCMAKE_PREFIX_PATH=&quot;C:&#x2F;Program Files&#x2F;${INSTALLATION}&quot;&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;CMAKE_PREFIX_PATH&lt;&#x2F;code&gt; should be where your zenoh-c installation is. By default, &lt;code&gt;C:&#x2F;Program Files&#x2F;zenohc&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;cmake --install . --config Release&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;blockquote&gt;
&lt;p&gt;To get a deeper breakdown of the build process here, you may refer to this &lt;a href=&quot;https:&#x2F;&#x2F;danieltam.com&#x2F;posts&#x2F;zenoh-introduction-installation-breakdown&#x2F;&quot;&gt;optional article&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h1 id=&quot;next-step-project-setup&quot;&gt;Next Step: Project Setup&lt;&#x2F;h1&gt;
&lt;p&gt;Now that we&#x27;ve installed zenoh-cpp into our system, we can start to dive into setting up a project and writing our first few lines of code. You will find this in the next &lt;a href=&quot;https:&#x2F;&#x2F;danieltam.com&#x2F;posts&#x2F;zenoh-project-setup&#x2F;&quot;&gt;article&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;br&gt;&lt;&#x2F;br&gt;
&lt;br&gt;&lt;&#x2F;br&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;glossary&quot;&gt;Glossary&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;strong&gt;Pub&#x2F;Sub (publication and subscription)&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;This is a messaging pattern in which components or nodes within a network are split into two categories: publisher and subscriber (not mutually exclusive).&lt;&#x2F;li&gt;
&lt;li&gt;When a publisher publishes a message (e.g. a node running on a sensor publishes its readings), a list of nodes that are subscribed to it (subscriber nodes), are able to receive those messages, and perform some corresponding operation.&lt;&#x2F;li&gt;
&lt;li&gt;Different protocols implement this pattern differently, but a defining property of this property is the decoupling between the publisher and subscriber, making them independent.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;Distributed Query&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Unlike pub&#x2F;sub, instead of waiting for data to arrive, nodes can perform queries to actively find specific data upon demand. A query is made, and a response is returned.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;Binding&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Some code that acts as an interface for calling some other code. It aims to cover&#x2F;translate the same functionality for the code it binds to, but with a different language. Note that it doesn&#x27;t &quot;port&quot; the functionality over, i.e. rewrite the original code in its entirety.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Zenoh Project Setup and Example</title>
          <pubDate>Sun, 26 Jul 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/zenoh-project-setup/</link>
          <guid>https://danieltam.com/posts/zenoh-project-setup/</guid>
          <description xml:base="https://danieltam.com/posts/zenoh-project-setup/">&lt;p&gt;Hey! This is a work-in-progress. Stay tuned!&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Zenoh CPP Series</title>
          <pubDate>Sun, 26 Jul 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/series/zenoh-series/</link>
          <guid>https://danieltam.com/series/zenoh-series/</guid>
          <description xml:base="https://danieltam.com/series/zenoh-series/">&lt;p&gt;Besides learning how we can use Zenoh, I also dive into the challenges I personally faced while trying to learn it.&lt;&#x2F;p&gt;
&lt;p&gt;Furthermore, I break down little things I&#x27;d simply picked off of Google during the process of development (e.g. code snippets, commands, etc) to form a deeper understanding of what I was really doing.&lt;&#x2F;p&gt;
&lt;p&gt;I do this in hopes of avoiding a &quot;blind leading the blind&quot; situation.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;post-list&quot;&gt;Post list&lt;&#x2F;h1&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;danieltam.com&#x2F;posts&#x2F;zenoh-introduction-installation&#x2F;&quot;&gt;Zenoh Introduction &amp;amp; Installation&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;danieltam.com&#x2F;posts&#x2F;zenoh-introduction-installation-breakdown&#x2F;&quot;&gt;Zenoh Introduction &amp;amp; Installation Process Breakdown (Optional)&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;danieltam.com&#x2F;posts&#x2F;zenoh-project-setup&#x2F;&quot;&gt;Zenoh Project Setup &amp;amp; Sample&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
</description>
      </item>
      <item>
          <title>Notes on Introduction to Information Retrieval, Chap. 6 (Scoring, term weighting and the vector space model)</title>
          <pubDate>Wed, 17 Jun 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/ir-chap6-notes/</link>
          <guid>https://danieltam.com/posts/ir-chap6-notes/</guid>
          <description xml:base="https://danieltam.com/posts/ir-chap6-notes/">&lt;h1 id=&quot;6-1-parametric-and-zone-indexes&quot;&gt;6.1 Parametric and zone indexes&lt;&#x2F;h1&gt;
&lt;p&gt;Digital documents come with &lt;em&gt;metadata&lt;&#x2F;em&gt;. Metadata includes &lt;em&gt;fields&lt;&#x2F;em&gt; (e.g. creation date, file format). Field values are part of a finite set. Each field has one &lt;em&gt;parametric index&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Hence, &lt;code&gt;query processing: merge(standard inverted index, parametric index)&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Zones are like fields, but its contents are not part of a finite set, but free text (e.g. document title, abstracts).
Numerous approaches to indexing zones:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Build separate inverted index for each zone
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;(dict) william.abstract -&amp;gt; (postings) {11, 121, 1441}&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;william.title -&amp;gt; {2, 4, 8, 16}&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Encode zone in which a term occurs in the postings (favourable)
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;(dict) william -&amp;gt; (postings) {(2.author,2.title), 3.author, 4.title}&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;The second approach is favourable because it allows for weighted zone scoring.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;6-1-1-weighted-zone-scoring&quot;&gt;6.1.1 Weighted Zone Scoring&lt;&#x2F;h1&gt;
&lt;p&gt;Method&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Consider a pair $(q, d)$ where $q$ is some Boolean query and $d$ is some document within a collection. Let each document in the collection have $l$ zones.&lt;&#x2F;li&gt;
&lt;li&gt;Let $z_i$ be the $i$-th zone of document $d$&lt;&#x2F;li&gt;
&lt;li&gt;Let $g_1, \dots, g_l \in [0,1]$ such that $\sum_{i=1}^{l} g_i=1$.&lt;&#x2F;li&gt;
&lt;li&gt;Each zone $z_i$ will have a Boolean score $s_i$ denoting a match with $q$. This match is based on some Boolean function mapping the presence of query terms in a zone to either $0$ or $1$.&lt;&#x2F;li&gt;
&lt;li&gt;Then, the &lt;em&gt;weighted zone score&lt;&#x2F;em&gt; for the document $d$ is $\sum^{l}_{i=1}{g_i s_i}$&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Example Implementation&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ZONESCORE(q1, q2)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	float scores[N] = [0]  &#x2F;&#x2F; array with score entry for each doc, initialised to 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	constant g[l]  &#x2F;&#x2F; contains the respective zone weights&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	p1 &amp;lt;- postings(q1)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	p2 &amp;lt;- postings(q2)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	&#x2F;&#x2F; p1 and p2 are initialised to point to the beginning of their postings	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	while p1 != NIL and p2 != NIL&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	do if docID(p1) = docID(p2)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;		then scores[docID(p1)] &amp;lt;- WEIGHTEDZONE(p1, p2, g)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;			p1 &amp;lt;- next(p1)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;			p2 &amp;lt;- next(p2)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;		else if docID(p1) &amp;lt; docID(p2)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;			then p1 &amp;lt;- next(p1)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;			else p2 &amp;lt;- next(p2)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	return scores&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;blockquote&gt;
&lt;p&gt;In this implementation, the query is a two-term query with query terms &lt;code&gt;q1&lt;&#x2F;code&gt; and &lt;code&gt;q2&lt;&#x2F;code&gt;, and the Boolean function is &lt;code&gt;AND: 1&lt;&#x2F;code&gt; if &lt;code&gt;q1&lt;&#x2F;code&gt; and &lt;code&gt;q2&lt;&#x2F;code&gt; are in a zone, and &lt;code&gt;0&lt;&#x2F;code&gt; otherwise.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;WEIGHTEDZONE&lt;&#x2F;code&gt; function is assumed to calculate the weighted zone score based on postings and weight.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
</description>
      </item>
      <item>
          <title>Nonlinear Thinking - The Power of Mathematical Thinking</title>
          <pubDate>Mon, 15 Jun 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/linear-thinking/</link>
          <guid>https://danieltam.com/posts/linear-thinking/</guid>
          <description xml:base="https://danieltam.com/posts/linear-thinking/">&lt;h1 id=&quot;background&quot;&gt;Background&lt;&#x2F;h1&gt;
&lt;p&gt;I&#x27;ve just picked up a book called &lt;em&gt;&quot;How Not To Be Wrong: The Power of Mathematical Thinking by Jordan Ellenberg&quot;&lt;&#x2F;em&gt; that I&#x27;d started reading a while back, but never had the time or patience to get past the first chapter. It&#x27;s an interesting book that highlights how approaching everyday thought mathematically can add a layer of rigour and logic to the way we think. In this post, I discuss a specific part of the book on linearity, and touch on the first chapter to reflect on what&#x27;s been learnt.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;textual-example-of-linear-thinking&quot;&gt;Textual example of linear thinking&lt;&#x2F;h1&gt;
&lt;p&gt;In the very first chapter, he points out a common flaw or hole in many arguments: the false assumption of linearity. He does so by introducing a political issue back in the 2000s. The Obama administration wanted to make the U.S. &quot;more like Sweden&quot; by raising taxes, while Sweden reformed to lower tax, aiming to become less like itself. This was a critique against the Obama administration brought up by Daniel J. Mitchell of the libertarian Cato Institute as a blog entry, questioning why the U.S. wanted to be more like Sweden if Sweden and other nations alike had learnt from their own mistakes—that&#x27;s just stupid.&lt;&#x2F;p&gt;
&lt;p&gt;However, Jordan notes that the Cato institute had looked at the relationship between tax rates and prosperity as a linear graph. The more &quot;Swedish&quot; you are, the lower your prosperity. The less &quot;Swedish&quot; you are, the higher the prosperity. They unknowingly assume that the relationship between the two variables ought to be a linear graph, with some inverse relationship.&lt;&#x2F;p&gt;
&lt;p&gt;Jordan refutes this argument by introducing a Laffer Curve, a &lt;strong&gt;nonlinear&lt;&#x2F;strong&gt; graph showing how tax rates and tax revenue are related. According to the curve, at a tax rate of 0%, the government has no revenue. At the tax rate of 100%, people no longer have the incentive to work and so the government has no revenue yet again. It tells us that the sweet spot is somewhere between the two extremes, forming some &lt;strong&gt;n&lt;&#x2F;strong&gt;-shaped parabola. Hence, &lt;strong&gt;optimisation&lt;&#x2F;strong&gt; is about finding that perfect middleground. Understanding this idea of potentially having too much or too little of something allows us to see the pitfall in linearity, and is the first step to breaking free of it.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;This rebuttal isn&#x27;t as strong to me because there was no statement supporting the claim that Mitchell had assumed a linear relationship. The case may be that from his point of view, the U.S. was in a position that required a step towards decreased tax rates in order to reach the sweet spot. However, I haven&#x27;t actually read the article so this is just a little remark to take with a grain of salt.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h1 id=&quot;effect-of-escaping-linearity&quot;&gt;Effect of escaping linearity&lt;&#x2F;h1&gt;
&lt;p&gt;I believe this is a false mode of thinking unintentionally adopted by many of us in our daily lives. Although I believe most are in fact, aware of the conceptual dangers of linearity, we unknowingly choose not to apply nonlinear thinking because it involves more work by forcing us to question ourselves. Below are some examples.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;example-1&quot;&gt;Example 1&lt;&#x2F;h2&gt;
&lt;p&gt;&quot;The more work I do, the more success I have&quot;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Linear thinking:
&lt;ul&gt;
&lt;li&gt;&quot;If I am not successful, that just means I have to work harder until I reach my condition of success.&quot;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Nonlinear thinking:
&lt;ul&gt;
&lt;li&gt;&quot;If we think nonlinearly, there is a sweet spot between hard work and no work. What is that spot? How do I reach it?&quot;&lt;&#x2F;li&gt;
&lt;li&gt;Once we break free from linearity, we can consider other variables and add a wholeness to our analytical lens to gain a more holistic view. In reality, there is no strict correlation between hard work and success. More often than not, working smarter instead of harder is a key part of success. So we need to explore and find ways in which we can personally optimise ourselves and our habits that drive us towards the shortest path to success.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;example-2&quot;&gt;Example 2&lt;&#x2F;h2&gt;
&lt;p&gt;&quot;I have to sleep longer hours to recover from a lack of sleep&quot;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Linear thinking:
&lt;ul&gt;
&lt;li&gt;&quot;By working longer hours and sleeping later this week, I have built up a sleep debt of 1 hour per day. Throughout the weekend, I have to sleep 5 extra hours to recover.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Nonlinear thinking:
&lt;ul&gt;
&lt;li&gt;We have falsely assigned a simple linear relationship between lost hours of sleep and compensatory hours for recovery. Modern research shows that the biology of sleep debt recovery (which is very relevant in today&#x27;s digital age) is more complex than that. By accumulating the compensatory hours of sleep and attempting to recover it over the weekend, we develop an inconsistent sleep-wake rhythm, which affects the quality of subsequent sessions of sleep. Experiments also show that certain physiological aspects of the body fail to &quot;re-regulate&quot; themselves throughout the weekend recovery period.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Hence, we can see that by developing a habit of nonlinear thinking, we get to view many subjects on a grayscale spectrum instead of black and white. This in turn allows us to think critically and approach a subject from multiple angles, developing our ability to think critically.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Notes on Introduction to Information Retrieval, Chap. 1. (Boolean Retrieval)</title>
          <pubDate>Fri, 12 Jun 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/ir-chap1-notes/</link>
          <guid>https://danieltam.com/posts/ir-chap1-notes/</guid>
          <description xml:base="https://danieltam.com/posts/ir-chap1-notes/">&lt;h1 id=&quot;1-0-background-information&quot;&gt;1.0 Background Information&lt;&#x2F;h1&gt;
&lt;p&gt;IR: Finding materials that satisfy an information need from unstructured data&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Information retrieval (IR) is finding material (usually documents) of an unstructured nature (usually text) that satisfies an information need from within large collections (usually stored on computers).&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Unstructured data&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;No clear structure =&amp;gt; difficult for computer
Clustering&lt;&#x2F;li&gt;
&lt;li&gt;Task of producing a suitable grouping of documents based on their contents
Classifying&lt;&#x2F;li&gt;
&lt;li&gt;Task of deciding which class(es) a document within a collection belongs to
Scales of IR&lt;&#x2F;li&gt;
&lt;li&gt;Web Search
&lt;ul&gt;
&lt;li&gt;Billions of documents stored over millions of computers&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Enterprise
&lt;ul&gt;
&lt;li&gt;Internal documents within a corporation&#x27;s collection, more domain-specific&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Personal Information Retrieval
&lt;ul&gt;
&lt;li&gt;Documents on a personal computer, handled in a lightweight manner&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;1-1-boolean-retrieval-problem-simplified&quot;&gt;1.1 Boolean Retrieval Problem Simplified&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;scenario-1&quot;&gt;Scenario #1&lt;&#x2F;h2&gt;
&lt;p&gt;Consider a collection of plays (Shakespeare&#x27;s Collected Works)&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Target: Determine which plays contain the words &lt;code&gt;&quot;Brutus&quot; AND &quot;Caesar&quot; AND NOT &quot;Calpurnia&quot;&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Simple Method: Linear scan through collection (or &lt;em&gt;grepping&lt;&#x2F;em&gt;), positive result if target conditions of query are satisfied
&lt;ul&gt;
&lt;li&gt;Note for each play whether it has &quot;Brutus&quot; and &quot;Caesar&quot;, exclude if it contains &quot;Calpurnia&quot;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Limits of simple method
&lt;ul&gt;
&lt;li&gt;Can&#x27;t process large collections efficiently&lt;&#x2F;li&gt;
&lt;li&gt;Inflexible matching operations (e.g. if we want a query with definable relationships between words instead of just logical)&lt;&#x2F;li&gt;
&lt;li&gt;Doesn&#x27;t pick the best answer (not ranked retrieval)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Overcoming linear scans: Consider &lt;em&gt;indexing&lt;&#x2F;em&gt; the documents in advance
&lt;ul&gt;
&lt;li&gt;Method
&lt;ul&gt;
&lt;li&gt;For each document, record whether it contains each word out of all the words Shakespeare has used (approximately 32,000 words)&lt;&#x2F;li&gt;
&lt;li&gt;Results in binary term-document &lt;em&gt;incidence matrix&lt;&#x2F;em&gt; (Fig. 1.1). The &lt;em&gt;terms&lt;&#x2F;em&gt; are indexed units.
&lt;ul&gt;
&lt;li&gt;
&lt;blockquote&gt;
&lt;p&gt;&quot;term-document&quot; as in a term-to-document relationship within the matrix. &quot;binary&quot; as in values are only true or false&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Refer to Fig. 1.1&lt;&#x2F;li&gt;
&lt;li&gt;We can have either a column vector (for each document, show the occurring terms), OR a row vector (for each term, show the documents it occurs in)&lt;&#x2F;li&gt;
&lt;li&gt;To solve initial proposed target, we take row vectors for &lt;code&gt;Brutus&lt;&#x2F;code&gt;, &lt;code&gt;Caesar&lt;&#x2F;code&gt;, and &lt;code&gt;Calpurnia&lt;&#x2F;code&gt;, and perform a bitwise AND operation&lt;&#x2F;li&gt;
&lt;li&gt;Result: &lt;code&gt;110100 AND 110111 AND 101111 = 100100&lt;&#x2F;code&gt;. Hence, &lt;code&gt;Antony and Cleopatra&lt;&#x2F;code&gt; and &lt;code&gt;Hamlet&lt;&#x2F;code&gt; are the answers.
&lt;ul&gt;
&lt;li&gt;
&lt;blockquote&gt;
&lt;p&gt;Note that we invert the last column vector (Calpurnia) in order to satisfy the NOT operator in our query&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The &lt;em&gt;Boolean retrieval model&lt;&#x2F;em&gt; allows us to pose a query in the form of a Boolean expression of terms. Each document is viewed as a set of words.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;scenario-2&quot;&gt;Scenario #2&lt;&#x2F;h2&gt;
&lt;p&gt;Consider a larger-scale scenario with a &lt;em&gt;collection&lt;&#x2F;em&gt; of N = 1 million &lt;em&gt;documents&lt;&#x2F;em&gt; that are roughly 1000 words long each. Generally, there might be about M = 500,000 distinct terms throughout the collection.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Goal: Address the &lt;em&gt;ad hoc retrieval&lt;&#x2F;em&gt; task where we aim to provide documents &lt;em&gt;relevant&lt;&#x2F;em&gt; (perceived as containing information of value with respect to their need) to some user &lt;em&gt;information need&lt;&#x2F;em&gt; (topic which user wants to know more about), communicated through a one-off, user &lt;em&gt;query&lt;&#x2F;em&gt; (what user conveys to computer to try to communicate their need)&lt;&#x2F;li&gt;
&lt;li&gt;Assessing &lt;em&gt;effectiveness&lt;&#x2F;em&gt; (quality of search results)
&lt;ul&gt;
&lt;li&gt;Precision
&lt;ul&gt;
&lt;li&gt;Fraction of returned results that are relevant to the information need&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Recall
&lt;ul&gt;
&lt;li&gt;Fraction of relevant documents in the collection that were actually returned&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Limit: term-document matrix is not a viable solution, too large.
&lt;ul&gt;
&lt;li&gt;However, note that there are few non-zero entries because each document is only a 1000 words long.
&lt;ul&gt;
&lt;li&gt;
&lt;blockquote&gt;
&lt;p&gt;Matrix would have 500,000 rows (distinct terms) * 1,000,000 columns (documents) = 500 billion cells. Since each document has a general length of being a 1000 words long, assuming all terms in each document are distinct, at most 1,000,000 documents * 1000 distinct terms per document = 1 billion. So there is a maximum of 1 billion 1&#x27;s out of 500 billions cells. 99.8% of the cells are zero.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Overcome limit: Record only the 1 positions.
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Inverted index&lt;&#x2F;em&gt;
&lt;ul&gt;
&lt;li&gt;Concept
&lt;ul&gt;
&lt;li&gt;Keep a &lt;em&gt;dictionary&lt;&#x2F;em&gt; (refers to the data structure used) of terms.&lt;&#x2F;li&gt;
&lt;li&gt;For each term, there will be a list that records which documents the term occurs in&lt;&#x2F;li&gt;
&lt;li&gt;, Each item in the list is called a &lt;em&gt;posting&lt;&#x2F;em&gt;&lt;&#x2F;li&gt;
&lt;li&gt;The list is known as a &lt;em&gt;postings list&lt;&#x2F;em&gt;&lt;&#x2F;li&gt;
&lt;li&gt;All postings lists are collectively known as the &lt;em&gt;postings&lt;&#x2F;em&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;1-2-building-an-inverted-index&quot;&gt;1.2 Building an inverted index&lt;&#x2F;h1&gt;
&lt;p&gt;Steps&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Collect documents to be indexed&lt;&#x2F;li&gt;
&lt;li&gt;Tokenize text so each document is a list of tokens&lt;&#x2F;li&gt;
&lt;li&gt;Preprocessing to normalise tokens&lt;&#x2F;li&gt;
&lt;li&gt;Index documents that each term occurs in by creating an inverted index&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Consider a scenario in which steps 1-3 are done. Now we perform step 4.
Indexing Method&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Assign each document a unique &lt;em&gt;docID&lt;&#x2F;em&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Input to indexing method will be pairs of term and docID (Fig. 1.4)&lt;&#x2F;li&gt;
&lt;li&gt;Sort the list with terms alphabetically&lt;&#x2F;li&gt;
&lt;li&gt;Merge terms that repeat in the same document&lt;&#x2F;li&gt;
&lt;li&gt;Group instances of the same term&lt;&#x2F;li&gt;
&lt;li&gt;Split them into dictionary and postings&lt;&#x2F;li&gt;
&lt;li&gt;Sort postings by docID&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Singly linked lists or variable length arrays are good structures for postings lists.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;1-3-processing-boolean-queries&quot;&gt;1.3 Processing Boolean queries&lt;&#x2F;h1&gt;
&lt;p&gt;Target: Combine inverted index and Boolean retrieval model
Consider the statement: &lt;code&gt;Brutus AND Calpurnia&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Locate &lt;code&gt;Brutus&lt;&#x2F;code&gt; in Dictionary&lt;&#x2F;li&gt;
&lt;li&gt;Get its postings&lt;&#x2F;li&gt;
&lt;li&gt;Locate &lt;code&gt;Calpurnia&lt;&#x2F;code&gt; in Dictionary&lt;&#x2F;li&gt;
&lt;li&gt;Get its postings&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;Intersect&lt;&#x2F;em&gt; the postings lists
&lt;ul&gt;
&lt;li&gt;Simple intersection algorithm
&lt;ul&gt;
&lt;li&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;INTERSECT(p1, p2)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    answer &amp;lt;- {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    while p1 != NIL and p2 != NIL&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    do if docID(p1) = docID(p2)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  	  then ADD(answer, docID(p1))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  		  p1 &amp;lt;- next(p1)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  		  p2 &amp;lt;- next(p2)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  	  else if docID(p1) &amp;lt; docID(p2)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  		  then p1 &amp;lt;- next(p1)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  		  else p2 &amp;lt;- next(p2)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    return answer&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&#x2F;&#x2F; x+y intersections are done where x = size(doc(p1)), y = size(doc(p2))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Through this form of indexing, complexity is improved by a constant (although still linear), but it&#x27;s a huge difference in practice.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Query optimisation&lt;&#x2F;em&gt; is the process of selecting how to organise the work of answering a query so that the system does minimal work.&lt;&#x2F;p&gt;
&lt;p&gt;Consider a query that is an &lt;code&gt;AND&lt;&#x2F;code&gt; of &lt;code&gt;t&lt;&#x2F;code&gt; terms, optimise intersection by:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Intersecting the two smallest postings lists&lt;&#x2F;li&gt;
&lt;li&gt;All intermediate results will be at most the size of the smallest postings list
&lt;ul&gt;
&lt;li&gt;
&lt;blockquote&gt;
&lt;p&gt;&quot;intermediate&quot; in the sense that they are temporary results that come after the starting result, working towards the final result&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;blockquote&gt;
&lt;p&gt;Code:&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;INTERSECT({t1, ..., tn})&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    terms &amp;lt;- SORTBYINCREASINGFREQUENCY({t1, ..., tn})&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    result &amp;lt;- postings(first(terms))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    terms &amp;lt;- rest(terms)  &#x2F;&#x2F; rest of the terms&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    while terms != NIL and result != NIL&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    do result &amp;lt;- INTERSECT(result, postings(first(terms)))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  	  terms &amp;lt;- rest(terms)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    return result&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;blockquote&gt;
&lt;p&gt;If you have a hard time accepting it, try going through this scenario. Let &lt;code&gt;N1=2, N2=100, N3=50&lt;&#x2F;code&gt; where &lt;code&gt;Nn&lt;&#x2F;code&gt; represents the size of the postings list. Now see what happens when you compare &lt;code&gt;N2&lt;&#x2F;code&gt; and &lt;code&gt;N3&lt;&#x2F;code&gt; first instead of &lt;code&gt;N1&lt;&#x2F;code&gt; and &lt;code&gt;N3&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Many ways to modify and optimise intersection depending on the situation. Even the standard intersection algorithm is essential in certain cases.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;1-4-extended-b-r-m-vs-ranked-retrieval&quot;&gt;1.4 Extended B.R.M. vs Ranked Retrieval&lt;&#x2F;h1&gt;
&lt;p&gt;Some systems have extended the Boolean retrieval model by incorporating operators such as term proximity operators (helps specify that two terms must occur within a certain distance of each other).&lt;&#x2F;p&gt;
&lt;p&gt;Problems with B.R.M.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Document either matches query or does not&lt;&#x2F;li&gt;
&lt;li&gt;AND operators lead to high precision but low recall&lt;&#x2F;li&gt;
&lt;li&gt;OR gives low precision but high recall&lt;&#x2F;li&gt;
&lt;li&gt;Lack of middle ground&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Ranked retrieval models (like vector space models) possess certain advantages, and allows for &lt;em&gt;free text queries&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;figures&quot;&gt;Figures&lt;&#x2F;h1&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Fig. 1.1&lt;&#x2F;th&gt;&lt;th&gt;Antony and Cleopatra&lt;&#x2F;th&gt;&lt;th&gt;Julius Caesar&lt;&#x2F;th&gt;&lt;th&gt;The Tempest&lt;&#x2F;th&gt;&lt;th&gt;Hamlet&lt;&#x2F;th&gt;&lt;th&gt;Othello&lt;&#x2F;th&gt;&lt;th&gt;Macbeth&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Antony&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Brutus&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Caesar&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Calpurnia&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Fig. 1.3&lt;&#x2F;strong&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Brutus -&amp;gt; {1, 2, 4, 11, 31, 45, 173, 174}&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Caesar -&amp;gt; {1, 2, 4, 5, 6, 16, 57, 132, ...}&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Calpurnia -&amp;gt; {2, 31, 54, 101}&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;LHS: Dictionary&lt;&#x2F;li&gt;
&lt;li&gt;RHS: Postings&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;Fig. 1.4&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;term&lt;&#x2F;th&gt;&lt;th&gt;docID&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;I&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;did&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;enact&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;caesar&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;caesar&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;enact&lt;&#x2F;td&gt;&lt;td&gt;2&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Sorts into&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;term&lt;&#x2F;th&gt;&lt;th&gt;docID&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;caesar&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;caesar&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;did&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;enact&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;enact&lt;&#x2F;td&gt;&lt;td&gt;2&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;I&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Merges and splits into a structure like in Fig. 1.3&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
</description>
      </item>
      <item>
          <title>C Language Cheatsheet</title>
          <pubDate>Thu, 11 Jun 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/cuhk-engg1110-notes/</link>
          <guid>https://danieltam.com/posts/cuhk-engg1110-notes/</guid>
          <description xml:base="https://danieltam.com/posts/cuhk-engg1110-notes/">&lt;p&gt;This is a C language cheatsheet I made, tailored to the ENGG1110 Problem Solving by Programming class. I believe this class is a foundational course for all engineering students. I think it may be of help to others who enter the course with some prior knowledge of programming, and just need to pick up some C. Personally, it was all that was necessary for a good grade (A) in the course, but results may vary of course.&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s worth noting that the notes are not very organised nor does it follow the curriculum structure, it&#x27;s just bits and pieces of information I thought worth recording. However, all content does pertain to what was taught.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;notes&quot;&gt;Notes&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;int x = 5.99&lt;&#x2F;code&gt; =&amp;gt; &lt;code&gt;x = 5&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Remember that characters are actually 1-byte integer values that represent an ASCII character.
&lt;ul&gt;
&lt;li&gt;So, char a = &quot;A&quot; actually has an int value of 65 according to the ASCII table.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Type-casting a float to an integer performs a floor operation on the value.
&lt;ul&gt;
&lt;li&gt;e.g. &lt;code&gt;(int) 0.99 + 5&lt;&#x2F;code&gt; =&amp;gt; &lt;code&gt;5&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Any variables declared within the initialisation of the for loop and its body is scoped to the loop.
&lt;ul&gt;
&lt;li&gt;However, the initialisation may make use of a variable declared in the outer scope.
&lt;ul&gt;
&lt;li&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span&gt;i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;    printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; result is: &amp;quot;1 2 3&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;The escape character &lt;code&gt;\&lt;&#x2F;code&gt; is not regarded as its own individual character. Only the escape sequence in its entirety is regarded as a single character.
&lt;ul&gt;
&lt;li&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;length&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;\\&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;a&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; results in a string of length 2 (because the printed string is &amp;quot;\a&amp;quot;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;They also occupy the same index within a character array.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;By default, C uses pass by value for all arguments (except arrays, which practically pass by reference)
&lt;ul&gt;
&lt;li&gt;When it comes to arrays
&lt;ul&gt;
&lt;li&gt;Instead of passing a copy of the array, a pointer to the first element of the array is passed (array decay -&amp;gt; the array variable decays into a pointer, so information about the array is lost like size)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;void&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; myFunction&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt;arr&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Equivalent to passing int arr[]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;When you modify the passed array (either through pointer arithmetic or indexing), it changes the original array. So in effect, it&#x27;s pass by reference.&lt;&#x2F;li&gt;
&lt;li&gt;The name of an array itself can be treated as a pointer to its first element (&lt;code&gt;arr = &amp;amp;arr[0]&lt;&#x2F;code&gt;). However, there are still some differences. It is not entirely equivalent. Generally, in an expression, the array name decays to a pointer to the first element of the array, excluding its use in &lt;code&gt;sizeof&lt;&#x2F;code&gt;(returns size of entire array in bytes) and unary &lt;code&gt;&amp;amp;&lt;&#x2F;code&gt; (&lt;code&gt;int (*ptr_to_array)[5]=&amp;amp;array_size_5&lt;&#x2F;code&gt; points to the entire array.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;When the size of an array is not stated, it is initialised to fit the initial declaration.&lt;&#x2F;li&gt;
&lt;li&gt;You have misunderstood the order of precedence and associativity in C.
&lt;ul&gt;
&lt;li&gt;Precedence tells us which operator comes first, and associativity tells us the direction in which operators of the same level are evaluated.&lt;&#x2F;li&gt;
&lt;li&gt;E.g.
&lt;code&gt;double x = 5 &#x2F; 2 * 4.0&lt;&#x2F;code&gt;
&lt;code&gt;&#x2F;&lt;&#x2F;code&gt; and &lt;code&gt;*&lt;&#x2F;code&gt; are on the same order of precedence, hence the expression is evaluated from left to right.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Be wary of integer divisions and floating-point divisions.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;double x = 5.0 &#x2F; 2 * 4.0&lt;&#x2F;code&gt; results in &lt;code&gt;10.0&lt;&#x2F;code&gt; because &lt;code&gt;5.0&#x2F;2&lt;&#x2F;code&gt; is a floating-point division which results in &lt;code&gt;2.5&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;double x = 5 &#x2F; 2 * 4.0&lt;&#x2F;code&gt; results in &lt;code&gt;8.0&lt;&#x2F;code&gt; because &lt;code&gt;5&#x2F;2&lt;&#x2F;code&gt; is integer division, which results in &lt;code&gt;2&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;In C, &lt;code&gt;0&lt;&#x2F;code&gt; is regarded as false, and all other non-zero values are regarded as true (including doubles &amp;amp; integers).&lt;&#x2F;li&gt;
&lt;li&gt;Format Specifiers in C
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;%d&lt;&#x2F;code&gt; or &lt;code&gt;%i&lt;&#x2F;code&gt; for signed integers&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;%f&lt;&#x2F;code&gt; for floating-point values, defaults to printing to the 6-th decimal place.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;%.xf&lt;&#x2F;code&gt; where &lt;code&gt;x&lt;&#x2F;code&gt; is an integer results in printing a floating-point value to the x-th decimal place. &lt;code&gt;x=0&lt;&#x2F;code&gt; results in an integer result.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;%c&lt;&#x2F;code&gt; for a single character&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;%s&lt;&#x2F;code&gt; for a string&#x2F;(array of characters).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;%u&lt;&#x2F;code&gt; for unsigned integers&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;%%&lt;&#x2F;code&gt; to print a literal percentage sign&lt;&#x2F;li&gt;
&lt;li&gt;Use of whitespace
&lt;ul&gt;
&lt;li&gt;&lt;code&gt; %c&lt;&#x2F;code&gt; skips leading whitespace and reads the first non-whitespace character&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;%c &lt;&#x2F;code&gt; reads any character, skips trailing whitespace until non-whitespace&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;scanf&lt;&#x2F;code&gt; reads the input buffer character after character, sequentially, including &lt;code&gt;\n&lt;&#x2F;code&gt; when the user presses enter&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Escape Sequences in C
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;\n&lt;&#x2F;code&gt; next line&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;\t&lt;&#x2F;code&gt; horizontal tab&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;\\&lt;&#x2F;code&gt; backslash character&lt;&#x2F;li&gt;
&lt;li&gt;There are many more, not just the ones stated here. So be wary of that.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Strings
&lt;ul&gt;
&lt;li&gt;The ASCII value of &lt;code&gt;0&lt;&#x2F;code&gt; is the &lt;code&gt;NUL&lt;&#x2F;code&gt; character, which is the string terminator &lt;code&gt;\0&lt;&#x2F;code&gt;.
&lt;ul&gt;
&lt;li&gt;It is not included when we call &lt;code&gt;strlen&lt;&#x2F;code&gt;. However, in the actual size of the character array, it has to be taken into account.&lt;&#x2F;li&gt;
&lt;li&gt;For example, if we want a string of at most 100 characters, we need to declare an array of size 101 to include the string terminator&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Reading a string
&lt;ul&gt;
&lt;li&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;char&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt; str&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;scanf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%s&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; str&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; notice that prefix &amp;amp; is not needed for strings because of array decay&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Functions
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;strlen(str1) -&amp;gt; length of string&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;strcpy(dst, src)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;strcat(dst, src)&lt;&#x2F;code&gt; (appends &lt;code&gt;src&lt;&#x2F;code&gt; to end of &lt;code&gt;dst&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;strcmp(str1, str2) -&amp;gt; 0 : identical; &amp;lt;0 : first non-matching character in str1 less than corresponding character in str2; &amp;gt;0 : vice versa&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Note that type-casting takes precedence over calculations.
&lt;ul&gt;
&lt;li&gt;E.g.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    double&lt;&#x2F;span&gt;&lt;span&gt; a &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; -&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;3&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;6&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;    printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span&gt;a &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;    printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%f&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; a &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ```&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;The above code results in &#x27;-3&#x27; and &#x27;-2.500000&#x27;.&lt;&#x2F;li&gt;
&lt;li&gt;&#x27;-3&#x27; : it first calculates the result in a+0.5, and then type-casts the result to an int.&lt;&#x2F;li&gt;
&lt;li&gt;&#x27;-2.500000&#x27; : following precedence, it first type-casts a to an int (&lt;code&gt;-3&lt;&#x2F;code&gt;) =&amp;gt; -3 + 0.5 = -2.5&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Size of data types
&lt;ul&gt;
&lt;li&gt;Integer - 4 bytes&lt;&#x2F;li&gt;
&lt;li&gt;Float - 4 bytes&lt;&#x2F;li&gt;
&lt;li&gt;Double - 8 bytes&lt;&#x2F;li&gt;
&lt;li&gt;Character - 1 byte&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Extracting each digit from an integer
&lt;ul&gt;
&lt;li&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; a&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; n &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;scanf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt;n&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;    printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; a &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;%&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 10&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    a &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&#x2F;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 10&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span&gt;a &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&amp;lt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      i &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; n&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Postfix and Prefix Increment&#x2F;Decrement
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;++variable&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;Variable is incremented before its value is used in the expression.&lt;&#x2F;li&gt;
&lt;li&gt;Result of the expression is the incremented value of the variable.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;variable++&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;The variable&#x27;s current value is used in the expression first.&lt;&#x2F;li&gt;
&lt;li&gt;The variable is then incremented after its value has been used.&lt;&#x2F;li&gt;
&lt;li&gt;The result of the expression is the original value of the variable before the increment.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;An assignment operation evaluates to the newly assigned value
&lt;ul&gt;
&lt;li&gt;x=5 =&amp;gt; 5&lt;&#x2F;li&gt;
&lt;li&gt;z = 0 =&amp;gt; 0&lt;&#x2F;li&gt;
&lt;li&gt;x+=5 =&amp;gt; x=x+5 =&amp;gt; x+5&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Function Prototype or Forward Declaration in C
&lt;ul&gt;
&lt;li&gt;This is a statement that describes a function&#x27;s details (name, parameters, return type) before its definition.&lt;&#x2F;li&gt;
&lt;li&gt;It&#x27;s used when you want to reference or call a function before its definition in your source code.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;stdio.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; sum&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt; x&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; int&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt; y&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;void&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    int&lt;&#x2F;span&gt;&lt;span&gt; Sum &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; sum&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;x&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; y&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; sum&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt; x&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; int&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt; y&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; x&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt;y&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Because it&#x27;s troublesome to maintain, it should only be used when necessary.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;ASCII Table Non-Printable Characters (definitions)
&lt;ul&gt;
&lt;li&gt;
&lt;ol start=&quot;0&quot;&gt;
&lt;li&gt;NUL : String-terminator&#x2F;Null-character&#x2F;&#x27;\0&#x27;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;ol&gt;
&lt;li&gt;SOH :&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Remember that array declarations are as such
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;char name[5]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;char getchar(void)&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;This function has no parameters. It reads the first character entered into the input stream and returns it.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;char x = getchar()&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;In C, local variables take precedence over global variables when they share the same name within the scope of a function or block. This is known as variable shadowing.&lt;&#x2F;li&gt;
&lt;li&gt;File IO
&lt;ul&gt;
&lt;li&gt;Reading a file&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;FILE &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;fptr&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fptr &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; fopen&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;file.txt&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;r&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span&gt;fptr &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;==&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; NULL&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; file failed to open&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;	return&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;	exit&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; only when stdlib.h included; alternative&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; APPROACH 1 - Controlled Reading	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;char&lt;&#x2F;span&gt;&lt;span&gt; character&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;	fscanf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;fptr&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%c&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;character&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;	&#x2F;*&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;	- reads like scanf would but from a file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;	- adding that whitespace &amp;quot;%c &amp;quot; allows us to skip newlines and whitespaces found in the stream&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;	 *&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;	printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%c&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; character&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; APPROACH 2 - Line after line to the end&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;while&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;fscanf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;fptr&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%c&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt;character&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span&gt; EOF&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;	printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%c&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; character&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;fclose&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;fptr&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  ```&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;fscanf&lt;&#x2F;code&gt; returns the number of items successfully read. If it reaches the end of file or an input error occurs, a constant &lt;code&gt;EOF&lt;&#x2F;code&gt; is returned. Hence it is our terminating condition in the while loop
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;0&lt;&#x2F;code&gt; can also be returned, which means the input read didn&#x27;t conform to the type specified by the format specifier.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Writing to a file
&lt;ul&gt;
&lt;li&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;FILE &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;fptr&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fptr &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; fopen&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;data.txt&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;w&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span&gt;fptr &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;==&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; NULL&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; OR exit(1)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;fprintf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;fptr&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;Hello!&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;    fprintf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;fptr&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;fprintf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;fptr&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;fclose&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;fptr&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;Content:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;Hello!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;0 1 2 3 4 5 6 7 8 9&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;*&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;fgets(char_array_to_store_into, max_characters, input_stream)&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;Reads at most &lt;code&gt;max_characters-1&lt;&#x2F;code&gt; or until a newline character appears. The newline is included in the character array. It also automatically appends a null terminator.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;scanf&lt;&#x2F;code&gt; for string reading
&lt;ul&gt;
&lt;li&gt;Only includes up to the first whitespace character, unlike &lt;code&gt;fgets&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;In C, you cannot directly assign one array to equal to another. For character arrays, use &lt;code&gt;strcpy&lt;&#x2F;code&gt; if necessary. Or &lt;code&gt;memcpy(dest_arr, src_arr, sizeof(src_arr))&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Structures
&lt;ul&gt;
&lt;li&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span&gt; student &lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    char&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt; id&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;11&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    char&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;40&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    double&lt;&#x2F;span&gt;&lt;span&gt; gpa&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;    &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; int day, month, year; (acceptable)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span&gt; student peter&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;peter.id &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;1155123456&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;peter.name &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;Peter Pennyworth&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;peter.gpa &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; -&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span&gt; student amanda &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;1155325932&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;Amanda the Baboon&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span&gt; student amanda_cpy&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;amanda_cpy &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; amanda&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; copies info over&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;typedef&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; struct&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    double&lt;&#x2F;span&gt;&lt;span&gt; lat&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; lng&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span&gt; GeoLoc&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span&gt; place &lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    char&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;200&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    GeoLoc centre&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;struct&lt;&#x2F;span&gt;&lt;span&gt; place HK &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;Hong Kong&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;22&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;28&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 114&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;17&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; this is also valid&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;When referencing a user-defined struct data type, we need to include this : &lt;code&gt;struct defined_name&lt;&#x2F;code&gt;, it cannot just be the name we defined, unless we create a &lt;code&gt;typedef&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;typedef struct type_name alias_name&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;Defines an alias for any existing type&lt;&#x2F;li&gt;
&lt;li&gt;Structs are also pass by value into a function unless a pointer is used.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Macro
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;#define MAX_COUNT 30&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Defines a referenceable constant&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Pointers&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; pointers are a distinct data type in C, declared using *ptr_name&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; n &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt;p &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;n&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; &amp;amp;variable -&amp;gt; address of variable (referencing)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; to change address of existing pointer is p = &amp;amp;newaddress&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt;p&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; *ptr -&amp;gt; dereferencing pointer -&amp;gt; value at pointed address&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; p = &amp;amp;n (stores in p the memory address of n); *p = n (accesses value in memory address stored in p);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; p&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt;n&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; OUTPUT : address of n twice&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;p &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; manipulates n&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; n&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; n = 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;ptr &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;p&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; pointer to a pointer&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Dynamic Memory Allocation
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;malloc(size_in_bytes)&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;This function allocates a single block of contiguous memory at runtime according to the size specified. Note that it is in bytes.&lt;&#x2F;li&gt;
&lt;li&gt;Hence, we usually use &lt;code&gt;sizeof(data_type) * no_of_elements&lt;&#x2F;code&gt; for its parameter. &lt;code&gt;sizeof(data_type)&lt;&#x2F;code&gt; returns the size of the data type we specify in bytes. E.g. &lt;code&gt;m (int) -&amp;gt; 2 bytes&lt;&#x2F;code&gt;, &lt;code&gt;sizeof(char) -&amp;gt; 1 byte&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;It can return &lt;code&gt;NULL&lt;&#x2F;code&gt; if allocations fails. So we ensure we check for that condition.&lt;&#x2F;li&gt;
&lt;li&gt;The function returns a pointer to the allocated memory, which is inherently void, so we need to perform type casting.&lt;&#x2F;li&gt;
&lt;li&gt;The allocated memory is not initialised, hence filled with garbage values. So it shouldn&#x27;t be read without writing to it.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;  #&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;stdio.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;  #&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;include&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;stdlib.h&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;  int&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;void&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;      int&lt;&#x2F;span&gt;&lt;span&gt; numOfGrades&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;      printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;Enter the number of grades: &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;      scanf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;numOfGrades&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;      char&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt;grades &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; malloc&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;sizeof&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;char&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt; numOfGrades&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; -&amp;gt; returns a pointer to the base address of the allocated memory, equivalent to returning a pointer to the start of the array that we want&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;      if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span&gt;grades &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;==&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; NULL&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; ESSENTIAL, avoids segmentation faults&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;          return&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;      for&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt;numOfGrades&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;          printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;Grade #&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;          scanf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; %c&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt;grades&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span&gt;i&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;          &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; &amp;quot; %c&amp;quot;; whitespace is needed to avoid capturing the newline character that enters the input stream when we enter numOfGrades and type &amp;quot;ENTER&amp;quot;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;      for&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt;numOfGrades&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;          printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;Grade #&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%c&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt; grades&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span&gt;i&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;          &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; we do not need to do *grades[i] here because dereferencing is implied&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;      free&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;grades&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; essential to free the memory locations (since we&amp;#39;re just &amp;quot;borrowing it&amp;quot;) to avoid memory leaks&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      grades &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; NULL&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;  &#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; avoids a dangling pointer that would point to deallocated memory&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;      return&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Static Variables
&lt;ul&gt;
&lt;li&gt;Static variables are initialised only once, and retain their value between function calls.&lt;&#x2F;li&gt;
&lt;li&gt;Example 1
&lt;ul&gt;
&lt;li&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; fun&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    static&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; int&lt;&#x2F;span&gt;&lt;span&gt; count &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    count&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; count&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;    printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; fun&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;    printf&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; fun&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; OUTPUT: 1 2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;It&#x27;s not destroyed upon function return&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;int i, j, x = 5&lt;&#x2F;code&gt; doesn&#x27;t initialise all three variables to &lt;code&gt;5&lt;&#x2F;code&gt; like Python would. It declares &lt;code&gt;i, j&lt;&#x2F;code&gt; and only initialises &lt;code&gt;x&lt;&#x2F;code&gt; to 5. The others would be garbage values.&lt;&#x2F;li&gt;
&lt;li&gt;Width specifier
&lt;ul&gt;
&lt;li&gt;In &lt;code&gt;printf&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;It specifies the minimum number of characters the output should occupy. If the output given is shorter than the minimum width, the output will be padded by whitespace.&lt;&#x2F;li&gt;
&lt;li&gt;E.g.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;printf(&quot;%5d\n&quot;, 42) &#x2F;&#x2F; OUTPUT: &quot;   42&quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;In &lt;code&gt;scanf&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;It specifies the maximum number of characters to be read&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;scanf(&quot;%5d&quot;, &amp;amp;n); &#x2F;&#x2F; reads at most 5 digits&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
      </item>
      <item>
          <title>Website Update</title>
          <pubDate>Thu, 11 Jun 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/website-revamp/</link>
          <guid>https://danieltam.com/posts/website-revamp/</guid>
          <description xml:base="https://danieltam.com/posts/website-revamp/">&lt;p&gt;This is just a quick update to get me back into the loop of blogging. I&#x27;ve revamped the website by switching from Wordpress to a little SSG (Static Site Generator) called Zola. Zola is now the backbone of my blog, and I am enjoying it so far. It removes certain barriers to a more free form of blogging, which is what I intend to do. It does so in a couple of obvious ways.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First of all, I can do all my writing entirely offline because I can run the site locally before I manually deploy it.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Secondly, I can use plain simple markdown (or technically &quot;CommonMark&quot;), which I feel is faster than having to slowly format things in a word processor-esque GUI (I have also had plenty of Markdown practice thanks to my heavy use of Obsidian).&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Thirdly, Zola is extremely fast. It was built in Rust, which is a strong competitor to C++. For example, after saving this file, it detected changes and redeployed them within the short duration of 211ms.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The main hassles with a CLI-based SSG is embedding pictures into my pages. It&#x27;s a little more trouble because I can&#x27;t just copy and paste a picture or resize it freely. I guess it deters me from flooding my posts with images, and keeps things as minimalist as possible while conserving preicious storage.&lt;&#x2F;p&gt;
&lt;p&gt;Anyways, that&#x27;s the end of this update. I hope to be posting more as I dive into AI&#x2F;ML.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>The Quarrasi Lock Online: My first web-hosted application</title>
          <pubDate>Thu, 05 Sep 2024 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/quarassi-lock/</link>
          <guid>https://danieltam.com/posts/quarassi-lock/</guid>
          <description xml:base="https://danieltam.com/posts/quarassi-lock/">&lt;p&gt;As a quick getaway from academics after a whirlwind of exams and a refresher into programming, I made my first leap into browser game development. Now this is something I’ve worked on indirectly (in the form of offered help), but hardly dirtied my hands with.&lt;&#x2F;p&gt;
&lt;p&gt;This project is simple and was in fact completed over a matter of hours, so what deems this “blog-worthy”?&lt;&#x2F;p&gt;
&lt;p&gt;Well, since it’s  a simple vanilla JavaScript game, it’s much easier for me to host it on this website as compared to my other projects, which are either too large in scale or lacking in compability.&lt;&#x2F;p&gt;
&lt;p&gt;The fact that I’ve always wanted to host an application on my website is also a contributing factor. This puzzle is now something anyone can try from anywhere, without having to go through all the hassle of downloading the projects files in order to run it. That’s the beauty of the web.&lt;&#x2F;p&gt;
&lt;p&gt;It’s also, to my knowledge, a one-of-a-kind application as I haven’t seen any other visual interfaces for this puzzle.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Delta Time - The Road to Frame Rate Independence</title>
          <pubDate>Sun, 22 Oct 2023 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/delta-time/</link>
          <guid>https://danieltam.com/posts/delta-time/</guid>
          <description xml:base="https://danieltam.com/posts/delta-time/">&lt;p&gt;The word “delta” can be defined as the difference between two things or values. This was a word I first came across through physics, with delta(represented by a triangle) describing the change in a certain value. So from there, we can draw the conclusion that delta time is the change in time. In game development terms, it’d specifically represent the time that passes between each frame drawn.&lt;&#x2F;p&gt;
&lt;p&gt;Why do we need delta time?
Delta time allows us to achieve what is known as “frame rate independence”. That means,
regardless of how low or high your framerate is, the rate at which things occur
or are updated(for example, the change in object positions according to
velocity, the rate at which an object’s velocity increases) remains consistent
throughout the game.&lt;&#x2F;p&gt;
&lt;p&gt;For example, if we were to be updating a flying object’s position by a velocity of 20 pixels per second toward the north, having frame rate independence would help us ensure that regardless of whether we’re getting 30 frames per second on one computer or 60 frames per second on another, the position of that flying object on both computers would remain the same after each second.&lt;&#x2F;p&gt;
&lt;p&gt;How do we implement it?
Let’s continue building off of the example that we used above. Our goal is to update an object’s position so that they move 20 pixels toward the north every second.&lt;&#x2F;p&gt;
&lt;p&gt;First things first, let’s calculate delta time. This can be done by calculating the reciprocal of the player&#x27;s frame rate, giving us the time between each frame (let’s say that value is 1&#x2F;60 because the player’s frame rate is 60fps, do take note that in the real code implementation you won’t know what the frame rate is, you need to take the frame rate with whatever function your library or your engine supports).&lt;&#x2F;p&gt;
&lt;p&gt;Now, we multiply the velocity of 20 pixels per second to the north by delta time, which reduces the velocity so that after 60 frames, i.e a full second, the object’s position would have moved by approximately 20 pixels towards the north.&lt;&#x2F;p&gt;
&lt;p&gt;In this case, our object’s position would be updated by 0.3333 pixels towards the north every frame. So by the end of 60 frames, our object would have moved by 0.3333 * 60 = 19.998 pixels toward the north.&lt;&#x2F;p&gt;
&lt;p&gt;Below you’ll find the full representation of this process in pseudocode.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;player_frame_rate&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; get_fps&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;delta_time&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;player_frame_rate&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;velocity&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; Vector2&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 20&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;object&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;y&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; +=&lt;&#x2F;span&gt;&lt;span&gt; velocity&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;y&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt; delta_time&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Alternatively, you can just divide the velocity by the frame rate because&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;y&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; *&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;60&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; y&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#005CC5, #79B8FF);&quot;&gt;60&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Let’s say our game was being run on a lower-end computer and we were getting 30 frames per second. Let’s step through our code and see what happens. Intuitively, we know that if we’re getting only 30 frames per second, our object will have to move faster each frame compared to when we had higher frame rates. This is because we have less frames to display the journey of the object’s position to our target destination, and therefore we need to increase the distance our object moves each frame. Let’s check if our code does end up following that trend.&lt;&#x2F;p&gt;
&lt;p&gt;First, with a frame rate of 30 fps, our delta time will now be 1&#x2F;30. When we multiply 1&#x2F;30 by our velocity of 20 pixels to the north, we get &lt;code&gt;1&#x2F;30 * 20 = 0.6666&lt;&#x2F;code&gt; pixels toward the north every frame. That’s double the velocity we had previously with 60 frames per second.&lt;&#x2F;p&gt;
&lt;p&gt;We now know that our code works and it indeed follows the inversely proportional trend between frame rate and update speed.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Static Keyword in Java – What in the world is it?</title>
          <pubDate>Tue, 29 Aug 2023 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/about-static-kw/</link>
          <guid>https://danieltam.com/posts/about-static-kw/</guid>
          <description xml:base="https://danieltam.com/posts/about-static-kw/">&lt;p&gt;Is a question many young and naive Java developers have that often go unanswered due to overly-complicated explanations that are rather obscure, and not geared towards beginners.&lt;&#x2F;p&gt;
&lt;p&gt;Here(not just this article&#x2F;post but on the behalf of any subsequent tutorials), I aim to provide a quick yet effective definition of what this keyword actually means, and what it can be used for.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;a-quick-definition&quot;&gt;A Quick Definition&lt;&#x2F;h1&gt;
&lt;p&gt;The static keyword tells Java that a method or variable in a class should be made accessible without the need of instantiation. Therefore, it becomes a part of the class. Any objects instantiated from that class will have the same value for its static variables.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;example-how-can-i-use-it&quot;&gt;Example - How can I use it?&lt;&#x2F;h2&gt;
&lt;p&gt;Let’s create an application that categorises users into their age groups, based on their age input. These age groups consist of seniors, middle-aged, and youngsters.&lt;&#x2F;p&gt;
&lt;p&gt;Let’s start by creating a class for each of them, and group them into a package just for demographics.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;java&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;package&lt;&#x2F;span&gt;&lt;span&gt; org&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;demographics&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; class&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; Senior&lt;&#x2F;span&gt;&lt;span&gt;&#x2F;MiddleAged&#x2F;Young &lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; static&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; int&lt;&#x2F;span&gt;&lt;span&gt; ageGroup&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; ?&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;some&lt;&#x2F;span&gt;&lt;span&gt; more code dedicated to each class&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now, let’s create the main class that will make use of these classes and make up the logic of the application itself.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;java&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt;&#x2F;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6A737D, #6A737D);&quot;&gt; Main class where we specify the logic&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;import&lt;&#x2F;span&gt;&lt;span&gt; org&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;demographics&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;Senior&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;import&lt;&#x2F;span&gt;&lt;span&gt; org&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;demographics&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;MiddleAged&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;import&lt;&#x2F;span&gt;&lt;span&gt; org&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;demographics&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;Young&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; class&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; Categoriser&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; static&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; void&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#E36209, #FFAB70);&quot;&gt; args&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        Scanner&lt;&#x2F;span&gt;&lt;span&gt; scanner&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; new&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; Scanner&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;System&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;in&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        System&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;out&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;println&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;Enter your age&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;        int&lt;&#x2F;span&gt;&lt;span&gt; age&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; scanner&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;nextInt&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        String&lt;&#x2F;span&gt;&lt;span&gt; ageGroup&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span&gt;age &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&amp;gt;=&lt;&#x2F;span&gt;&lt;span&gt; Senior&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;ageGroup&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ageGroup &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;Senior&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            …&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;do&lt;&#x2F;span&gt;&lt;span&gt; stuff&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; instantiate &lt;&#x2F;span&gt;&lt;span&gt;Senior&lt;&#x2F;span&gt;&lt;span&gt; and add to an array&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span&gt; etc…&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;        else&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span&gt;age &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&amp;gt;=&lt;&#x2F;span&gt;&lt;span&gt; MiddleAged&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;ageGroup&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ageGroup &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;Middle Aged&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            …&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;do&lt;&#x2F;span&gt;&lt;span&gt; more stuff…&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;        else&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span&gt;age &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;&amp;gt;=&lt;&#x2F;span&gt;&lt;span&gt; Young&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;ageGroup&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            ageGroup &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;Young&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            …&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;do&lt;&#x2F;span&gt;&lt;span&gt; more stuff…&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;        else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            System&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;out&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;println&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;You are too young!&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        System&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;out&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt;println&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;You shall be categorised as &lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#032F62, #9ECBFF);&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; ageGroup&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Each demographic class has a specific age range. With the static variable, we get rid of the need to instantiate a Senior, MiddleAged, and Young class just to access their age range.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;reminder&quot;&gt;Reminder&lt;&#x2F;h1&gt;
&lt;p&gt;Remember, we made the ageGroup variable static because:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;We want to be able to access it without or before instantiation, otherwise we’d have to do:&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);&quot;&gt;&lt;code data-lang=&quot;java&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Senior&lt;&#x2F;span&gt;&lt;span&gt; placeholderSenior&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#6F42C1, #B392F0);&quot;&gt; Senior&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; seniorAgeGroup&lt;&#x2F;span&gt;&lt;span style=&quot;color: light-dark(#D73A49, #F97583);&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; placeholderSenior&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span&gt;ageGroup&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;It is clearly established for all objects created from that class, and can’t be modified for any exceptional object. We don’t want two Senior objects having an age group of 10 years old and the other 60 years old.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h1 id=&quot;note&quot;&gt;Note&lt;&#x2F;h1&gt;
&lt;p&gt;Do note that static variables aren’t constant(some may misunderstand it to be), rather it is consistent across all its instantiated objects. It can be changed, but the change will be reflected across all objects instantiated from it.&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Programming Plans for The Next Few Months</title>
          <pubDate>Mon, 02 Aug 2021 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/plans/</link>
          <guid>https://danieltam.com/posts/plans/</guid>
          <description xml:base="https://danieltam.com/posts/plans/">&lt;p&gt;After giving a lot of careful thought and consideration, I have decided to continue my programming journey by learning more about Python(by taking on different programming challenges with native Python), learning Web Development with Flask(for now, may switch to Django) and game development with Unity 3D.&lt;&#x2F;p&gt;
&lt;p&gt;First of all, I came upon this decision because of three primary reasons.&lt;&#x2F;p&gt;
&lt;p&gt;I think that it’s good for me to stick to a specific language that I’m already comfortable with and improve on it
I will be taking Computer Science for my O-Levels next year and it just so happens that the syllabus is more focused on webdev as the Pre-Release project is actually based on creating a web application&#x2F;service. Therefore, I think it’ll be beneficial for me to have my own little side projects, so that they may prepare me for the final exams. I also happen to like creating websites.
I really love creating games and I don’t think I will ever give it up. In the future, I aspire to be a hobbyist game developer while working a full-time job as either a software engineer or AI engineer. I just love the fact that gamedev is a mix of creativity(in terms of creating beautiful graphics and music), programming, story-writing and etc.
Anyways, that’s the end of my short and brief update!&lt;&#x2F;p&gt;
</description>
      </item>
      <item>
          <title>Introduction</title>
          <pubDate>Mon, 26 Jul 2021 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://danieltam.com/posts/first-post/</link>
          <guid>https://danieltam.com/posts/first-post/</guid>
          <description xml:base="https://danieltam.com/posts/first-post/">&lt;p&gt;Hello! My name is Daniel and I absolutely adore programming. From simple console “Hello World” programs to large applications, I just love all of it. For the past few months now, I’ve been wondering, why do I like programming? Well, here are a few answers. Programming is a very rewarding and challenging hobby&#x2F;profession. There’s just something about the ecstatic feeling you get when you solve a bug, or devise a concise and elegant algorithm that allows you to create whatever you want.&lt;&#x2F;p&gt;
&lt;p&gt;I’ve been programming for about a year now and will from now on be using this website&#x2F;blog to document my journey into the programming world so that I may one day look back upon all these projects and reminisce the hardships as well as the sweet memories and experiences.&lt;&#x2F;p&gt;
&lt;p&gt;Projects and details about them will go into the Projects page whilst the development logs will be going into my Posts page. I plan to have the posts page contain both programming and life updates so that things can be a little more organised for a better viewing experience.&lt;&#x2F;p&gt;
</description>
      </item>
    </channel>
</rss>
