<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Systems, Simply.</title>
    <description>The latest articles on DEV Community by Systems, Simply. (@systems_simply).</description>
    <link>https://dev.to/systems_simply</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4240289%2F8860112b-df9c-4a96-a4a5-8784f1be66fe.png</url>
      <title>DEV Community: Systems, Simply.</title>
      <link>https://dev.to/systems_simply</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/systems_simply"/>
    <language>en</language>
    <item>
      <title>Variables and Expressions in C: Follow the Values and Types</title>
      <dc:creator>Systems, Simply.</dc:creator>
      <pubDate>Mon, 16 Nov 2026 05:49:15 +0000</pubDate>
      <link>https://dev.to/systems_simply/variables-and-expressions-in-c-follow-the-values-and-types-3c66</link>
      <guid>https://dev.to/systems_simply/variables-and-expressions-in-c-follow-the-values-and-types-3c66</guid>
      <description>&lt;p&gt;In Part 1, we separated saving source code, building a program, and running it. Now let's give the program values to store and calculations to perform.&lt;/p&gt;

&lt;p&gt;Our goal is to understand variables, initialization, assignment, and the types inside a small arithmetic expression. By the end, you will be able to explain why storing &lt;code&gt;5 / 2&lt;/code&gt; in a &lt;code&gt;double&lt;/code&gt; produces &lt;code&gt;2.0&lt;/code&gt;, and calculate a useful progress percentage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Series:&lt;/strong&gt; C, One Experiment at a Time — Part 2.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before you start:&lt;/strong&gt; You should be able to save, build, and run a C program. &lt;a href="https://dev.to/systems_simply/from-c-source-code-to-a-running-program-1i5l"&gt;Part 1 walks through those steps&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test environment:&lt;/strong&gt; Windows, MSVC, C17 mode, x64. Commands use an x64 Visual Studio developer command prompt. The arithmetic examples use small values and nonzero divisors.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Start with named values
&lt;/h2&gt;

&lt;p&gt;Save this complete program as &lt;code&gt;values.c&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;attempts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;snapshot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attempts&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"initial: attempts=%d seconds=%.1f\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attempts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;attempts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attempts&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"updated: attempts=%d snapshot=%d\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attempts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;snapshot&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Build it with &lt;code&gt;cl /nologo /std:c17 /W4 values.c&lt;/code&gt;, then run &lt;code&gt;values.exe&lt;/code&gt; after the build succeeds.&lt;/p&gt;

&lt;p&gt;The tested output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;initial: attempts=3 seconds=2.5
updated: attempts=4 snapshot=3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;int attempts = 3;&lt;/code&gt; defines an integer variable named &lt;code&gt;attempts&lt;/code&gt; and initializes it to &lt;code&gt;3&lt;/code&gt;. &lt;code&gt;double seconds = 2.5;&lt;/code&gt; defines a floating-point variable and initializes it to &lt;code&gt;2.5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The name identifies the variable; the type affects which values it can represent and how expressions using it behave. We use &lt;code&gt;int&lt;/code&gt; for these small whole-number counts and &lt;code&gt;double&lt;/code&gt; for a value with a fractional part. Floating-point types do not represent every decimal fraction exactly; these particular small examples avoid that extra issue.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;printf&lt;/code&gt;, &lt;code&gt;%d&lt;/code&gt; formats an &lt;code&gt;int&lt;/code&gt;, while &lt;code&gt;%.1f&lt;/code&gt; formats a &lt;code&gt;double&lt;/code&gt; with one digit after the decimal point. Formatting controls the displayed text. It does not change how the earlier arithmetic was performed.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Initialization and later assignment do different jobs
&lt;/h2&gt;

&lt;p&gt;This line supplies an initial value when the variable is defined:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;snapshot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attempts&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, &lt;code&gt;attempts&lt;/code&gt; is &lt;code&gt;3&lt;/code&gt;, so &lt;code&gt;snapshot&lt;/code&gt; receives that value.&lt;/p&gt;

