Creating User-Defined Functions in C With Practical Examples
What is Creating User-Defined Functions in C With Practical Examples? The previous page covered the theory of functions — types, syntax, pass by value. This page is about the craft: actually sitting down and writing...
How do you design, write, and integrate user-defined functions into a C software project?
Explanation & In-Depth Details
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-id">int</span> <span class="js-id">isEven</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">n</span><span class="js-op">)</span> <span class="js-op">{</span>
<span class="js-kw">return</span> <span class="js-op">(</span><span class="js-id">n</span> <span class="js-op">%</span> <span class="js-num">2</span> <span class="js-op">==</span> <span class="js-num">0</span><span class="js-op">);</span> <span class="js-cm">// comparison gives 1 (true) or 0 (false)</span>
<span class="js-op">}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Job, inputs, output. Answer three questions, get a function. Let's prove it works on bigger problems.</p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">Example 1: Prime Number Checker</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Design:</span></p><ol class="list-inside list-decimal whitespace-normal [li_&]:pl-6" data-streamdown="ordered-list" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); list-style-position: outside; list-style-image: initial; padding-inline-start: 1.375rem; margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Job: <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">"Report whether a number is prime"</em></li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Needs: the number → <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">int n</code></li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Gives back: yes/no → <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">int</code> (1 or 0)</li></ol><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;">#<span class="js-id">include</span> <span class="js-op"><</span><span class="js-id">stdio</span><span class="js-op">.</span><span class="js-id">h</span><span class="js-op">></span>
<span class="js-id">int</span> <span class="js-id">isPrime</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">n</span><span class="js-op">);</span> <span class="js-cm">// declaration</span>
<span class="js-id">int</span> <span class="js-id">main</span><span class="js-op">()</span> <span class="js-op">{</span> <span class="js-id">int</span> <span class="js-id">num</span><span class="js-op">;</span>
<span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"Enter a number: "</span><span class="js-op">);</span> <span class="js-id">scanf</span><span class="js-op">(</span><span class="js-str">"%d"</span><span class="js-op">,</span> <span class="js-op">&</span><span class="js-id">num</span><span class="js-op">);</span>
<span class="js-kw">if</span> <span class="js-op">(</span><span class="js-id">isPrime</span><span class="js-op">(</span><span class="js-id">num</span><span class="js-op">))</span> <span class="js-op">{</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"%d is prime.\n"</span><span class="js-op">,</span> <span class="js-id">num</span><span class="js-op">);</span> <span class="js-op">}</span> <span class="js-kw">else</span> <span class="js-op">{</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"%d is not prime.\n"</span><span class="js-op">,</span> <span class="js-id">num</span><span class="js-op">);</span> <span class="js-op">}</span>
<span class="js-kw">return</span> <span class="js-num">0</span><span class="js-op">;}</span>
<span class="js-id">int</span> <span class="js-id">isPrime</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">n</span><span class="js-op">)</span> <span class="js-op">{</span> <span class="js-kw">if</span> <span class="js-op">(</span><span class="js-id">n</span> <span class="js-op"><</span> <span class="js-num">2</span><span class="js-op">)</span> <span class="js-op">{</span> <span class="js-kw">return</span> <span class="js-num">0</span><span class="js-op">;</span> <span class="js-cm">// 0 and 1 are not prime — done, exit early }</span>
<span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">2</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-id">n</span> <span class="js-op">/</span> <span class="js-num">2</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-kw">if</span> <span class="js-op">(</span><span class="js-id">n</span> <span class="js-op">%</span> <span class="js-id">i</span> <span class="js-op">==</span> <span class="js-num">0</span><span class="js-op">)</span> <span class="js-op">{</span> <span class="js-kw">return</span> <span class="js-num">0</span><span class="js-op">;</span> <span class="js-cm">// found a divisor — not prime, exit now } }</span>
<span class="js-kw">return</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-cm">// survived all checks — prime}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Sample Runs:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-id">Enter</span> <span class="js-id">a</span> <span class="js-id">number</span><span class="js-op">:</span> <span class="js-num">2929</span> <span class="js-id">is</span> <span class="js-id">prime</span><span class="js-op">.</span></code></pre></div></div></div><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-id">Enter</span> <span class="js-id">a</span> <span class="js-id">number</span><span class="js-op">:</span> <span class="js-num">5151</span> <span class="js-id">is</span> <span class="js-id">not</span> <span class="js-id">prime</span><span class="js-op">.</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Notice the design elegance: <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">isPrime</code> knows nothing about keyboards or screens. It takes a number, answers a question. All the printf/scanf lives in <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">main</code>. That separation — <span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">logic in functions, I/O at the edges</span> — is the single most professional habit on this page.</p><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Also notice the readability win: <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">if (isPrime(num))</code> reads like English. The function name <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">is</em> the documentation.</p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">Example 2: Power Function (No math.h Needed)</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Design:</span></p><ol class="list-inside list-decimal whitespace-normal [li_&]:pl-6" data-streamdown="ordered-list" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); list-style-position: outside; list-style-image: initial; padding-inline-start: 1.375rem; margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Job: <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">"Calculate base raised to an exponent"</em></li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Needs: two integers → <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">int base, int exp</code></li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Gives back: the result → <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">long</code> (powers get big fast!)</li></ol><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;">#<span class="js-id">include</span> <span class="js-op"><</span><span class="js-id">stdio</span><span class="js-op">.</span><span class="js-id">h</span><span class="js-op">></span>
<span class="js-id">long</span> <span class="js-id">power</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">base</span><span class="js-op">,</span> <span class="js-id">int</span> <span class="js-id">exp</span><span class="js-op">);</span>
<span class="js-id">int</span> <span class="js-id">main</span><span class="js-op">()</span> <span class="js-op">{</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"2^10 = %ld\n"</span><span class="js-op">,</span> <span class="js-id">power</span><span class="js-op">(</span><span class="js-num">2</span><span class="js-op">,</span> <span class="js-num">10</span><span class="js-op">));</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"5^3 = %ld\n"</span><span class="js-op">,</span> <span class="js-id">power</span><span class="js-op">(</span><span class="js-num">5</span><span class="js-op">,</span> <span class="js-num">3</span><span class="js-op">));</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"7^0 = %ld\n"</span><span class="js-op">,</span> <span class="js-id">power</span><span class="js-op">(</span><span class="js-num">7</span><span class="js-op">,</span> <span class="js-num">0</span><span class="js-op">));</span> <span class="js-kw">return</span> <span class="js-num">0</span><span class="js-op">;}</span>
<span class="js-id">long</span> <span class="js-id">power</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">base</span><span class="js-op">,</span> <span class="js-id">int</span> <span class="js-id">exp</span><span class="js-op">)</span> <span class="js-op">{</span> <span class="js-id">long</span> <span class="js-id">result</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span>
<span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">1</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><=</span> <span class="js-id">exp</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-id">result</span> <span class="js-op">*=</span> <span class="js-id">base</span><span class="js-op">;</span> <span class="js-op">}</span>
<span class="js-kw">return</span> <span class="js-id">result</span><span class="js-op">;}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Output:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-num">2</span><span class="js-op">^</span><span class="js-num">10</span> <span class="js-op">=</span> <span class="js-num">10245</span><span class="js-op">^</span><span class="js-num">3</span> <span class="js-op">=</span> <span class="js-num">1257</span><span class="js-op">^</span><span class="js-num">0</span> <span class="js-op">=</span> <span class="js-num">1</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Two lessons hiding in here: the result starts at <span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">1</span>, not 0 (multiply by zero and everything dies — accumulator initialization matters!), and the return type is <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">long</code> because <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">2^31</code> doesn't fit in an <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">int</code>. Choosing types is part of designing functions.</p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">Example 3: Palindrome Number Checker</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Design:</span></p><ol class="list-inside list-decimal whitespace-normal [li_&]:pl-6" data-streamdown="ordered-list" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); list-style-position: outside; list-style-image: initial; padding-inline-start: 1.375rem; margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Job: <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">"Check if a number reads the same backward"</em></li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Needs: the number → <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">int n</code></li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Gives back: yes/no → <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">int</code></li></ol><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Here we reuse the digit-reversal trick from our while-loop tutorial — as a <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">helper function</em>:</p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;">#<span class="js-id">include</span> <span class="js-op"><</span><span class="js-id">stdio</span><span class="js-op">.</span><span class="js-id">h</span><span class="js-op">></span>
<span class="js-id">int</span> <span class="js-id">reverseNumber</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">n</span><span class="js-op">);</span> <span class="js-cm">// helperint isPalindrome(int n);</span>
<span class="js-id">int</span> <span class="js-id">main</span><span class="js-op">()</span> <span class="js-op">{</span> <span class="js-id">int</span> <span class="js-id">num</span><span class="js-op">;</span>
<span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"Enter a number: "</span><span class="js-op">);</span> <span class="js-id">scanf</span><span class="js-op">(</span><span class="js-str">"%d"</span><span class="js-op">,</span> <span class="js-op">&</span><span class="js-id">num</span><span class="js-op">);</span>
<span class="js-kw">if</span> <span class="js-op">(</span><span class="js-id">isPalindrome</span><span class="js-op">(</span><span class="js-id">num</span><span class="js-op">))</span> <span class="js-op">{</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"%d is a palindrome.\n"</span><span class="js-op">,</span> <span class="js-id">num</span><span class="js-op">);</span> <span class="js-op">}</span> <span class="js-kw">else</span> <span class="js-op">{</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"%d is not a palindrome.\n"</span><span class="js-op">,</span> <span class="js-id">num</span><span class="js-op">);</span> <span class="js-op">}</span>
<span class="js-kw">return</span> <span class="js-num">0</span><span class="js-op">;}</span>
<span class="js-id">int</span> <span class="js-id">reverseNumber</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">n</span><span class="js-op">)</span> <span class="js-op">{</span> <span class="js-id">int</span> <span class="js-id">reversed</span> <span class="js-op">=</span> <span class="js-num">0</span><span class="js-op">;</span>
<span class="js-kw">while</span> <span class="js-op">(</span><span class="js-id">n</span> <span class="js-op">!=</span> <span class="js-num">0</span><span class="js-op">)</span> <span class="js-op">{</span> <span class="js-id">reversed</span> <span class="js-op">=</span> <span class="js-id">reversed</span> <span class="js-op">*</span> <span class="js-num">10</span> <span class="js-op">+</span> <span class="js-op">(</span><span class="js-id">n</span> <span class="js-op">%</span> <span class="js-num">10</span><span class="js-op">);</span> <span class="js-id">n</span> <span class="js-op">/=</span> <span class="js-num">10</span><span class="js-op">;</span> <span class="js-op">}</span>
<span class="js-kw">return</span> <span class="js-id">reversed</span><span class="js-op">;}</span>
<span class="js-id">int</span> <span class="js-id">isPalindrome</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">n</span><span class="js-op">)</span> <span class="js-op">{</span> <span class="js-kw">return</span> <span class="js-op">(</span><span class="js-id">n</span> <span class="js-op">==</span> <span class="js-id">reverseNumber</span><span class="js-op">(</span><span class="js-id">n</span><span class="js-op">));</span> <span class="js-cm">// palindrome = number equals its reverse}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Sample Run:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-id">Enter</span> <span class="js-id">a</span> <span class="js-id">number</span><span class="js-op">:</span> <span class="js-num">12211221</span> <span class="js-id">is</span> <span class="js-id">a</span> <span class="js-id">palindrome</span><span class="js-op">.</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">This is the big moment in this tutorial:</span> <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">isPalindrome</code> doesn't reverse anything itself — it <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">calls another user-defined function</em>. Functions building on functions. That's not a trick; that's how all real software is assembled, from calculators to operating systems.</p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">Example 4: A void Function — Printing a Report Header</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Not every function computes. Some just <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">do</em> — and those return <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">void</code>:</p><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Design:</span></p><ol class="list-inside list-decimal whitespace-normal [li_&]:pl-6" data-streamdown="ordered-list" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); list-style-position: outside; list-style-image: initial; padding-inline-start: 1.375rem; margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Job: <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">"Print a formatted report header"</em></li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Needs: the title text → <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">char title[]</code></li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Gives back: nothing → <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">void</code></li></ol><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;">#<span class="js-id">include</span> <span class="js-op"><</span><span class="js-id">stdio</span><span class="js-op">.</span><span class="js-id">h</span><span class="js-op">></span>
<span class="js-kw">void</span> <span class="js-id">printHeader</span><span class="js-op">(</span><span class="js-id">char</span> <span class="js-id">title</span>[]<span class="js-op">);</span><span class="js-kw">void</span> <span class="js-id">printLine</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">length</span><span class="js-op">);</span>
<span class="js-id">int</span> <span class="js-id">main</span><span class="js-op">()</span> <span class="js-op">{</span> <span class="js-id">printHeader</span><span class="js-op">(</span><span class="js-str">"SALES REPORT"</span><span class="js-op">);</span> <span class="js-id">puts</span><span class="js-op">(</span><span class="js-str">"Item 1 ....... 450.00"</span><span class="js-op">);</span> <span class="js-id">puts</span><span class="js-op">(</span><span class="js-str">"Item 2 ....... 299.99"</span><span class="js-op">);</span> <span class="js-id">printLine</span><span class="js-op">(</span><span class="js-num">30</span><span class="js-op">);</span> <span class="js-kw">return</span> <span class="js-num">0</span><span class="js-op">;}</span>
<span class="js-kw">void</span> <span class="js-id">printHeader</span><span class="js-op">(</span><span class="js-id">char</span> <span class="js-id">title</span>[]<span class="js-op">)</span> <span class="js-op">{</span> <span class="js-id">printLine</span><span class="js-op">(</span><span class="js-num">30</span><span class="js-op">);</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">" %s\n"</span><span class="js-op">,</span> <span class="js-id">title</span><span class="js-op">);</span> <span class="js-id">printLine</span><span class="js-op">(</span><span class="js-num">30</span><span class="js-op">);}</span>
<span class="js-kw">void</span> <span class="js-id">printLine</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">length</span><span class="js-op">)</span> <span class="js-op">{</span> <span class="js-kw">for</span> <span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">i</span> <span class="js-op">=</span> <span class="js-num">0</span><span class="js-op">;</span> <span class="js-id">i</span> <span class="js-op"><</span> <span class="js-id">length</span><span class="js-op">;</span> <span class="js-id">i</span><span class="js-op">++)</span> <span class="js-op">{</span> <span class="js-id">putchar</span><span class="js-op">(</span><span class="js-str">'-'</span><span class="js-op">);</span> <span class="js-op">}</span> <span class="js-id">putchar</span><span class="js-op">(</span><span class="js-str">'\n'</span><span class="js-op">);}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Output:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-op">------------------------------</span> <span class="js-id">SALES</span> <span class="js-id">REPORT</span><span class="js-op">------------------------------</span><span class="js-id">Item</span> <span class="js-num">1</span> <span class="js-op">.......</span> <span class="js-num">450</span><span class="js-op">.</span>00Item <span class="js-num">2</span> <span class="js-op">.......</span> <span class="js-num">299.99</span><span class="js-op">------------------------------</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">void</code> functions are the workhorses of menus, banners, and display code. And look — <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">printHeader</code> calls <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">printLine</code>. Even trivial functions compose.</p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">Example 5: Functions Calling Functions — Grade Calculator</h2><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;">#<span class="js-id">include</span> <span class="js-op"><</span><span class="js-id">stdio</span><span class="js-op">.</span><span class="js-id">h</span><span class="js-op">></span>
<span class="js-id">float</span> <span class="js-id">calculateAverage</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">total</span><span class="js-op">,</span> <span class="js-id">int</span> <span class="js-id">subjects</span><span class="js-op">);</span><span class="js-id">char</span> <span class="js-id">assignGrade</span><span class="js-op">(</span><span class="js-id">float</span> <span class="js-id">average</span><span class="js-op">);</span><span class="js-kw">void</span> <span class="js-id">printReport</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">total</span><span class="js-op">,</span> <span class="js-id">float</span> <span class="js-id">average</span><span class="js-op">,</span> <span class="js-id">char</span> <span class="js-id">grade</span><span class="js-op">);</span>
<span class="js-id">int</span> <span class="js-id">main</span><span class="js-op">()</span> <span class="js-op">{</span> <span class="js-id">int</span> <span class="js-id">m1</span><span class="js-op">,</span> <span class="js-id">m2</span><span class="js-op">,</span> <span class="js-id">m3</span><span class="js-op">;</span>
<span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"Enter marks for 3 subjects: "</span><span class="js-op">);</span> <span class="js-id">scanf</span><span class="js-op">(</span><span class="js-str">"%d %d %d"</span><span class="js-op">,</span> <span class="js-op">&</span><span class="js-id">m1</span><span class="js-op">,</span> <span class="js-op">&</span><span class="js-id">m2</span><span class="js-op">,</span> <span class="js-op">&</span><span class="js-id">m3</span><span class="js-op">);</span>
<span class="js-id">int</span> <span class="js-id">total</span> <span class="js-op">=</span> <span class="js-id">m1</span> <span class="js-op">+</span> <span class="js-id">m2</span> <span class="js-op">+</span> <span class="js-id">m3</span><span class="js-op">;</span> <span class="js-id">float</span> <span class="js-id">avg</span> <span class="js-op">=</span> <span class="js-id">calculateAverage</span><span class="js-op">(</span><span class="js-id">total</span><span class="js-op">,</span> <span class="js-num">3</span><span class="js-op">);</span> <span class="js-id">char</span> <span class="js-id">grade</span> <span class="js-op">=</span> <span class="js-id">assignGrade</span><span class="js-op">(</span><span class="js-id">avg</span><span class="js-op">);</span>
<span class="js-id">printReport</span><span class="js-op">(</span><span class="js-id">total</span><span class="js-op">,</span> <span class="js-id">avg</span><span class="js-op">,</span> <span class="js-id">grade</span><span class="js-op">);</span> <span class="js-kw">return</span> <span class="js-num">0</span><span class="js-op">;}</span>
<span class="js-id">float</span> <span class="js-id">calculateAverage</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">total</span><span class="js-op">,</span> <span class="js-id">int</span> <span class="js-id">subjects</span><span class="js-op">)</span> <span class="js-op">{</span> <span class="js-kw">return</span> <span class="js-op">(</span><span class="js-id">float</span><span class="js-op">)</span><span class="js-id">total</span> <span class="js-op">/</span> <span class="js-id">subjects</span><span class="js-op">;</span> <span class="js-cm">// cast to float — no integer division!}</span>
<span class="js-id">char</span> <span class="js-id">assignGrade</span><span class="js-op">(</span><span class="js-id">float</span> <span class="js-id">average</span><span class="js-op">)</span> <span class="js-op">{</span> <span class="js-kw">if</span> <span class="js-op">(</span><span class="js-id">average</span> <span class="js-op">>=</span> <span class="js-num">90</span><span class="js-op">)</span> <span class="js-kw">return</span> <span class="js-str">'A'</span><span class="js-op">;</span> <span class="js-kw">if</span> <span class="js-op">(</span><span class="js-id">average</span> <span class="js-op">>=</span> <span class="js-num">75</span><span class="js-op">)</span> <span class="js-kw">return</span> <span class="js-str">'B'</span><span class="js-op">;</span> <span class="js-kw">if</span> <span class="js-op">(</span><span class="js-id">average</span> <span class="js-op">>=</span> <span class="js-num">60</span><span class="js-op">)</span> <span class="js-kw">return</span> <span class="js-str">'C'</span><span class="js-op">;</span> <span class="js-kw">if</span> <span class="js-op">(</span><span class="js-id">average</span> <span class="js-op">>=</span> <span class="js-num">40</span><span class="js-op">)</span> <span class="js-kw">return</span> <span class="js-str">'D'</span><span class="js-op">;</span> <span class="js-kw">return</span> <span class="js-str">'F'</span><span class="js-op">;}</span>
<span class="js-kw">void</span> <span class="js-id">printReport</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">total</span><span class="js-op">,</span> <span class="js-id">float</span> <span class="js-id">average</span><span class="js-op">,</span> <span class="js-id">char</span> <span class="js-id">grade</span><span class="js-op">)</span> <span class="js-op">{</span> <span class="js-id">puts</span><span class="js-op">(</span><span class="js-str">"\n===== REPORT CARD ====="</span><span class="js-op">);</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"Total : %d / 300\n"</span><span class="js-op">,</span> <span class="js-id">total</span><span class="js-op">);</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"Average : %.2f\n"</span><span class="js-op">,</span> <span class="js-id">average</span><span class="js-op">);</span> <span class="js-id">printf</span><span class="js-op">(</span><span class="js-str">"Grade : %c\n"</span><span class="js-op">,</span> <span class="js-id">grade</span><span class="js-op">);}</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Sample Run:</span></p><div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem 0.75rem; background: 0px 0px rgb(18, 18, 22); gap: 0px; --tw-space-y-reverse: 0; display: flex; width: 960px; flex-direction: column; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="" data-language="" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-id">Enter</span> <span class="js-id">marks</span> <span class="js-kw">for</span> <span class="js-num">3</span> <span class="js-id">subjects</span><span class="js-op">:</span> <span class="js-num">78</span> <span class="js-num">85</span> <span class="js-num">92</span>
<span class="js-op">=====</span> <span class="js-id">REPORT</span> <span class="js-id">CARD</span> <span class="js-op">=====</span>
<span class="js-id">Total</span> <span class="js-op">:</span> <span class="js-num">255</span> <span class="js-op">/</span> <span class="js-num">300</span>
<span class="js-id">Average</span> <span class="js-op">:</span> <span class="js-num">85.00</span>
<span class="js-id">Grade</span> <span class="js-op">:</span> <span class="js-id">B</span></code></pre></div></div></div><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Three functions, one job each, chained like an assembly line: total → average → grade → report. If the grading policy changes next semester, you touch exactly <span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">one function</span>. That's maintainability, and it's the whole point.</p><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">(Suggested image: the assembly-line diagram — total → calculateAverage → assignGrade → printReport as connected stations)</em></p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">Naming and Design Conventions Professionals Use</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Naming:</span></p><ul class="list-inside list-disc whitespace-normal [li_&]:pl-6" data-streamdown="unordered-list" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); list-style-position: outside; list-style-image: initial; padding-inline-start: 1.375rem; margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Use <span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">verbs or verb phrases</span> — functions <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">do</em> things: <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">calculateTotal</code>, <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">isPrime</code>, <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">printReport</code> ✓ ... <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">number</code>, <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">stuff</code>, <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">myFunc</code> ✗</li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;"><code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">camelCase</code> is the common C convention for functions: <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">getUserInput</code>, <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">findMaximum</code></li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;">Predicates (yes/no functions) read best as questions: <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">isEven()</code>, <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">hasVowel()</code>, <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">canVote()</code> — so <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">if (isEven(n))</code> reads like prose</li></ul><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Design rules worth their weight in gold:</span></p><ol class="list-inside list-decimal whitespace-normal [li_&]:pl-6" data-streamdown="ordered-list" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); list-style-position: outside; list-style-image: initial; padding-inline-start: 1.375rem; margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">One function, one job.</span> If you need "and" to describe what it does ("validates input <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">and</em> saves the file <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">and</em> prints a receipt"), it's three functions wearing a trench coat.</li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Logic in, I/O out.</span> Calculation functions return values; let the caller decide whether to print them. A function that both computes <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">and</em> prints can never be reused somewhere that doesn't want printing.</li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Keep them short.</span> A function longer than a screen is a candidate for splitting.</li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Name honestly.</span> A function called <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">getValue</code> that also deletes files is a bug magnet.</li></ol><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">The Six Common Mistakes When Writing Your Own Functions</h2><ol class="list-inside list-decimal whitespace-normal [li_&]:pl-6" data-streamdown="ordered-list" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); list-style-position: outside; list-style-image: initial; padding-inline-start: 1.375rem; margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Forgetting the prototype</span> when the definition sits below <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">main</code> — the compiler meets the call before the function and complains. Prototype up top, always.</li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Semicolon after the definition header</span> — <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">int add(int a, int b); { ... }</code> → error. Semicolon belongs to prototypes only.</li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Missing return on some path</span> —<div class="my-4 flex w-full flex-col gap-2 rounded-xl bg-sidebar p-2" data-language="c" data-streamdown="code-block" dir="ltr" style="border: medium none currentcolor; margin-top: 0px; margin-bottom: 0px; padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); max-width: 100%; border-radius: 7.5px; margin-block: 1rem; background: 0px 0px; gap: 0px; display: flex; width: 939.375px; flex-direction: column; content-visibility: auto; contain-intrinsic-size: auto 200px;"><div class="language-c" data-language="c" data-streamdown="code-block-body" dir="ltr" style="border: 1px solid rgb(47, 47, 55); padding: 0.625rem 0.75rem; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(24, 25, 27); border-radius: 0.5rem; font-size: 0.8125rem; line-height: 1.6; max-height: 400px;"><div class="code-card position-relative my-2">
<div class="code-card-actions">
<button type="button" class="btn-code-action copy-code-btn" onclick="copyCode(this)" title="Copy Code">
<i class="far fa-copy"></i>
</button>
<a href="/tools/c-compiler" target="_blank" class="btn-code-action run-code-btn" title="Run Online">
<i class="fas fa-play"></i>
</a>
</div>
<pre class="language-c bg-[var(--sdm-bg,inherit)] dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit))] code-box" style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); padding: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text; background-position: 0px 0px; background-color: initial; --sdm-bg: transparent; --sdm-fg: inherit;"><code style="border-width: 0px; border-style: solid; border-color: rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 1em; user-select: text;"><span class="js-id">int</span> <span class="js-id">check</span><span class="js-op">(</span><span class="js-id">int</span> <span class="js-id">n</span><span class="js-op">)</span> <span class="js-op">{</span>
<span class="js-kw">if</span> <span class="js-op">(</span><span class="js-id">n</span> <span class="js-op">></span> <span class="js-num">0</span><span class="js-op">)</span> <span class="js-kw">return</span> <span class="js-num">1</span><span class="js-op">;</span>
<span class="js-cm">// what if n <= 0?? No return — undefined garbage</span>
<span class="js-op">}</span></code></pre></div></div></div>Every path through a non-void function must hit a <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">return</code>.</li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Parameter/type mismatches at the call</span> — passing <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">float</code> where <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">int</code> is expected; the compiler warns <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">if</em> it saw a prototype (reason #2 to always prototype).</li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">Expecting the argument to change</span> — pass by value, always a copy. <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">tryToChange(x)</code> can't touch <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">main</code>'s <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">x</code>. (Pointers — the fix — get their own cluster.)</li><li class="py-1 [&>p]:inline" data-streamdown="list-item" dir="ltr" style="border: 0px solid rgb(47, 47, 55); padding-top: 0px; padding-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); padding-block: 0.125rem;"><span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">The God function</span> — one 300-line function doing everything. If scrolling is required, splitting is required.</li></ol><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">(Suggested image: "6 Mistakes" checklist graphic — consistent with the series)</em></p><hr class="my-6" data-streamdown="horizontal-rule" style="border-top: 1px solid rgb(47, 47, 55); border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: rgb(47, 47, 55); border-bottom-color: rgb(47, 47, 55); border-left-color: rgb(47, 47, 55); margin-top: 0px; margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); height: 0px; margin-block: 1rem 0.75rem; --tw-space-y-reverse: 0; font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);"><h2 class="mt-6 mb-2 font-semibold text-2xl" data-streamdown="heading-2" dir="ltr" style="border-width: 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-color: rgb(47, 47, 55); border-image: initial; margin-top: 22.5px; margin-bottom: 7.5px; padding-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-size: 1.125rem; line-height: 1.35; --tw-space-y-reverse: 0; letter-spacing: -0.105469px; --tw-font-weight: 600; margin-block: 1.25rem 0.75rem; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; background-color: rgb(18, 18, 22);">Final Thoughts</h2><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">Here's what changed today: you stopped being a <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">user</em> of functions and became an <span class="font-semibold" data-streamdown="strong" style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); --tw-font-weight: 600; font-weight: 600;">author</span> of them. The skill isn't memorizing syntax — you already had that — it's the design habit: <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">one job, clear inputs, clear output, honest name</em>. Answer the three questions and the code follows.</p><p dir="ltr" style="border: 0px solid rgb(47, 47, 55); margin-bottom: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); margin-block: 0px 0.75rem; --tw-space-y-reverse: 0; color: rgb(252, 252, 253); font-family: "Inter Variable", sans-serif; font-size: 13px; background-color: rgb(18, 18, 22);">And notice what your programs have become: <code class="rounded bg-muted px-1.5 py-0.5 font-mono text-sm" data-streamdown="inline-code" dir="ltr" style="border-width: 0px; border-color: rgb(47, 47, 55); margin-right: 0px; margin-left: 0px; outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5); font-family: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-feature-settings: normal; font-variation-settings: normal; font-size: 0.8125rem; user-select: text; border-radius: 0.25rem; background-color: rgb(33, 34, 37); padding-inline: 5.625px; padding-block: 1.875px; line-height: 18.75px; padding: 0.1em 0.35em;">main()</code> is now a conductor, not the whole orchestra. Small functions, each testable, each reusable, composing into larger behavior. From this point in the series onward, that structure is simply <em style="border: 0px solid rgb(47, 47, 55); outline-color: oklab(0.51773 0.045283 -0.122431 / 0.5);">how we write programs</em>.</p><div><br></div>
Code Example
#include <stdio.h>
// Function prototype
double calculateCelsius(double fahrenheit);
int main() {
double f = 98.6;
double c = calculateCelsius(f);
printf("%.1f F = %.1f C\
", f, c);
return 0;
}
// Function definition
double calculateCelsius(double fahrenheit) {
return (fahrenheit - 32.0) * (5.0 / 9.0);
}Interview Question & Tips
A: `int`. However, C99 and modern C standards removed implicit `int` and require explicit return types.
Q: What happens if a non-void function reaches the end of its body without a `return` statement?
A: If the caller uses the return value, the behavior is undefined.
Best Practices
This study reference for Creating User-Defined Functions in C With Practical Examples is curated and verified against recognized curriculum benchmarks, peer-reviewed textbooks, and official technical documentation: