<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Moeizx on Medium]]></title>
        <description><![CDATA[Stories by Moeizx on Medium]]></description>
        <link>https://medium.com/@moeizcode?source=rss-7a303501fa40------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FTw1bUAxPkRZ6fewMJIdUQ.jpeg</url>
            <title>Stories by Moeizx on Medium</title>
            <link>https://medium.com/@moeizcode?source=rss-7a303501fa40------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 11:05:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@moeizcode/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[5 Shocking Truths About Arrays I Learned From Harvard’s CS50x]]></title>
            <link>https://medium.com/@moeizcode/5-shocking-truths-about-arrays-i-learned-from-harvards-cs50x-02dfc402e02b?source=rss-7a303501fa40------2</link>
            <guid isPermaLink="false">https://medium.com/p/02dfc402e02b</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[cs50x]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[strings-in-c]]></category>
            <dc:creator><![CDATA[Moeizx]]></dc:creator>
            <pubDate>Sat, 03 Jan 2026 21:36:06 GMT</pubDate>
            <atom:updated>2026-01-03T21:36:06.362Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DbMNmDNUAwf_rJWaHFytmA.jpeg" /></figure><p><strong>1. In C, Strings Are an Illusion</strong></p><p>In many modern languages like Python or JavaScript, a “string” is a built-in, first-class data type. In C, this is not the case. The first shocking truth is that C has no native string data type. What we call a string is merely a convention, a clever illusion built on top of arrays.</p><p>It’s important to note that while CS50 provides a convenient string type for learning, this is actually a typedef, or alias, for a char *—a pointer to a character. The fundamental C declaration is char *s = &quot;HI!&quot;; or char s[] = &quot;HI!&quot;;. A C string is simply an array of characters (char) terminated by a special &quot;null character&quot; (\0), a byte with a value of zero. For example, the string &quot;HI!&quot; is stored in memory as an array of <em>four</em> characters: H, I, !, and the invisible \0.</p><pre>char s[] = &quot;HI!&quot;; // Stored in memory as &#39;H&#39;,&#39;I&#39;,&#39;!&#39;,&#39;\0&#39;</pre><p>This has a critical implication that trips up nearly every new C programmer. The == operator compares the <em>values</em> of the variables. For pointers, like string variables in C, their value <em>is</em> the memory address they point to. It doesn&#39;t follow the pointer to see what&#39;s there. So, if you compare two strings with ==, you&#39;re just comparing their starting memory addresses, which will almost always be different, even if the strings contain the exact same characters. This is a classic &#39;gotcha&#39; that has cost developers countless hours of debugging, and it&#39;s precisely why C requires functions like strcmp to compare string content, character by character.</p><p><strong>2. All of Your Computer’s Memory is Just One Giant Array</strong></p><p>If you only take one mental model away from this article, let it be this one. It single-handedly demystifies some of the most feared topics in programming: imagine your computer’s entire RAM (Random Access Memory) as a single, enormous array of bytes. Every piece of data your program uses — every integer, every character, every variable of any type — is stored somewhere inside this giant array.</p><p>Each byte in this massive sequence has a unique numerical address, just like an array has an index. When you declare a variable, your program is allocated a small section of this giant array to store its data. This perspective demystifies why arrays are so fundamental in C; they are a direct, logical representation of how memory itself is organized.</p><p>Understanding this makes other complex topics click. A “pointer” is no longer abstract; it’s just a variable holding a memory address — the “index” of another piece of data in the giant array. This is why the &amp; operator (the &#39;address-of&#39; operator) is so critical. When you write &amp;my_variable, you are literally asking the computer, &quot;What is the index of this data in our giant memory array?&quot; And a &quot;segmentation fault&quot;? That&#39;s just your program trying to access an index in the memory array that wasn&#39;t assigned to it.</p><p><strong>3. The Humble Null Character (\0) is a Silent Guardian</strong></p><p>We’ve established that a C string is an array of characters ending in \0. But the importance of this single, invisible character cannot be overstated. Since the language doesn&#39;t store the length of a string as part of its data, the null terminator is the <em>only</em> thing that signals where the string ends.</p><p>Consider a function like printf that prints a string to the screen. How does it know when to stop printing? It starts at the first character&#39;s memory address and reads and prints one character at a time, moving to the next byte, until it encounters the \0.</p><p>Without that null character, the function would have no idea where the string’s data ends and the next piece of unrelated memory begins. It would just keep reading and printing bytes from adjacent memory locations, leading to unpredictable bugs, garbled output, or program crashes. This humble, silent guardian is the only thing preventing a simple print statement from running wild through your computer’s memory.</p><pre>printf(&quot;%s\n&quot;, s); // Prints until it hits &#39;\0&#39;</pre><p><strong>4. Command-Line Arguments Are Just an Array of Strings</strong></p><p>Ever wonder how a program like grep or cd receives instructions you type into the terminal? The answer, once again, is a simple and elegant use of arrays. The main function in a C program can be declared with two parameters: int argc and char *argv[].</p><p>These two parameters deliver everything you type on the command line to your program in a neatly organized structure:</p><p>• argc stands for &quot;argument count.&quot; It&#39;s an integer telling you how many words were typed.</p><p>• argv stands for &quot;argument vector.&quot; It&#39;s an array of strings (or char *), where each element is one of the words from the command line.</p><p>Crucially, argv[0] is always the name of the program itself. The actual arguments you provide start at argv[1], argv[2], and so on. If you run ./myprogram hello world, argc will be 3, argv[0] will be ./myprogram, argv[1] will be hello, and argv[2] will be world. This turns user input into a structured array that the program can easily loop through and process, demonstrating the power of arrays for handling program input.</p><pre>int main(int argc, char *argv[])<br>{<br>    // argc = argument count<br>    // argv = array of arguments<br>    printf(&quot;Program name: %s\n&quot;, argv[0]);<br>}</pre><p><strong>5. You Can Build a Classic Cipher by Treating Letters as Numbers</strong></p><p>One of the most compelling examples of array manipulation in CS50 is building a Caesar cipher, an ancient encryption technique that shifts letters in the alphabet. This exercise powerfully demonstrates that since strings are arrays of characters, and characters are just numbers (ASCII values) under the hood, you can perform mathematical operations on text.</p><p>The logic, however, is more nuanced than just adding a number to a letter. To implement it correctly, you must:</p><p>1. Loop through the input string (the char array).</p><p>2. For each character, use a function like isalpha() to check if it&#39;s actually a letter. Punctuation, spaces, and numbers should be left unchanged.</p><p>3. Differentiate between uppercase and lowercase letters to ensure they wrap correctly within their respective alphabets (e.g., ‘Z’ + 1 becomes ‘A’, not ‘a’).</p><p>4. For alphabetic characters, convert the letter to a 0–25 index (e.g., ‘A’ becomes 0, ‘C’ becomes 2), apply the Caesar shift using the formula c_i = (p_i + k) % 26 (where p_i is the original letter&#39;s 0-indexed position, k is the key, and c_i is the new position), and then convert the resulting index back to the corresponding ASCII character.</p><p>This elegant solution is only possible because we can treat a string as an array of numbers.</p><p><strong>Conclusion: From Data Structures to Mental Models</strong></p><p>Learning about arrays in a low-level context like C is about more than just mastering a data structure; it’s about building an accurate mental model of how computers actually manipulate data. The concepts we’ve explored — the “illusion” of strings, memory as one giant array, and the critical role of a single null byte — reveal that the elegant abstractions we use in higher-level languages are built upon these simple, powerful, and sometimes surprising C-style foundations. These are the truths that separate rote coding from deep, architectural understanding.</p><p>What seemingly “simple” concept in programming completely changed the way you think about code?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=02dfc402e02b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>