&lt;p&gt;Later, this assignment updates &lt;code&gt;attempts&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;attempts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;attempts&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The right side computes &lt;code&gt;3 + 1&lt;/code&gt;; the result becomes the new value of &lt;code&gt;attempts&lt;/code&gt;. The assignment operator &lt;code&gt;=&lt;/code&gt; is not a mathematical claim that the two sides must remain equal forever.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;snapshot&lt;/code&gt; stays &lt;code&gt;3&lt;/code&gt;. Initializing this separate &lt;code&gt;int&lt;/code&gt; variable copied a value; it did not establish a live connection between the variables. A snapshot is a photo, not a livestream.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Point in the program&lt;/th&gt;
&lt;th&gt;attempts&lt;/th&gt;
&lt;th&gt;snapshot&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;After snapshot is initialized&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;After attempts is assigned attempts + 1&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Initialize these local variables before reading them. This tutorial does not use an uninitialized value as a way to generate an interesting result.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Follow the expression before its destination
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2cm2vz4acq7vqhmg7ubo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2cm2vz4acq7vqhmg7ubo.png" alt="In C, 5 / 2 produces int 2, which becomes double 2.0 on initialization. Casting the completed integer division to double also gives 2.0. Casting an operand before division, (double)5 / 2, gives 2.5." width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;assigned&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two constants are of type &lt;code&gt;int&lt;/code&gt;. Their division therefore produces an integer result: &lt;code&gt;2&lt;/code&gt;. That result is then converted to &lt;code&gt;double&lt;/code&gt; for initialization, giving &lt;code&gt;2.0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The destination type does not retroactively turn the division into floating-point division. Here is a useful way to trace it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int 5 / int 2 -&amp;gt; int 2 -&amp;gt; convert to double -&amp;gt; 2.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare that with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;fractional&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;5.0&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;5.0&lt;/code&gt; is a &lt;code&gt;double&lt;/code&gt; constant. For this division, the &lt;code&gt;int&lt;/code&gt; operand is converted to &lt;code&gt;double&lt;/code&gt;, and the calculation produces &lt;code&gt;2.5&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;double 5.0 / int 2 -&amp;gt; floating-point division -&amp;gt; double 2.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are explanations of the expression's types and value, not promises about the exact machine instructions a compiler will emit.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Put the conversion where it can help
&lt;/h2&gt;

&lt;p&gt;Save this as &lt;code&gt;division.c&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;assigned&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;cast_after&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;cast_before&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;right_operand&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"assigned=%.1f\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;assigned&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"cast_after=%.1f\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cast_after&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"cast_before=%.1f\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cast_before&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"right_operand=%.1f\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;right_operand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Build with &lt;code&gt;cl /nologo /std:c17 /W4 division.c&lt;/code&gt;, then run &lt;code&gt;division.exe&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;assigned=2.0
cast_after=2.0
cast_before=2.5
right_operand=2.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;(double)(a / b)&lt;/code&gt; converts the result of integer division. The fractional part was already discarded by that division, so converting &lt;code&gt;2&lt;/code&gt; produces &lt;code&gt;2.0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;(double)a / b&lt;/code&gt; converts an operand before division. In this example, that makes the calculation floating-point division. Converting the other operand, as in &lt;code&gt;a / (double)b&lt;/code&gt;, also works here.&lt;/p&gt;

&lt;p&gt;A cast is not a general correctness repair. We are using it for a specific purpose: changing the type of an operand in this expression.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Use the rule to calculate progress
&lt;/h2&gt;

&lt;p&gt;Suppose you have completed 5 of 8 planned exercises. You expect &lt;code&gt;62.5%&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Save this as &lt;code&gt;progress.c&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;completed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;planned&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;lost_fraction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;completed&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;planned&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;percent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;100.0&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;completed&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;planned&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"integer_first=%d\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lost_fraction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"floating_first=%.1f\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;percent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Build with &lt;code&gt;cl /nologo /std:c17 /W4 progress.c&lt;/code&gt;, then run &lt;code&gt;progress.exe&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;integer_first=0
floating_first=62.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;completed / planned * 100&lt;/code&gt;, the operators group left to right: &lt;code&gt;(5 / 8) * 100&lt;/code&gt;. Integer division produces &lt;code&gt;0&lt;/code&gt;, and multiplying that by &lt;code&gt;100&lt;/code&gt; still gives &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;100.0 * completed / planned&lt;/code&gt;, the calculation starts with a &lt;code&gt;double&lt;/code&gt; operand. With our values, &lt;code&gt;500.0 / 8&lt;/code&gt; produces &lt;code&gt;62.5&lt;/code&gt;. A nonzero &lt;code&gt;planned&lt;/code&gt; value is a condition of this example; we will handle input checks when we reach conditions and branches.&lt;/p&gt;

