<?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 Vishal Chavda on Medium]]></title>
        <description><![CDATA[Stories by Vishal Chavda on Medium]]></description>
        <link>https://medium.com/@itsvishalchavda?source=rss-f941cb3cbbf9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*T45ayCkKRYTAH3waT9vksg.jpeg</url>
            <title>Stories by Vishal Chavda on Medium</title>
            <link>https://medium.com/@itsvishalchavda?source=rss-f941cb3cbbf9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 17:30:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@itsvishalchavda/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[Stop Seeking the Destination: Let Life Approximate]]></title>
            <link>https://medium.com/@itsvishalchavda/stop-seeking-the-destination-let-life-approximate-3031fac525cd?source=rss-f941cb3cbbf9------2</link>
            <guid isPermaLink="false">https://medium.com/p/3031fac525cd</guid>
            <category><![CDATA[goal-setting]]></category>
            <category><![CDATA[do-something]]></category>
            <category><![CDATA[goals]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[philosophy-of-mind]]></category>
            <dc:creator><![CDATA[Vishal Chavda]]></dc:creator>
            <pubDate>Tue, 19 May 2026 04:16:24 GMT</pubDate>
            <atom:updated>2026-05-21T14:00:41.490Z</atom:updated>
            <content:encoded><![CDATA[<p>have you been constantly seeking for the goal of life ? Confused and unable to decide between passion and survival? well, you are not alone this is the case with most of the peoples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5dqskJWPCJef7ky1efYICw.png" /></figure><p>You see, many people appear settled because their paths are clearly defined. They found their goals through their social environment and they follows the established system. That is why they seem more stable. You, on the other hand, are still seeking — perhaps because you are interested in many things. You might be a “Jack of all trades.” let’s me give you example of system following people.</p><p><strong>The System vs. The Seeker</strong></p><p>Those who follow the system clearly want a stable and predictable life. They choose traditional paths: earning degrees, obtaining certifications, becoming an expert in a specific field, and climbing the corporate ladder. In the end, their goals are straightforward — following social norms, building wealth, and passing it to their children than die happily.</p><p>but for few, life is confusing, because they ask the questions of existence. why we exist, why life exist, what is the purpose and meaning of life. what should I do with my life. well you never know like the great philosopher of past. like Socrates said, “I know that I know nothing.” but one thing I learn is this</p><p><strong><em>Take care of the moments, and the moments will take care of the hours.</em></strong></p><p><strong>the Big Picture</strong></p><p>we can not see the big pictures. our brain is unable to see it. it lives in the moments and constantly switching between contexts. it start feeling what current context tell it. that feeling is the consciousness. one moments it feels like path is clear and the next, confusion returns with uncertainty.</p><p>there are two things at play <strong><em>Survival Goals</em></strong> and <strong><em>Creative Goals</em></strong>. we want to be creative but we have to follow the system (Survival Goals) for survivals. to escape this dilemma don&#39;t try to find the link between them. don&#39;t try to merge them or don&#39;t try at all. let follow the one principle and that is</p><p><strong>Do Something</strong></p><p>Instead of letting confusion and frustration lead you to waste time on social media or mindless entertainment, simply <strong>do something</strong>. I learn this principle in the first book of Mark Manson. it is very effective. so, do something that you feel to do at the moments. regardless of it is creative or survival activity.</p><p>Do something, feel the moments, feel the air you breathe and the wind. feel your existence — everyday, that is your life&#39;s goal. and the life will eventually approximate and you will start seeing the big picture. current problem is you allow uncertainty to waste your time.</p><p><strong>that&#39;s it !!!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3031fac525cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How a 20-hour stress test and a few Linux kernel ‘quirks’ saved a decade-old drive (HDD) from a…]]></title>
            <link>https://medium.com/@itsvishalchavda/how-a-20-hour-stress-test-and-a-few-linux-kernel-quirks-saved-a-decade-old-drive-hdd-from-a-cb3ae1b3f070?source=rss-f941cb3cbbf9------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb3ae1b3f070</guid>
            <category><![CDATA[ssd]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[badblocks]]></category>
            <category><![CDATA[hdd]]></category>
            <category><![CDATA[rsync]]></category>
            <dc:creator><![CDATA[Vishal Chavda]]></dc:creator>
            <pubDate>Mon, 11 May 2026 14:50:22 GMT</pubDate>
            <atom:updated>2026-05-11T15:07:25.147Z</atom:updated>
            <content:encoded><![CDATA[<h3>How a 20-hour stress test and a few Linux kernel ‘quirks’ saved a decade-old drive (HDD) from a catastrophic failure.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H5wPycOWFWilbznZQNNTow.jpeg" /></figure><p>In the world of hardware, we often assume that <strong>low mileage</strong> equals <strong>high reliability</strong>. I recently found a 10-year-old 1TB Seagate portable drive that had spent most of its life in a drawer. It had less than 130 power-on hours. On paper, it was “new.” In reality, it was a ticking time bomb.</p><p>Here is the technical journey of how I diagnosed, stress-tested, and ultimately “certified” this drive using Linux (LMDE), and why you should do the same before trusting old hardware with your life’s work.</p><p>⚠️ <strong>WARNING:</strong> This process includes a destructive stress test (badblocks -w). Following the steps in this article <strong>WILL PERMANENTLY ERASE ALL DATA</strong> on the target drive. Do not proceed unless you have a backup of any existing files.</p><h4>The “Critical I/O Error” Panic:</h4><p>It started with a simple task: cleaning up an old drive. But as soon as I tried to delete a few files, I got the message: <strong>“Critical I/O Error.”</strong> The disk didn’t just stop working; it caused the file manager to hang. This is the hallmark of a physical hardware struggle. The operating system was waiting for a response from a sector that the drive simply couldn’t read.</p><h4>When the Tools Lie (and how to fix it):</h4><p>I immediately reached for the standard SMART diagnostic tools:</p><pre>sudo smartctl -a /dev/sdc</pre><p>but they failed to return any data. The USB-to-SATA bridge inside the Seagate enclosure was “masking” the hardware details, preventing the system from seeing the actual health of the platters.</p><p>To see the truth, I had to use a <strong>Kernel “Quirk”</strong>. By forcing Linux to use the older usb-storage driver instead of the high-speed uas driver, I bypassed the communication wall.</p><pre># Identify your device ID with lsusb (mine was 0da2:ab27)<br>sudo modprobe -r uas<br>sudo modprobe usb-storage quirks=0da2:ab27:u</pre><h4>The Diagnosis (10 Pending Sectors):</h4><p>With the quirk active, I tried smartctl again. In the output, I looked for <strong>ID 197 (Current_Pending_Sector)</strong>. There it was: <strong>10</strong>.</p><p>A “Pending Sector” is a “maybe” failure. The drive knows those 10 spots are unstable but hasn’t officially retired them yet. It’s waiting for a <strong>Write</strong> operation to decide if it should “heal” them or swap them for spare sectors (Reallocation).</p><h4>SMART Test vs. Stress Test:</h4><p>the above command is smart test but there is a massive difference between <strong>checking</strong> a drive and <strong>testing</strong> it.</p><ul><li><strong>SMART Test:</strong> This is like a doctor asking a patient, “Do you feel okay?” It relies on the drive’s own internal firmware.</li><li><strong>Stress Test (</strong><strong>badblocks):</strong> This is like a treadmill stress test. It forces the drive to write and read back 4 different patterns (0xaa, 0x55, 0xff, 0x00) across every single bit of its surface. # WARNING: This wipes all data!</li></ul><p><strong>Why the Stress Test is Mandatory:</strong></p><p>Writing to the drive forces the firmware to make a decision. It must either successfully write to those “Pending” sectors or admit they are broken and <strong>reallocate</strong> them to a “spare area.”</p><h4>The 20-Hour Stress Test:</h4><p>A SMART check is a report; badblocks is an exam. I ran a four-pass write/read test to force the drive to deal with those 10 sectors.</p><p><strong>The Marathon Command:</strong></p><pre># WARNING: This wipes all data!<br>sudo badblocks -wsv /dev/sdc</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aSTm6k7FT1s9ghK9PhUs8A.jpeg" /></figure><p>As you can see in the photo, this took over <strong>20 hours</strong>. But the result was worth it: <strong>0 bad blocks found.</strong> The intensive writing fixed the “logical” corruption in those 10 sectors.</p><p><strong>Why 20 hours?</strong> Writing to the drive forces the internal firmware to make a choice: either fix the bad sectors or officially “retire” them (Reallocation). If the drive survived this, it could survive anything.</p><h4>The Final Verification:</h4><p>After the test, I verified the fix by running the health check one last time:</p><pre>sudo smartctl -A /dev/sdc | grep -E &quot;Reallocated_Sector|Pending_Sector&quot;</pre><p><strong>Results:</strong> Pending Sectors dropped to <strong>0</strong>. The drive was stable. This drive is now <strong>“Certified Reliable”</strong> for secondary storage. It survived 10 years of sitting and 20 hours of torture.</p><h4><strong>The “Perfect” Backup with Rsync:</strong></h4><p>With the hardware certified, I created a fresh file system and began the long process of moving 500GB+ of data. I avoided “Copy-Paste” because it’s fragile. Instead, I used rsync.</p><pre>rsync -ahvP /source/folder/ /media/vishal/SeagateBackup/</pre><p>The -P flag is the lifesaver here. If that 10-year-old motor had disconnected at 90%, rsync would have picked up exactly where it left off once reconnected.</p><h4>Why “Defragmenting” Isn’t a Health Test</h4><p>I often hear Windows users say they’ll “just defrag the drive” to fix it. <strong>This is a dangerous myth.</strong> Defragmenting only rearranges files; it doesn’t test the physical integrity of the magnetic platters. In fact, if a drive is failing, the heavy movement of a defrag can actually finish it off.</p><p>On Windows, use chkdsk /f /r or professional tools. On Linux, badblocks is your best friend.</p><p>⚠️ <strong>Note for Windows Users:</strong> Running chkdsk /f /r on a physically failing drive is high-stress. It forces the mechanical arm to scan every sector to attempt a repair. If your drive is already clicking or heavily failing, <strong>backup your most critical files first</strong> before running this command, as the stress of the scan could be its &quot;final mission.&quot;</p><h4>Summary</h4><ol><li><strong>Don’t trust age:</strong> 10 years is 10 years, regardless of usage.</li><li><strong>SMART first, Stress later:</strong> Use smartctl -a to find the problem, Use badblocks -w for any drive you didn&#39;t buy yesterday.</li><li><strong>Monitor Heat:</strong> During my test, the drive hit 49°C. Keep it on a hard surface with airflow.</li><li><strong>Backup Rule:</strong> One backup is zero backups. Always have your data in three places.</li><li><strong>Use Rsync:</strong> Don’t gamble with “Copy-Paste” for large archives.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb3ae1b3f070" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Structure Packing in C/C++]]></title>
            <link>https://medium.com/@itsvishalchavda/what-is-structure-packing-in-c-c-c9968439f9db?source=rss-f941cb3cbbf9------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9968439f9db</guid>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[systems-programming]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[cplusplus]]></category>
            <dc:creator><![CDATA[Vishal Chavda]]></dc:creator>
            <pubDate>Fri, 06 Mar 2026 15:54:00 GMT</pubDate>
            <atom:updated>2026-03-06T16:15:10.692Z</atom:updated>
            <content:encoded><![CDATA[<p>During one of my win32 project, I was saving(dumping) struct data directly to a binary file. Everything was working perfectly. Then, I switched my project configuration from <strong>x86 to x64</strong> and recompiled it. Suddenly, the software couldn’t read the old saved file anymore. Now, that was expected but what I <a href="https://stackoverflow.com/questions/4306186/structure-padding-and-packing"><strong>learned</strong></a> that day was how <strong>volatile</strong> this really is. I realized that even a simple compiler update, changing a optimization flag, or switching between MSVC and GCC can trigger a change in the memory layout. We might think our data is safe, but without explicit structure packing, our data’s physical layout is determined entirely by the compiler’s internal defaults, which provides no guarantee of cross-platform or cross-version compatibility.</p><h4>So, What Actually happens Under the Hood ?</h4><p>For the compiler, a struct isn&#39;t just a list of variables. It’s an object that needs to be optimized for the CPU. Most modern processors prefer to read data from memory addresses that are multiples of the data size. This is called <strong>alignment</strong>. consider the following structure</p><pre>struct MyData <br>{<br>    char a;    // 1 byte<br>    int b;     // 4 bytes<br>};</pre><p>Here we have a char (1 byte) followed by an int (4 bytes), the compiler won&#39;t just place them at byte 0 and byte 1. It will insert <strong>3 bytes</strong> of padding after the char so the int starts at address 4. So, here total structure size will be 1 (char) + 3 (padding) + 4 (int) = 8 bytes. This makes the code faster, but it adds invisible bytes that mess up our binary file structure.</p><p>When we switch compilers or even just change compiler settings (like shifting to x64 from x86), those padding rules can shift, and suddenly our binary file is unreadable.</p><h4>Structure Packing: How to ?</h4><p>If we want to ensure that our structure matches a file format exactly, we need to <strong>pack</strong> it. This tells the compiler, “Do not add extra padding, just put the bytes exactly where I told you to put”</p><p><strong>How to do it ?</strong></p><p>well, it depends on compiler, below is example for both Microsoft C/C++ compiler and for GCC:</p><p><strong>For Visual Studio (MSVC), GCC, and Clang:</strong></p><pre>#pragma pack(push, 1) // Switch to 1-byte alignment (No padding)<br>struct MyData <br>{<br>    char a;<br>    int b;<br>};<br>#pragma pack(pop)     // Restore original settings</pre><p><strong>For GCC (Native way):</strong></p><pre>struct MyData <br>{<br>    char a;<br>    int b;<br>} __attribute__((packed));</pre><p><strong>Note:-</strong> #pragma pack is actually supported by <strong>both</strong> MSVC and modern GCC/Clang. While __attribute__((packed)) is the &quot;native&quot; GCC way, using the #pragma version often makes your code more portable across different compilers without using #ifdef blocks.</p><h4>Why Every C Programmer Should Care ?</h4><p>If you are writing to binary files, network packets, or communication buffers, <strong>packing is mandatory</strong>. Without it, you are effectively letting the compiler decide the layout of your file format, which makes it impossible to guarantee compatibility between different versions, architectures, or OS environments.</p><p><strong>The Embedded Perspective</strong></p><p>If you are working in Embedded C, this is even more critical:</p><ul><li><strong>Memory Constraints:</strong> You are often working with tight RAM limits. If your padding is wasting 20% of your struct size, that adds up.</li><li><strong>Hardware Registers:</strong> When mapping a struct to a memory-mapped I/O (MMIO) register, every bit must align perfectly with the hardware. A single padding byte means you are writing to the wrong register.</li><li><strong>Performance Trade-off:</strong> Be careful. Packing can lead to <strong>unaligned access</strong>. On some ARM or RISC architectures, this can cause hardware exceptions (crashes) or significantly slower execution.</li></ul><h4>The Alternative: Serialization</h4><p>Instead of dumping memory directly, you can write bytes one by one. This is called <strong>Serialization</strong>. You write the 1 byte for char a, then the 4 bytes for int b in a specific <strong>Endianness</strong>. This ignores the compiler’s internal layout entirely, ensuring the file remains consistent across any environment.</p><h3>Conclusion</h3><p>So, structure packing isn’t just a compiler trick but it is about taking back control of your data. When you dump a struct directly to a file or a network socket, you&#39;re basically trusting the compiler to keep memory layout of your structure consistent forever. but that can change the moment you update your tools or switch architectures.</p><p>Whether you choose to use #pragma pack for a tight memory layout or do manual serialization to keep things portable, understanding your data’s memory layout is what saves you from the hours of debugging. Keep an eye on those hidden bytes, and they won’t come back to haunt your binary files</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9968439f9db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Calling Convention in C/C++ programming languages ?]]></title>
            <link>https://medium.com/@itsvishalchavda/what-is-calling-convention-in-c-programming-language-f3935a08899f?source=rss-f941cb3cbbf9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3935a08899f</guid>
            <category><![CDATA[calling-conventions]]></category>
            <category><![CDATA[win32]]></category>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[device-drivers]]></category>
            <dc:creator><![CDATA[Vishal Chavda]]></dc:creator>
            <pubDate>Sun, 01 Mar 2026 10:56:27 GMT</pubDate>
            <atom:updated>2026-03-01T11:15:11.122Z</atom:updated>
            <content:encoded><![CDATA[<p>In C programming when function calls another function they follows a set of rules like how arguments are passed, from left-to-right or right-to-left and who will clear the stack, this agreement is called the Calling Convention.</p><p>If you have done native windows programming using Win32 API, than you may have already know that win32 API uses __stdcall <strong>(Standard Call)</strong> rather than Classic __cdecl <strong>(C Declaration)</strong>. look at the image below. it is the default code generated by visual studio when you create win32 GUI app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rz5z5C1vx_nqIkvO2uGeVw.png" /></figure><p>Look at the strange definition of wWinMain function. we are not interested in the arguments but the function type. it has the type of int with extra <strong>decoration </strong>(<strong>Annotation</strong>) APIENTRY. what is it ? well it is a macro which will expand to __stdcall . Finally the definition will looks like this,</p><pre>int __stdcall wWinMain(<br>    struct HINSTANCE__* hInstance, <br>    struct HINSTANCE__* hPrevInstance, <br>    wchar_t* lpCmdLine, <br>    int nShowCmd)<br>{<br>// function code<br>// ...<br>// function code<br>}</pre><p>This __stdcall is a <strong>compiler-specific modifier</strong> which tells the compiler that this function follows the <strong>Standard Call</strong> calling convention.</p><p>By default, your functions always follow the <strong>classic </strong><strong>__cdecl (C Declaration)</strong> convention if you don&#39;t explicitly provide a modifier during the function <strong>declaration</strong> or <strong>definition.</strong></p><p>so, now we have clear understanding of what is calling convention and how to use it, now lets explore them<strong>.</strong></p><h4>1. __cdecl: The Standard Convention</h4><p>The __cdecl (C Declaration) convention is the default for most C and C++ compilers. as I said earlier this is the default convention so we never needed to provide this modifier during functions declaration or definition. here the <strong>caller (the function which calls the other function) </strong>is responsible for cleaning the stack after the <strong>callee(the function which has been called)</strong> returns. so because the <strong>caller</strong> knows exactly how many arguments it has pushed to stack, it can clear all the arguments from the stack after the <strong>function(calee)</strong> returns. so this convention is the only one that supports functions with a variable number of arguments, like printf.</p><p>similarly, arguments are passed strictly on the <strong>stack</strong>, not in the registers. Furthermore, the arguments are pushed on the stack from<strong> right-to-left</strong>. This means the the last argument listed in the function definition is pushed first, and the first argument is pushed last, that means it <strong>(the first argument)</strong> is at the top of the stack before the function call instruction is executed.</p><h4>2. __stdcall: The Windows API Convention</h4><p>The __stdcall (Standard Call) convention is primarily used for calling functions within the Windows API. Unlike __cdecl, the <strong>callee (the function itself) cleans the stack</strong> before returning to the <strong>caller</strong>.</p><p>here, arguments are pushed on the stack from<strong> right-to-left</strong> same as __cdecl . However, The <strong>callee</strong> is responsible for removing the arguments from the stack usually by utilizing the ret X instruction, where X is the number of bytes to clear.</p><p>Because the <strong>callee</strong> must know exactly how many bytes to remove from the stack, __stdcall cannot support<strong> </strong>the functions with a variable number of arguments like printf.</p><h4>3. __fastcall: The Performance Convention</h4><p>this, the__fastcall convention is designed to increase performance. by placing first few arguments on <strong>CPU Registers</strong> it can reduce the number of memory accesses and so increasing performance by speeding up function calls. the remaining arguments are pushed on the stack from<strong> right-to-left</strong> same as other previous conventions. also like __stdcall, the <strong>callee</strong> is responsible for cleaning the stack.</p><h4><strong>4. __thiscall: The C++ exclusive</strong></h4><p>Used in C++ for calling member functions of the object. it typically passes the this pointer in the ECX register, and the remaining arguments on the stack and like __cdecl, the <strong>caller</strong> is responsible for cleaning the stack.</p><p><strong>A Real-World Scenario: Function Pointers</strong></p><p>this is crucial when calling C++ class member functions via function pointers. Because a member function technically has an invisible first argument (the this pointer), using a standard C function pointer will result in a stack mismatch and an immediate crash.</p><p>I encountered this exact dilemma while calling a C++ class member function via a function pointer. You can find more about the technical details on my <a href="https://stackoverflow.com/questions/61747010/c-calling-member-function-via-pointer-before-constructor-exit">Stack Overflow question</a>, but I recommend looking at my <a href="https://stackoverflow.com/questions/61747010/c-calling-member-function-via-pointer-before-constructor-exit">answer</a> for detail.</p><h4>5. __nakedcall: the kernel/drivers level convention</h4><p>A special convention where the compiler <strong>adds no extra code</strong> to the function. <strong>You are</strong> <strong>responsible for handling the stack manually</strong>. The programmer must write all assembly code for setting up the stack and for the returning, mainly used for writing device drivers or kernel-level code.</p><h4>Conclusion: Why Calling Conventions Matter</h4><p>Knowing about calling conventions is important if you are trying to do low-level stuff like reverse engineering or system-level programming. if the caller and callee don’t agree on how parameter are passed or who cleans the stack, the result is a program crash or corrupted memory.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3935a08899f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Temperature sensor with Arduino Uno]]></title>
            <link>https://medium.com/@itsvishalchavda/temperature-sensor-with-arduino-uno-2f75828c7420?source=rss-f941cb3cbbf9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f75828c7420</guid>
            <category><![CDATA[lm35]]></category>
            <category><![CDATA[temperature-sensor]]></category>
            <category><![CDATA[tmp36]]></category>
            <category><![CDATA[arduino]]></category>
            <dc:creator><![CDATA[Vishal Chavda]]></dc:creator>
            <pubDate>Fri, 09 Jan 2026 13:32:49 GMT</pubDate>
            <atom:updated>2026-01-09T13:32:49.973Z</atom:updated>
            <content:encoded><![CDATA[<p>So, there are many temperature sensor’s available in the market but we are going to use most common type LM35 or TMP36 (analog temperature sensors). there are digital temperature sensors like DHT11 but they require separate library to use it with Arduino like board. the analog temperature sensor outputs a voltage signal that changes linearly with temperature. so it is easy to measure voltage signal and calculate temperature based on it. you can even use volt-meter to find and calculate the current temperature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*PGLR2-sZWtZgS04f6fXWBw.png" /><figcaption>TMP36</figcaption></figure><p><strong>The Pinout</strong></p><p>In the above image TMP36 is shown. the first (Left) terminal is VCC terminal i.e. we are going to connect +5 v from Arduino to here. the last one (third) terminal is GND i.e. we are going to connect ground from Arduino to here. the middle one is the output terminal from where we will read our data. because this is analog output means the output will be between GND to VCC based on the temperature, we will connect this terminal to Arduino&#39;s any analog pin (A0-A5).</p><p><strong>The Working</strong></p><p>The TMP36 will give 10 millivolts (mV) per degree Celsius. that means its output voltage signal indicates the current temperature. so what about zero degree Celsius ? at zero degree Celsius it will give 500 mV (0.5V). that is offset voltage so it can measure negative temperature also.</p><p>Now, that we know it gives 10mV per degree Celsius and 500 mV at zero degree Celsius we can calculate temperate using following formula.</p><p>Temp = (Voltage measured (in mV) — 500 )/ 10</p><p>let’s me explain the above formula. 1. first we measure the sensor output voltage in mV 2. than we substract the offset voltage 500 mV for the 0°C baseline, because we want to calculate positive temperature here. 3. we divide it by 10 mV because the sensor changes by 10mV per degree.</p><p>so now we have clear understanding of its working let’s connect the circuit and code it.</p><p><strong>The Connections</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LBcoW7Us5-kdHO1D1dR2hA.png" /><figcaption>TMP36 with Arduino Uno on Tinkercad simulation</figcaption></figure><p>As you can see in the above image I have also interfaced LCD so we can see the output. the TMP36’s output pin (middle one) is connected to Arduino’s analog pin A0. for LCD’s connection see <a href="https://medium.com/@itsvishalchavda/simple-16x2-lcd-interfacing-with-arduino-uno-76207f8ae2bf">here</a>. let’s see the code</p><pre>#include &lt;LiquidCrystal.h&gt;<br><br>// pins for LCD<br>#define RS 12<br>#define EN 11<br>#define DB4 5<br>#define DB5 4<br>#define DB6 3<br>#define DB7 2<br><br>// define pins for temprature sensor tmp36<br>#define TMP_SENSOR_PIN A0 // here we are using A0<br><br>LiquidCrystal lcd(RS, EN, DB4, DB5, DB6, DB7); // lcd object for LCD<br><br>void setup() <br>{<br>  // initialising lcd<br>  lcd.begin(16, 2); <br>}<br><br>void loop() <br>{ <br>  // lets read output from TMP36 at A0 using analogRead<br>  int reading = analogRead(TMP_SENSOR_PIN); <br>  float miliVolt = reading * 4.88; // converting directly to milivolt<br>  float temp = miliVolt / 10; // converting milivolt to temp, explained below<br><br>  // Move the cursor to first row, first column<br>  lcd.setCursor(0, 0); <br>  lcd.print(&quot;Temperature in C&quot;);<br>  // Move the cursor to second row, first column<br>  lcd.setCursor(0, 1); <br>  lcd.print(temp);<br>  // wait for second<br>  delay(1000);<br>  // than loop again<br>}</pre><p>Here the main part is in the loop. I am not going to explain about LCD interfacing or its code here. you can check it <a href="https://medium.com/@itsvishalchavda/simple-16x2-lcd-interfacing-with-arduino-uno-76207f8ae2bf">here</a> again for that. lets focus on TMP36 part. as you can see in the loop the first line uses the Arduino’s library function analogRead this function uses for reading analog reading (input) from any analog pins from A0 to A5. we have passed TMP_SENSOR_PIN macro as arguments to this function. as it has been already define as A0. Now, this function analogRead returns analog voltage output of temperature sensor and which is depend on the current temperature of environment. now this will be in range 0–5V. so we need to convert this reading value into millivolt that’s why we multiplied it by 4.88. why 4.88 ? can you figure it out ? let you do that, and comment about it in comment section. than we divided millivolt by 10, why ? because the sensor’s sensitivity is 10 mv/degrees Celsius. so to convert millivolt to degrees Celsius we have to divide it by 10. finally we have temperature in Celsius. now can you convert it to Fahrenheit ? I suggest you to try by yourself. Nothing teaches you more than self-try rather than copy-paste.</p><p>So, that&#39;s it, feel free to comment and ask questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f75828c7420" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interfacing Ultrasonic Sensor with Arduino Uno]]></title>
            <link>https://medium.com/@itsvishalchavda/interfacing-ultrasonic-sensor-with-arduino-uno-88501b4c1a05?source=rss-f941cb3cbbf9------2</link>
            <guid isPermaLink="false">https://medium.com/p/88501b4c1a05</guid>
            <category><![CDATA[ultrasonic]]></category>
            <category><![CDATA[hc-sr04]]></category>
            <category><![CDATA[arduino]]></category>
            <dc:creator><![CDATA[Vishal Chavda]]></dc:creator>
            <pubDate>Tue, 18 Nov 2025 12:38:00 GMT</pubDate>
            <atom:updated>2025-11-18T12:38:00.100Z</atom:updated>
            <content:encoded><![CDATA[<p>In this quick tutorial, I am going to demonstrate how to interface Ultrasonic distance sensor with Arduino Uno. of course the same method is applicable to any other development board with minor changes. the most important thing is fundamental understanding of how to interface Ultrasonic to any development board. so let’s start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*I9tyfzXJaVv8TkGRVeoC9g.png" /><figcaption>Ultrasonic sensor HC-SR04 (Tinkercad)</figcaption></figure><p>The ultrasonic sensor measure distance by sending ultrasonic sound wave. which we human can’t here. the ultrasonic sound than get reflected by objects and the receiver detects echo. by measuring total time from transmission to receiving we can calculate distance by formula.</p><p><strong>distance = (velocity * time) / 2</strong></p><p>Here it is divided by 2 because sound travels to the object and back. we already knows the speed of sound is 0.0343 cm/µs. all we need to find is the total time for sound wave to go forth and travel back. before going into exact event steps to find distance, lets talk about each and every pins of ultrasonic sensor.</p><p>the sensor has four pins.</p><ol><li>VCC: for +5v D.C power supply</li><li>GND: for ground (negative supply)</li><li>TRIG: by making this pin HIGH for 10 µs Arduino tells the sensor to send ultrasonic sound wave.</li><li>ECHO: this pins becomes HIGH when start receiving sound wave back. by measuring time during which this pin stays high we can find that time as total time for transmission and receiving.</li></ol><p>so here is the entire sequence.</p><ol><li>Arduino sets TRIG HIGH for 10 µs.</li><li>Sensor emits 8 cycles of 40 kHz ultrasonic sound.</li><li>Sound travels through air, hits an object, and reflects back.</li><li>Receiver detects the echo and sets ECHO pin HIGH for the duration of the round trip.</li><li>Arduino measures the HIGH pulse width on ECHO.</li><li><strong>distance = (0.0343 * time) / 2<br></strong>0.0343 cm/µs = speed of sound in air.<br>Divide by 2 because sound travels to the object and back</li></ol><p><strong>Lets do the connection:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*E9iOVNre7j3uIZmGWdxn3g.png" /><figcaption>Interfacing Ultrasonic sensor with Arduino on Tinkercad</figcaption></figure><p>The circuit connection is simple. Provided VCC to ultrasonic via Arduino&#39;s 5V pin and Arduino’s GND to Ultrasonic’s GND. now for trigger pin we have used Arduino&#39;s digital pin 2 and the same way the pin 3 for the echo pin of sensor.</p><p><strong>The Arduino Uno Code:</strong></p><pre>// Define pins<br>#define TRIG_PIN 2   // Trigger pin connected to Arduino pin 2<br>#define ECHO_PIN 3   // Echo pin connected to Arduino pin 3<br><br>void setup() <br>{<br>  <br>  // Initialize serial communication<br>  Serial.begin(9600);<br><br>  // Set pin modes<br>  pinMode(TRIG_PIN, OUTPUT);<br>  pinMode(ECHO_PIN, INPUT);<br>}<br><br>void loop()<br>{<br>  // Clear the trigger pin<br>  digitalWrite(TRIG_PIN, LOW);<br>  delayMicroseconds(2);<br><br>  // Send a 10µs HIGH pulse to trigger the sensor<br>  digitalWrite(TRIG_PIN, HIGH);<br>  delayMicroseconds(10);<br>  digitalWrite(TRIG_PIN, LOW);<br><br>  // Read the echo pin: <br>  //pulseIn function will measures the time in microseconds<br>  int duration = pulseIn(ECHO_PIN, HIGH);<br><br>  // Calculate distance in cm using the formula<br>  <br>  int distance = (duration * 0.0343) / 2;<br><br>  Serial.print(&quot;Distance: &quot;);<br>  Serial.print(distance);<br>  Serial.println(&quot; cm&quot;);<br><br>  <br>  delay(500);<br>}</pre><p>The code is mostly self explanatory. before making trigger high for 10 microsecond we have to make it low for 2 microsecond to clear it out. than because of 10 µs pulse the sensor will emit ultrasonic sound wave. which than by detected using echo pin. we measure time for the entire event by using function call pulseIn this function returns the total time for echo pin to stay high. the time will be in microseconds. so finally we have used above distance measuring formula. this formula gives us distance in centimeter.</p><p>so that’s it, feel free to ask questions in comment section, also you can visit this simulated circuit <a href="https://www.tinkercad.com/things/6pXwT9pQRcG-ultrasonic">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88501b4c1a05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple 16x2 LCD interfacing with Arduino Uno]]></title>
            <link>https://medium.com/@itsvishalchavda/simple-16x2-lcd-interfacing-with-arduino-uno-76207f8ae2bf?source=rss-f941cb3cbbf9------2</link>
            <guid isPermaLink="false">https://medium.com/p/76207f8ae2bf</guid>
            <category><![CDATA[lcd]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[arduino]]></category>
            <dc:creator><![CDATA[Vishal Chavda]]></dc:creator>
            <pubDate>Tue, 18 Nov 2025 12:32:27 GMT</pubDate>
            <atom:updated>2025-11-18T12:32:27.375Z</atom:updated>
            <content:encoded><![CDATA[<p>In this quick tutorial, I am going to demonstrate how to interface LCD with Arduino Uno. of course the same method is applicable to any other development board with minor changes. the most important thing is fundamental understanding of how to interface LCD to any development board. so let’s start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*RbMwdriUO56EIcGv2a2IMg.png" /><figcaption>16x2 LCD module (tinkercad)</figcaption></figure><p>As you can see in the above image there are 16 number of pins available to 16x2 LCD display. lets look a deep look.</p><ol><li><strong>GND : </strong><br>this is ground pin. which is self-explanatory</li><li><strong>VCC :</strong><br>We connect positive 5 Volt to this Pin.</li><li><strong>VEE :</strong><br>In the above image you can see it as VO. this pin actually use for setting LCD contrast. when you apply 5V on this pin it will have minimum contrast and if you connect it to GND it will have maximum contrast. for our simple demonstration purposes I have connected it to GND directly for maximum contrast. but if you want to get variable contrast than you can connect 4.7 K potentiometer’s viper to this pin. of course the total voltage across this potentiometer should be 5V.</li><li><strong>RS (Register select) : </strong><br>suppose you want to write something on second line on LCD. how do you do that ? so you need someway to tell the LCD that you want to write character at specific location. for that you need to send command to LCD. similarly when you send character, how LCD will decide that it is not command but printing character. so to tell the LCD that data we are sending is command or character to display is decided by the state of this RS (Register select PIN). when RS = 0 (LOW) The LCD interprets the incoming bits as a command (e.g., clear screen, move cursor, set display mode). similarly when RS = 1(high) the LCD interprets that the data are ASCII char to display.<br><strong><em>For Example </em></strong><em>: <br>-&gt; Sending </em><em>0x01 with </em><strong><em>RS = 0</em></strong><em> will Clears the display. And <br>-&gt; Sending </em><em>0x41 (ASCII for &#39;A&#39;) with </em><strong><em>RS = 1</em></strong><em> will Displays the letter </em><strong><em>A</em></strong><em>.</em></li><li><strong>RW (Read/Write) :</strong><br>So as name suggest this PIN will use for direction of data flow. i.e. data from Arduino to LCD or data from LCD to Arduino.<br>for example if we want to write character or text to LCD display than we will make this pin LOW (RW = 0) similarly by making this pin HIGH (RW = 1) we can read data from LCD to Arduino. most of the time we are writing to LCD for this kind of simple requirements we always connect this pin to GND to make it as write only.</li><li><strong>E (Enable PIN) :</strong><br>this pin act like clock/latch signal. in simple words, how LCD know that data is available to data pins (7–14). for that when we write data at data pins(7–14), the Arduino makes this Enable PIN to High than LOW. so this transition from HIGH to LOW makes the LCD to latch the data/command. in simple words the LCD will read data/command available on data pins (7–14), Now we do not need to do this transition (HIGH to LOW) programmatically. because existing LCD library will do the job for us.</li><li><strong>D0-D7 (Data Pins) :</strong><br>this data pins (D0-D7 or 7–14) as name suggest use for data transfer from Arduino to LCD and vice versa. there are two modes of operation when writing characters to LCD, either you can use all 8-pins (8-bit mode) for data transfer or you can use 4-bit mode to transfer data. in 4-bit mode we only need four pins. thus saving number of connections between LCD and Arduino. in this demonstration, we have used 4-bit mode. you can clearly see all the connections in diagram below.</li><li><strong>LED backlight (pins 15–16):<br></strong>this two pins numbered as 15 and 16 also known as LED+ (Backlight Anode) and LED- (Backlight Cathode), these pins are actually backlight LED’s pins. by giving power supply to this pins (VCC -&gt; LED+ and GND -&gt; LED-) LCD will light up and we are able to see the display text more clear and bright. As this pins are actually LED’s pins we need to add extra current limiting resistor like we always use one register to with normal LED. you can see the resistor connection in below picture. Some LCD modules already have an onboard resistor, so LED+ can be connected directly to +5V.</li></ol><p>So that&#39;s all the pins with its functions and use cases. lets now connect the LCD with Arduino. you do it physically if Arduino board available but I suggest to use online simulator like Tinkercad or Wokwi.</p><p><strong>Circuit Connections:<br></strong>Here we have used 4-bit mode. so number of connection can be reduced. as you can see in the following circuit diagram. VCC (red wire) connected to LCD’s pin-2 (VCC pin) and GND (black wire) connected to GND (ground pin) of LCD. also keeping VEE to GND makes full contrast but you can adjust contrast by connecting one potentiometer here.</p><p>than RS pin to Arduino pin 12 and RW to GND for write only functionality. the Enable pin of LCD is connected to pin 11 of Arduino. and all four data pins (D4-D7) are connected to Arduino pins 2–5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6udvyshs3mRYpwQl4SlQRg.png" /><figcaption>16x2 LCD Interfacing with Arduino UNO</figcaption></figure><p><strong>Arduino code:<br></strong>In the following Arduino Uno code as you can see the first line include the LCD library (LiquidCrytal.h). So it provides us simple programming interface to control LCD easily. and we will not need to write all the stuff by ourselves.</p><p>than the code defines LCD pins which are connected to the Arduino pins. for example RS pin of LCD is connected to digital pin 12 of Arduino. and the same way Enable pin is connected to Arduino&#39;s digital pin 11. same for the rest of pins.</p><p>than program creates lcd (LiquidCrytal) object (C++ object) which has been defined in LiquidCrystal.h library. so that we can easily interact with LCD. otherwise we will needed to write everything from scratch. than in setup we are initialising LCD with lcd.begin() if it fails you can use lcd.init() . this is necessary first step to initialise LCD. than we have used lcd.setCursor(0,0). this function tells the LCD to bring cursor at specific location so we can print (write) character at that place. the first arguments to setCursor is column and the second one is row. because it is 16x2 LCD it has 2 rows and 16 columns. you can set cursor to any place. let use this function to set cursor at 5th place on second row. so we need to call lcd.setCursor(4, 1) because the index is zero (0) base. 0 for columns 1 and 0 for row 1, same way, for row 2 its index will be 1 and for column 5 we have index 4.</p><p>So, that’s it, For writing we simply call lcd.print. and it will print all the text you provided in print function at the location set by setCursor.</p><pre><br>#include &lt;LiquidCrystal.h&gt;<br><br>// defining the pins we are using<br>#define RS 12<br>#define EN 11<br>#define DB4 5<br>#define DB5 4<br>#define DB6 3<br>#define DB7 2<br><br>// this creates lcd object of type LiquidCrystal<br>LiquidCrystal lcd(RS, EN, DB4, DB5, DB6, DB7); <br><br>void setup() <br>{<br>  // this tells the lcd object that the LCD is 16x2<br>  lcd.begin(16, 2); <br>  <br>  // setting the cursor at the begining (first row, first column)<br>  lcd.setCursor(0, 0);<br>  <br>  // Print a message to the LCD<br>  lcd.print(&quot;LCD Demo by&quot;);<br>  <br>  lcd.setCursor(0, 1);<br>  <br>  lcd.print(&quot;Vishal Chavda&quot;);<br><br>}<br><br>void loop() <br>{<br>  // Move the cursor to the desire position<br>  lcd.setCursor(14, 1);            <br>  <br>  // continuesly updating seconds since start or reset<br>  lcd.print(millis() / 1000);<br>  <br>  // wait for second<br>  delay(1000);<br>  <br>  // than loop again<br>}<br></pre><p>So, that it, feel free to ask questions in comment section.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76207f8ae2bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java string be careful while comparing]]></title>
            <link>https://medium.com/@itsvishalchavda/java-string-be-careful-while-comparing-9ef665bdef07?source=rss-f941cb3cbbf9------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ef665bdef07</guid>
            <category><![CDATA[object-comparison]]></category>
            <category><![CDATA[string]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Vishal Chavda]]></dc:creator>
            <pubDate>Fri, 17 Oct 2025 13:32:58 GMT</pubDate>
            <atom:updated>2025-10-17T13:32:58.145Z</atom:updated>
            <content:encoded><![CDATA[<p>when I was experimenting with java string, I got strange behaviour while comparing two strings. first I compare using == operator than I tried with string.equals method. consider the following code snippet.</p><pre>String str1 = &quot;str&quot;;<br>String str2 = &quot;str&quot;;<br>System.out.println(str1.equals(str2));<br>System.out.println(str1 == str2);<br><br>/*** output ***/<br>// true<br>// true</pre><p>In the above code snippet, both the output will be true.</p><p>Now consider the following code snippet.</p><pre>String str1 = new String(&quot;str&quot;);<br>String str2 = new String(&quot;str&quot;);<br>System.out.println(str1.equals(str2));<br>System.out.println(str1 == str2);<br><br>/*** output ***/<br>// true<br>// false</pre><p>Here in this test the first output will be true and second is false. why not both true like the first code snippet ?</p><p>it turns out because == operator use to compare object reference for non-primitives, not the content of the objects. so in second example it gives false because, str1 and str2 are two different objects. but than why it gives true in the first code snippet. aren’t str1 and str2 different objects ?</p><p>No, because both str1 and str2 points to the same object. because when we create String like String str1 = “str”; (without new keyword). it creates string object in <strong>String Pool</strong> (a special area within the Heap memory). when we create another String str2 = “str”; with the same string literal, it return the same object reference from the String Pool because both has the same string literal (same content). so, Both str1 and str2 points to the same single object reference. that&#39;s why comparing both using == returns the true.</p><p>So, in conclusion, it is always best practice to compare two java String using String.equals rathern than == operator.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ef665bdef07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Amazing Thing you can do with C pointers.]]></title>
            <link>https://medium.com/@itsvishalchavda/the-amazing-thing-you-can-do-with-c-pointers-27de8d1823e5?source=rss-f941cb3cbbf9------2</link>
            <guid isPermaLink="false">https://medium.com/p/27de8d1823e5</guid>
            <category><![CDATA[pointers]]></category>
            <category><![CDATA[pointers-in-c]]></category>
            <category><![CDATA[c-programming]]></category>
            <dc:creator><![CDATA[Vishal Chavda]]></dc:creator>
            <pubDate>Mon, 05 May 2025 06:29:35 GMT</pubDate>
            <atom:updated>2025-05-05T06:29:35.916Z</atom:updated>
            <content:encoded><![CDATA[<p>So, I assume you already know the basic of pointers. now what you can do with it except manipulating single variable? lets see,</p><p><strong>Manipulating variable byte by byte</strong>:</p><p>basically pointer point to the block of memory. and you can manipulate this block of memory as you want. consider following code</p><pre>int a = 5;<br>int* ptr_a = &amp;a;<br>char* charPtr_a = (char*) ptr_a;<br>*charPtr_a = ~(*charPtr_a);<br>charPtr_a++; // increament to next byte</pre><p>Here we have converted integer pointer into char pointer, So now we can manipulate it as char (byte by byte). as in the last statement we have inverted the first byte of integer. after incrementing char pointer variable we can manipulate the second byte of integer variable the way we wish.</p><p>but be careful here. as we need to know the size of int variable before manipulating it. assuming int as 4 byte. than we can change four byte like char array of 4 values.</p><p>The same we can manipulate array of any type with pointers. consider following code.</p><pre>typedef struct<br>{<br> float x;<br> float y;<br>} Point;<br><br>Point points[10] = {0};</pre><p>Here, we have created array of 10 points. we can manipulate it as follow using pointes.</p><pre>for(int i = 0; i &lt; 10; i++)<br>{<br>  points-&gt;x = 0;<br>  points-&gt;y = 0;<br>  points++;<br>}</pre><p>But if we convert the pointer to the points to byte array as follow.</p><pre>unsigned char byte = (unsigned char*)points;</pre><p>now we have converted the block of memory pointed by points to byte array. so we can manipulate this byte array as we want (byte by byte). but of course we need to carefully about memory out of bound exception.</p><p>using this same technique we can zeroing block of memory as follow by using standard library function which operate as byte by byte.</p><pre>memset(byte, 0, 10 * sizeof(Point));</pre><p>Here the memset the standard library function treat the pointer as byte pointer and fills the value zero to each byte.</p><p>I hope this helps you better understanding of pointers and the power it gives to the programmers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27de8d1823e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The C programming — The pointers:]]></title>
            <link>https://medium.com/@itsvishalchavda/the-c-programming-the-pointers-2c4c8fd10ee3?source=rss-f941cb3cbbf9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c4c8fd10ee3</guid>
            <category><![CDATA[pointers]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[pointers-in-c]]></category>
            <dc:creator><![CDATA[Vishal Chavda]]></dc:creator>
            <pubDate>Mon, 05 May 2025 04:43:16 GMT</pubDate>
            <atom:updated>2025-05-05T04:43:59.691Z</atom:updated>
            <content:encoded><![CDATA[<h3>The C programming — The pointers:</h3><p>So, what is pointers? pointers are, in fact, variables just like other variables but they store memory addresses. as you already use char data types for storing single character, int data types for storing integer numbers and so on. similarly, pointer variables store memory addresses of any other variables (<a href="https://stackoverflow.com/questions/15151377/what-exactly-is-a-c-pointer-if-not-a-memory-address">may not be exact memory addresses but for simplicity we stick to that view of pointer</a>). still confused?</p><p>let&#39;s take a different approach. let&#39;s create a single char variable.</p><pre>char mychar = &#39;A&#39;;</pre><p>So, here we told the computer (microprocessor via compiler) that we want to store ASCII character ‘A’ in memory (RAM or CPU registers). and because it stored in memory it has memory address. every memory location has memory address (like a house has address) to access that memory content. so, when we reference our variable by its name (here mychar) compiler knows what we are referencing so, it replaces its name by its memory addresses in machine code because microprocessor don&#39;t understand words but memory addresses(numbers).</p><p>So, can we directly manipulate these memory locations via its addresses? yes that&#39;s why pointer exist for. so, that means we can get memory address of our mychar variable. yes, and here is how we do it.</p><pre>char* ptr_mychar = &amp;mychar;</pre><p>Here, first we created ptr_mychar variable of type char* pointer to the char and initialize it with the address of mychar by using address of operator &amp;. So, now ptr_mychar has the address of mychar So, we can now manipulate mychar indirectly via pointer address as follow.</p><pre>*ptr_mychar = &#39;B&#39;;</pre><p>Here, this time the asterisk (*) is used for dereferencing the memory address. So, the ‘B’ will be stored at memory whose address contain by ptr_mychar. if you are still confused. just remember following things.</p><ol><li>Every variable you declare in C has memory Address.</li><li>we can reference these variables indirectly by using its memory address.</li><li>to get the address of variable, you must need to use address of operator &amp; i.e. &amp;mychar</li><li>to dereference the pointer you need to use dereferencing operator asterisk (*). i.e. *ptr_mychar</li></ol><p>So, Thats it for Pointers. More you practice, more you become the master. and the skill of pointer manipulation is extremely essential for the master of C programming.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c4c8fd10ee3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>