<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mukul Roy</title>
    <description>The latest articles on DEV Community by Mukul Roy (@mukulroy).</description>
    <link>https://dev.to/mukulroy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3758890%2F51b53858-5965-43ec-ae01-52173c094453.png</url>
      <title>DEV Community: Mukul Roy</title>
      <link>https://dev.to/mukulroy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mukulroy"/>
    <language>en</language>
    <item>
      <title>🚀 C Challenge: Spot the Memory Leak! 🧠</title>
      <dc:creator>Mukul Roy</dc:creator>
      <pubDate>Mon, 09 Feb 2026 03:21:35 +0000</pubDate>
      <link>https://dev.to/mukulroy/c-challenge-spot-the-memory-leak-2aoa</link>
      <guid>https://dev.to/mukulroy/c-challenge-spot-the-memory-leak-2aoa</guid>
      <description>&lt;p&gt;Hello Devs! Time for another round of debugging. This time, we are diving into Dynamic Memory Allocation.&lt;/p&gt;

&lt;p&gt;Look at the code below. It’s a simple function that creates a copy of a string. But wait... there's a serious problem here.&lt;br&gt;
The Code:&lt;br&gt;
C&lt;/p&gt;

&lt;h1&gt;
  
  
  include 
&lt;/h1&gt;

&lt;h1&gt;
  
  
  include 
&lt;/h1&gt;

&lt;h1&gt;
  
  
  include 
&lt;/h1&gt;

&lt;p&gt;char* get_string_copy(char *str) {&lt;br&gt;
    char *copy = (char *)malloc(strlen(str) + 1);&lt;br&gt;
    if (copy != NULL) {&lt;br&gt;
        strcpy(copy, str);&lt;br&gt;
    }&lt;br&gt;
    return copy;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;int main() {&lt;br&gt;
    char *my_str = "Game Changer";&lt;br&gt;
    char *new_str = get_string_copy(my_str);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (new_str != NULL) {
    printf("Copy: %s\n", new_str);
}

// Is something missing here?
return 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;The Question:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Does this code have a Memory Leak? If yes, where?

How would you fix it to ensure the memory is properly managed?

What happens if we call get_string_copy inside a loop 1 million times without fixing the issue?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let's see who can provide the cleanest fix! 🔎&lt;/p&gt;

</description>
      <category>c</category>
      <category>programming</category>
      <category>memorymanagement</category>
      <category>cpp</category>
    </item>
    <item>
      <title>🚀 C Challenge: Can you find the bug in this Pointer Logic? 🧠</title>
      <dc:creator>Mukul Roy</dc:creator>
      <pubDate>Sat, 07 Feb 2026 18:14:39 +0000</pubDate>
      <link>https://dev.to/mukulroy/c-challenge-can-you-find-the-bug-in-this-pointer-logic-2j23</link>
      <guid>https://dev.to/mukulroy/c-challenge-can-you-find-the-bug-in-this-pointer-logic-2j23</guid>
      <description>&lt;p&gt;Hello C Developers! 👋&lt;/p&gt;

&lt;p&gt;Let's test our debugging skills today. I’ve written a small piece of code that is supposed to swap two strings using pointers. However, it's not behaving as expected for everyone, or is it?&lt;br&gt;
The Code:&lt;/p&gt;

&lt;h1&gt;
  
  
  include 
&lt;/h1&gt;

&lt;p&gt;// Function to swap two string pointers&lt;br&gt;
void swap_strings(char **str1, char **str2) {&lt;br&gt;
    char *temp = *str1;&lt;br&gt;
    *str1 = *str2;&lt;br&gt;
    *str2 = temp;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;int main() {&lt;br&gt;
    char *p1 = "Game";&lt;br&gt;
    char *p2 = "Changer";&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;printf("Before Swap: p1 = %s, p2 = %s\n", p1, p2);

// Attempting to swap
swap_strings(&amp;amp;p1, &amp;amp;p2);

printf("After Swap: p1 = %s, p2 = %s\n", p1, p2);

return 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;The Challenge:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Memory Safety: Does this code lead to a Segmentation Fault?

Pointer Logic: Are we swapping the actual content or just the memory addresses?

Best Practice: Why is using char *p = "String" considered risky compared to char p[] = "String" in this context?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I’ve seen many beginners struggle with pointer-to-pointer logic and String Literals. Let's discuss in the comments! 🔎&lt;/p&gt;

&lt;h1&gt;
  
  
  c #programming #debugging #challenge #learning
&lt;/h1&gt;

</description>
      <category>c</category>
      <category>programming</category>
      <category>challenge</category>
      <category>devchallenge</category>
    </item>
  </channel>
</rss>