&lt;p&gt;All the examples use small values. They are not a complete guide to integer overflow, division by zero, signed/unsigned conversions, or floating-point rounding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it yourself
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;In &lt;code&gt;values.c&lt;/code&gt;, initialize &lt;code&gt;attempts&lt;/code&gt; to &lt;code&gt;7&lt;/code&gt;. Predict &lt;code&gt;attempts&lt;/code&gt; and &lt;code&gt;snapshot&lt;/code&gt; after the assignment.&lt;/li&gt;
&lt;li&gt;In &lt;code&gt;division.c&lt;/code&gt;, set &lt;code&gt;a&lt;/code&gt; to &lt;code&gt;7&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; to &lt;code&gt;2&lt;/code&gt;. Predict all four results before running it.&lt;/li&gt;
&lt;li&gt;In &lt;code&gt;progress.c&lt;/code&gt;, set &lt;code&gt;completed&lt;/code&gt; to &lt;code&gt;3&lt;/code&gt; and keep &lt;code&gt;planned&lt;/code&gt; at &lt;code&gt;8&lt;/code&gt;. Predict both printed results.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Check your reasoning
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;attempts&lt;/code&gt; becomes &lt;code&gt;8&lt;/code&gt;; &lt;code&gt;snapshot&lt;/code&gt; stays &lt;code&gt;7&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The results are &lt;code&gt;3.0&lt;/code&gt;, &lt;code&gt;3.0&lt;/code&gt;, &lt;code&gt;3.5&lt;/code&gt;, and &lt;code&gt;3.5&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Integer-first gives &lt;code&gt;0&lt;/code&gt;; floating-first gives &lt;code&gt;37.5&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These exercise predictions follow the same rules. The three main programs above were compiled and run locally; see the testing note below for the tested scope.&lt;/p&gt;

&lt;p&gt;Next, we will use conditions and loops to let a program choose and repeat work. For now, the habit to keep is: identify the operands, follow the calculation, and only then look at the destination variable.&lt;/p&gt;

&lt;p&gt;Have you encountered a calculation where changing the destination type did not change the answer? What expression caused it?&lt;/p&gt;

&lt;h2&gt;
  
  
  References and testing
&lt;/h2&gt;

&lt;p&gt;The three complete programs above were built and run with MSVC in C17 x64 mode, with &lt;code&gt;/W4 /WX&lt;/code&gt; during verification. Output was checked against expected results. The test record also contains a separate size/limits experiment, which this tutorial does not use to claim fixed type sizes across implementations.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/cpp/c-language/initializing-scalar-types?view=msvc-170" rel="noopener noreferrer"&gt;MSVC: initializing scalar types&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/cpp/c-language/assignment-conversions?view=msvc-170" rel="noopener noreferrer"&gt;MSVC: assignment conversions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/cpp/c-language/usual-arithmetic-conversions?view=msvc-170" rel="noopener noreferrer"&gt;MSVC: usual arithmetic conversions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-170" rel="noopener noreferrer"&gt;MSVC: printf format specifications&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Writing note: Prepared with AI assistance; the main code examples were tested locally.&lt;/p&gt;

</description>
      <category>c</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>From C Source Code to a Running Program</title>
      <dc:creator>Systems, Simply.</dc:creator>
      <pubDate>Fri, 13 Nov 2026 03:28:40 +0000</pubDate>
      <link>https://dev.to/systems_simply/from-c-source-code-to-a-running-program-1i5l</link>
      <guid>https://dev.to/systems_simply/from-c-source-code-to-a-running-program-1i5l</guid>
      <description>&lt;p&gt;Saving a C file and running a C program are different actions. An editor may put them behind one convenient button, but the steps still matter when something goes wrong.&lt;/p&gt;

&lt;p&gt;This walkthrough follows one small program from source code to output. Along the way, we will deliberately break it in two different ways, then investigate how an old executable can survive a failed build.&lt;/p&gt;

&lt;p&gt;By the end, you should be able to build and run the program, recognize the files involved, and choose a sensible first check when the result is unexpected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Series:&lt;/strong&gt; C, One Experiment at a Time — Part 1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Environment:&lt;/strong&gt; Windows, MSVC, C17 mode, and an x64 Visual Studio developer command prompt. The commands below use Command Prompt syntax. This assumes the Visual Studio C/C++ build tools are already installed; it is not an installation guide. Other toolchains use different commands and sometimes different filenames.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Start with a program whose result you can check
&lt;/h2&gt;

&lt;p&gt;Create a working folder and save this as &lt;code&gt;hello.c&lt;/code&gt;. Make sure the filename really ends in &lt;code&gt;.c&lt;/code&gt;, rather than &lt;code&gt;.c.txt&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello from C.\n"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only a few details are needed for this experiment:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;stdio.h&amp;gt;&lt;/code&gt; provides the declaration of &lt;code&gt;printf&lt;/code&gt;, the standard output function we use here. Including a header does not paste the implementation of &lt;code&gt;printf&lt;/code&gt; into this file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;int main(void)&lt;/code&gt; defines the starting function for this ordinary hosted C program. &lt;code&gt;void&lt;/code&gt; here means that this function has no parameters.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;printf&lt;/code&gt; writes the message to standard output, which normally appears in our terminal. &lt;code&gt;\n&lt;/code&gt; adds a newline.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;return 0;&lt;/code&gt; reports successful completion to the environment that started the program. It does not print a zero.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal is a visible, checkable result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello from C.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Build first, then run
&lt;/h2&gt;

&lt;p&gt;Open an &lt;strong&gt;x64 Native Tools Command Prompt for Visual Studio&lt;/strong&gt;, then change to the folder containing &lt;code&gt;hello.c&lt;/code&gt;. If its path contains spaces, put the path in double quotes.&lt;/p&gt;

&lt;p&gt;Build with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="n"&gt;cl&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nologo&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;c17&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="no"&gt;W4&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the command finishes successfully, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exe&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first command creates a program. The second starts it.&lt;/p&gt;

&lt;p&gt;Here, &lt;code&gt;cl&lt;/code&gt; is MSVC's compiler driver: it can control compilation and invoke the linker. &lt;code&gt;/std:c17&lt;/code&gt; selects C17 mode, &lt;code&gt;/W4&lt;/code&gt; enables a useful warning level, and &lt;code&gt;/nologo&lt;/code&gt; hides the startup banner. Warnings deserve attention even when a build succeeds.&lt;/p&gt;

&lt;p&gt;For this simple build, you should find &lt;code&gt;hello.obj&lt;/code&gt; and &lt;code&gt;hello.exe&lt;/code&gt; alongside your source file. A larger project or an IDE may place these outputs elsewhere.&lt;/p&gt;

&lt;p&gt;If the terminal says that &lt;code&gt;cl&lt;/code&gt; is not recognized, check that you opened the developer command prompt and installed the C/C++ tools. That message is about the tool environment, not a diagnosis of your C code.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Make the build stages visible
&lt;/h2&gt;

&lt;p&gt;Our useful first model is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hello.c  --compile to object--&amp;gt;  hello.obj
hello.obj  ------link---------&amp;gt;  hello.exe
hello.exe  ------run----------&amp;gt;  terminal output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft4d8cpe8zdq6a8z2d7e4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft4d8cpe8zdq6a8z2d7e4.png" alt="C source code is compiled into an object file, linked into an executable, and run to produce output. The simplified compile step groups preprocessing, compilation and assembly. Example filenames use MSVC on Windows." width="800" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The middle file is worth noticing. An object file is an intermediate input to the linker; it is not the final executable you start in this walkthrough.&lt;/p&gt;

&lt;p&gt;We can ask MSVC to stop before linking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="n"&gt;cl&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nologo&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;c17&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="no"&gt;W4&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;/c&lt;/code&gt; option produces the object file without invoking the linker. Then link explicitly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="n"&gt;link&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nologo&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="no"&gt;OUT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exe&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exe&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output is still &lt;code&gt;Hello from C.&lt;/code&gt; We changed how explicitly we requested the stages, not what the program does.&lt;/p&gt;

&lt;p&gt;“Compile to object” is a simplified label. A conventional toolchain also preprocesses the source and translates it through compilation and assembly before linking. The diagram groups those earlier stages so we can focus on the distinction between building and running. It is not claiming that every implementation exposes identical files or separate commands for each stage.&lt;/p&gt;

&lt;p&gt;Linking brings together the required object code and libraries and resolves references between them. In this example, it connects our program with the runtime support it needs. A header declaration and a function implementation have different jobs; including &lt;code&gt;&amp;lt;stdio.h&amp;gt;&lt;/code&gt; does not remove the need for linking.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Break compilation: remove one semicolon
&lt;/h2&gt;

&lt;p&gt;Save this separate file as &lt;code&gt;syntax_error.c&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello from C.\n"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try compiling it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="n"&gt;cl&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nologo&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;c17&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="no"&gt;W4&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="n"&gt;syntax_error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The semicolon after &lt;code&gt;printf(...)&lt;/code&gt; is missing. In the tested MSVC environment, this reports &lt;strong&gt;C2143&lt;/strong&gt;, pointing near &lt;code&gt;return&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;An error location is where the compiler detected a problem; the edit you need may be just before it. Check the diagnostic and the surrounding code, rather than assuming the highlighted token is always the cause.&lt;/p&gt;

&lt;p&gt;This attempt has not reached a successful link or run. Fix the syntax before investigating the program's output.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Break linking: promise a function, but never define it
&lt;/h2&gt;

&lt;p&gt;Save this as &lt;code&gt;missing_definition.c&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;missing_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;missing_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line declares a function. For now, think of it as describing how the function can be called, without providing its body.&lt;/p&gt;

&lt;p&gt;Compile it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="n"&gt;cl&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nologo&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;c17&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="no"&gt;W4&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="n"&gt;missing_definition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This succeeds in the tested environment and creates &lt;code&gt;missing_definition.obj&lt;/code&gt;. Now try to link it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="n"&gt;link&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nologo&lt;/span&gt; &lt;span class="n"&gt;missing_definition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="no"&gt;OUT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;missing_definition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exe&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MSVC reports &lt;strong&gt;LNK2019&lt;/strong&gt;, followed by &lt;strong&gt;LNK1120&lt;/strong&gt;. Our object code refers to &lt;code&gt;missing_function&lt;/code&gt;, but we have supplied no definition in an object file or library.&lt;/p&gt;

&lt;p&gt;Why can compilation succeed? In a multi-file program, a function's definition can live elsewhere. The linker is where that missing piece must be resolved for this build.&lt;/p&gt;

&lt;p&gt;The useful distinction is already visible: code can compile into an object file and still fail to become a usable executable. We will return to function declarations and definitions in the functions unit.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Why can an old message appear after a failed build?
&lt;/h2&gt;

&lt;p&gt;Return to a working &lt;code&gt;hello.c&lt;/code&gt;. Change its message to &lt;code&gt;Version 1&lt;/code&gt;, build successfully, and run it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Version 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now change the message to &lt;code&gt;Version 2&lt;/code&gt;, but deliberately remove the semicolon:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Version 2\n"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the file and run the build command again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="n"&gt;cl&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nologo&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;c17&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="no"&gt;W4&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It fails. If you then explicitly run the existing executable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="n"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exe&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;it can still print:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Version 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No time travel involved. In this tested sequence, compilation failed before replacing the previous executable, and we manually launched that older file.&lt;/p&gt;

&lt;p&gt;This does &lt;strong&gt;not&lt;/strong&gt; mean every IDE automatically runs an old build after an error. An IDE may stop, prompt you, or handle output differently. The experiment deliberately separates the failed build from the later command that starts the existing file.&lt;/p&gt;

&lt;p&gt;Restore the semicolon, save, build successfully, and run again. The output becomes &lt;code&gt;Version 2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When an edit appears to do nothing, check:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Did you save the intended source file?&lt;/li&gt;
&lt;li&gt;Did the latest build actually succeed?&lt;/li&gt;
&lt;li&gt;Are you running the executable from that build, in the intended directory?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Saving a new source file does not by itself update an existing executable.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. A successful build still needs a result check
&lt;/h2&gt;

&lt;p&gt;There is another kind of mistake that these build stages cannot diagnose for you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"2 + 3 = %d\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This builds and runs in the tested environment, producing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2 + 3 = -1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The label says addition, but the expression performs subtraction. Both are valid C; the compiler does not know which task we intended.&lt;/p&gt;

&lt;p&gt;“It builds” is good news. It is not a correctness certificate. Compare the output with an expected result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it yourself
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Change the greeting, predict the output, then save, rebuild, and run.&lt;/li&gt;
&lt;li&gt;Repeat the missing-semicolon experiment. Before running anything, identify whether the latest build succeeded.&lt;/li&gt;
&lt;li&gt;Fix the arithmetic example, then explain why its earlier version could build successfully.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We now have a practical foundation for the next unit: variables, types, and expressions. That is where we will start replacing fixed examples with values we can store and calculate with.&lt;/p&gt;

&lt;p&gt;If you have seen a program ignore your edits, what turned out to be the cause: an unsaved file, a failed build, a different executable, or something else?&lt;/p&gt;

&lt;h2&gt;
  
  
  References and testing
&lt;/h2&gt;

&lt;p&gt;The normal build, separate compilation and linking, intentional compile/link failures, arithmetic mistake, and old-executable sequence were executed locally with MSVC on Windows in C17 mode. Diagnostic numbers and wording may differ with another compiler. This walkthrough does not claim to test runtime crashes or other toolchains.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options?view=msvc-170" rel="noopener noreferrer"&gt;MSVC compiler driver and environment&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/cpp/build/reference/c-compile-without-linking?view=msvc-170" rel="noopener noreferrer"&gt;MSVC: compile without linking&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=msvc-170" rel="noopener noreferrer"&gt;MSVC: language standard modes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2019?view=msvc-170" rel="noopener noreferrer"&gt;MSVC: LNK2019&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html" rel="noopener noreferrer"&gt;GCC: conventional build stages&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Writing note: Prepared with AI assistance; code examples were tested locally.&lt;/p&gt;

</description>
      <category>c</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
