<?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: Gaurav</title>
    <description>The latest articles on DEV Community by Gaurav (@crazysamurai).</description>
    <link>https://dev.to/crazysamurai</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%2F640871%2Fe96e7d5e-b7ac-45fd-a7f8-e5903b3c7505.jpg</url>
      <title>DEV Community: Gaurav</title>
      <link>https://dev.to/crazysamurai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/crazysamurai"/>
    <language>en</language>
    <item>
      <title>Data Structures : Graph Traversal (DFS)</title>
      <dc:creator>Gaurav</dc:creator>
      <pubDate>Thu, 13 Oct 2022 16:37:57 +0000</pubDate>
      <link>https://dev.to/crazysamurai/data-structures-graph-traversal-dfs-m44</link>
      <guid>https://dev.to/crazysamurai/data-structures-graph-traversal-dfs-m44</guid>
      <description>&lt;p&gt;&lt;strong&gt;Depth First Search (DFS)&lt;/strong&gt; is a graph traversal technique which is used to visit the nodes in a graph. &lt;/p&gt;

&lt;p&gt;Start from one node and visit it's adjacent node and then it's adjacent node, keep doing this until you reach the last node and then start backtracking. &lt;br&gt;
While backtracking visit the rest of the adjacent nodes in the same way.&lt;/p&gt;

&lt;p&gt;Let's understand this with an example:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Consider this graph and &lt;strong&gt;Node 1&lt;/strong&gt; as the starting point.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RdknX5pb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9k7m1wj1j54hd8a1ivk2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RdknX5pb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9k7m1wj1j54hd8a1ivk2.png" alt="traversal" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now as we can see node &lt;strong&gt;1&lt;/strong&gt; has two adjacent nodes, &lt;strong&gt;2&lt;/strong&gt; &amp;amp; &lt;strong&gt;3&lt;/strong&gt; and we can visit any one we want. In this example we'll start with &lt;strong&gt;Node 2&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--alwWaIQW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vof6w3lqtycfweq17h3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--alwWaIQW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vof6w3lqtycfweq17h3.png" alt="traversal" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Again node &lt;strong&gt;2&lt;/strong&gt; has two adjacent nodes and we'll pick node &lt;strong&gt;5&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N1yZfM45--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ttgm3lgluorb69n1paww.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N1yZfM45--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ttgm3lgluorb69n1paww.png" alt="traversal" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This is an important part of the algorithm because there are no adjacent nodes for &lt;strong&gt;5&lt;/strong&gt; which means we can't move forward. At this point we start backtracking and move back to node &lt;strong&gt;2&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SKNXu1cf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hgwhxdp971ju76pk0e5x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SKNXu1cf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hgwhxdp971ju76pk0e5x.png" alt="traversal" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We notice that node &lt;strong&gt;2&lt;/strong&gt; has another node which we didn't visit yet so we'll do just that, we'll visit &lt;strong&gt;Node 6&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Again node &lt;strong&gt;6&lt;/strong&gt; doesn't have any adjacent node so we'll backtrack to node &lt;strong&gt;2&lt;/strong&gt; and since we have visited all the adjacent nodes of &lt;strong&gt;2&lt;/strong&gt; we'll backtrack to node &lt;strong&gt;1&lt;/strong&gt;. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lS2Cu8aB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q3yojy0sk0ugg8uatu4b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lS2Cu8aB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q3yojy0sk0ugg8uatu4b.png" alt="traversal" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using the same steps we'll visit all the remaining nodes i.e. &lt;strong&gt;3, 4, 8 &amp;amp; 7&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now you might ask that there is an edge between node &lt;strong&gt;7&lt;/strong&gt; and &lt;strong&gt;3&lt;/strong&gt; so do we visit it again? The answer is No because we've already visited node &lt;strong&gt;3&lt;/strong&gt; on our way to node &lt;strong&gt;7&lt;/strong&gt; and the same logic applies when we backtrack to node 3. We'll see how this is taken care of in the code.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x5Hc9SfX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/en2jphrbu503ntp905ka.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x5Hc9SfX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/en2jphrbu503ntp905ka.png" alt="traversal" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So we've visited all the nodes in the graph and the path is {1, 2, 5, 6, 3, 4, 8, 7}.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now it's time to code it up but before that I should explain the situation with already visited nodes. Since we have visited the particular node before we don't have to do that again. Now you might be wondering how do we keep track of which node we have visited and which one we haven't and the simple answer is an Array.&lt;/p&gt;

&lt;p&gt;We simply create an array of length equal to the number of vertices in the graph and fill it with 0 or false depending on the array type you want. Now as we visit a node we simply mark that index in the array as visited by setting it as 1 or true. &lt;/p&gt;

&lt;p&gt;In the next dfs call we will first check if the node we are on is visited or not by simply checking the value at that index in the array. We will look at the code to better understand this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Dxc7I3tO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qih3cb4kovi7l93a8kih.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Dxc7I3tO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qih3cb4kovi7l93a8kih.jpeg" alt="dfs code" width="880" height="746"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Steps to sum up the code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visited array and a list are created.&lt;/li&gt;
&lt;li&gt;Call the dfs on starting node.&lt;/li&gt;
&lt;li&gt;Set vis[node] = true  and list.add(node).&lt;/li&gt;
&lt;li&gt;For each loop on adjacency list and find the adjacent node.&lt;/li&gt;
&lt;li&gt;Check if the adjacent node is visited, if not call dfs on it.&lt;/li&gt;
&lt;li&gt;The path is stored in list.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Space Complexity: O(N) + O(N) + O(N) Adjacency list, Array, Auxiliary space.&lt;/p&gt;

&lt;p&gt;Time Complexity: O(N) + (2*E) Recursion call for each node + Summation of degrees.&lt;/p&gt;

&lt;p&gt;That's it for the DFS traversal. I hope this was helpful.&lt;br&gt;
Thanks for reading.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>java</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Data Structures : Introduction to Graphs</title>
      <dc:creator>Gaurav</dc:creator>
      <pubDate>Mon, 10 Oct 2022 20:56:27 +0000</pubDate>
      <link>https://dev.to/crazysamurai/data-structures-introduction-to-graphs-7ih</link>
      <guid>https://dev.to/crazysamurai/data-structures-introduction-to-graphs-7ih</guid>
      <description>&lt;p&gt;You are probably familiar with arrays, stacks and linked lists which are linear data structures because they store the data in a sequence. Graph is a non-linear data structure just like a tree data structure. In fact tree is a special kind of data structure with some restrictions. &lt;/p&gt;

&lt;p&gt;Graphs have a lot of real world applications like finding the best routes in navigation apps, creating complex electrical circuits, storing useful user information on social media platforms, etc.&lt;/p&gt;

&lt;p&gt;Before moving forward we must know the following terms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Nodes&lt;/strong&gt;: These are the vertices of the graph that are used                 to store the data and are connected by edges.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Edges&lt;/strong&gt;: Two nodes are connected by a horizontal line called an edge. An edge can be directed or undirected. A directed edge means that we can only traverse the graph in one direction which is shown by the edge whereas an undirected edge lets us traverse in any direction.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b6ja-ZXT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x31u09iamj5ib8vo8p1k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b6ja-ZXT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x31u09iamj5ib8vo8p1k.png" alt="nodes and edges" width="856" height="571"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Graphs are of two types:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Undirected graph&lt;/strong&gt;: A type of graph in which the nodes are connected by undirected edges.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Directed graph&lt;/strong&gt;: A type of graph in which the nodes are connected by directed edges.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u1PIekMm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nwges5dx12rpc6z7x60t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u1PIekMm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nwges5dx12rpc6z7x60t.png" alt="types of graphs" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Cycle in a Graph
&lt;/h2&gt;

&lt;p&gt;When we start moving from one node and after a few moves end up back at the starting node, this means that there's a cycle in the graph.&lt;/p&gt;

&lt;p&gt;If there is a cycle in a graph and the edges are undirected then the graph is called &lt;strong&gt;Undirected Cyclic Graph&lt;/strong&gt;.&lt;br&gt;
Similarly if the graph has a cycle but the edges are directed then it's called a &lt;strong&gt;Directed Cyclic Graph&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8fSSVSnk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqecye2pzq3uvl823gb3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8fSSVSnk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqecye2pzq3uvl823gb3.png" alt="cycles" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Degree of a Graph
&lt;/h2&gt;

&lt;p&gt;In case of undirected graphs the number of edges connected to a node is it's degree.&lt;br&gt;
But in Directed graphs:&lt;br&gt;
In-degree: Total number of incoming edges in a node.&lt;br&gt;
Out-degree: Total number of outgoing edges in a node. &lt;/p&gt;

&lt;p&gt;Total degree of a graph = 2 x the number of edges in the graph&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---1rUxd53--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oc2ultd67yiz6ko715mw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---1rUxd53--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oc2ultd67yiz6ko715mw.png" alt="Degree" width="716" height="716"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Weights in a Graph
&lt;/h2&gt;

&lt;p&gt;Weights are used to measure the cost of a traversal in a graph usually represented by edges hence known as weighted edges.&lt;br&gt;
Why do we need them? Well consider this, you have to travel from city A to city B but there are multiple paths that you can use. To make the decision easier we can just calculate the time it'll take for us to reach our destination for each path and then pick the one with lowest time.&lt;/p&gt;

&lt;p&gt;That's about the introduction to graphs but there are a lot of interesting and important topics associated with graphs like representing a graph in a language, traversal algorithms, shortest path algorithms, cycle detection algorithms, topological sort, etc.&lt;/p&gt;

&lt;p&gt;I hope this article was helpful for you.&lt;br&gt;
Thanks for reading.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>How To Increase The Size Of An Array In C ?</title>
      <dc:creator>Gaurav</dc:creator>
      <pubDate>Wed, 11 Aug 2021 08:53:11 +0000</pubDate>
      <link>https://dev.to/crazysamurai/how-to-increase-the-size-of-an-array-in-c-50o0</link>
      <guid>https://dev.to/crazysamurai/how-to-increase-the-size-of-an-array-in-c-50o0</guid>
      <description>&lt;p&gt;To understand this better let's see how you would resize an array in JavaScript with a simple example.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;someArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someArray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;someArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someArray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Which when executed gives this output: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2anjy8nfjlyohs2iz2j5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2anjy8nfjlyohs2iz2j5.png" alt="Output of array"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was a straight forward and easy example of how you would do that in JavaScript but this is not the case with some other languages like C.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So how would you do that in C?&lt;/strong&gt;&lt;br&gt;
I'm glad you asked. But first we need to understand what the problem is or why isn't it this simple in C.&lt;/p&gt;

&lt;p&gt;In C we need to understand that memory for an array is allocated at compile time and not at runtime which means we cannot increase it once the array size is declared in the code.&lt;br&gt;
We know to create an array we need a contiguous memory allocation or in simpler terms the next element in an array must be placed adjacent or after the previous one. After specifying the size of an array we can't determine if the memory location adjacent to the last element in an array is empty or not and hence we can't increase the size of the array.I hope that made sense. Now you might be thinking why were we able to do this in JavaScript, then the simple answer is JavaScript arrays are just objects with special properties. JavaScript is a wired language and I love it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps to get the job done:&lt;/strong&gt;&lt;br&gt;
1.Create an array (lets say p) with n items.&lt;br&gt;
2.Create another array (lets say q) but an empty one which is larger than array p.&lt;br&gt;
3.Now copy the elements of p into q by a simple for loop.&lt;br&gt;
4.Delete the memory held by pointer p using &lt;code&gt;free(p);&lt;/code&gt; so that array p no longer exists.&lt;br&gt;
5.Assign the address of array q in p.&lt;br&gt;
6.Assign q the value NULL so that it can't access array q.&lt;br&gt;
7.And that's it. The array size is now increased.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Please read the code for better understanding.&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;Code&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;

&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
&lt;span class="c1"&gt;//Two pointers for two different arrays&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;//declaring array at pointer p&lt;/span&gt;
    &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;malloc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="k"&gt;sizeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//Printing the elements of p&lt;/span&gt;
    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Array p: &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%d &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;//declaring array at pointer q&lt;/span&gt;
    &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;malloc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="k"&gt;sizeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;&lt;span class="c1"&gt;//assigning elements of p to q&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;free&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;//releasing the memory held by pointer p&lt;/span&gt;

    &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//assigning the address held by q to p for the array&lt;/span&gt;
    &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//removing the address of array from q&lt;/span&gt;

&lt;span class="c1"&gt;//printing the elements of p&lt;/span&gt;
    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Array q converted to p: &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%d &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg9ynmaxd7l33dmwgdieh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg9ynmaxd7l33dmwgdieh.png" alt="output of c"&gt;&lt;/a&gt;&lt;br&gt;
So we can clearly see that the array p in the beginning was of size 5 but after all that code its increased to 7.&lt;br&gt;
&lt;em&gt;The 0 at the end of the array after size increase is added by C automatically if no data is entered at that index.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's understand with this example.&lt;/strong&gt;&lt;br&gt;
Let a guy named P has a car (array 1). But now he has kids due to which he needs a bigger car. He has a  friend named Q who is moving to a different country and wants to sell his car (array 2). P realizes that his friend's car will be just the perfect size for him so he makes his friend Q an offer and buys his car (array2) and Q leaves the country &lt;code&gt;q=NULL;&lt;/code&gt;. Now P has 2 cars and since he doesn't need his old car (array 1) he gets rid of it &lt;code&gt;free(p);&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I hope this was clear and easy to understand. Thanks for your time.&lt;/p&gt;

</description>
      <category>c</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>The This Keyword in JavaScript</title>
      <dc:creator>Gaurav</dc:creator>
      <pubDate>Mon, 09 Aug 2021 06:57:05 +0000</pubDate>
      <link>https://dev.to/crazysamurai/the-this-keyword-in-javascript-2l0k</link>
      <guid>https://dev.to/crazysamurai/the-this-keyword-in-javascript-2l0k</guid>
      <description>&lt;p&gt;To understand this keyword let’s take an example of the word “this” in the English language with the help of the following images.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vp2JQrbJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nirdnjuu6iiygoy0d0jz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vp2JQrbJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nirdnjuu6iiygoy0d0jz.jpg" alt="this keyword example 1"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2ZaQDO8D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1nghousx9vmqxby4ztx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2ZaQDO8D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1nghousx9vmqxby4ztx.jpg" alt="this keyword example 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the above two images what I’m trying to explain is that the This keyword refers to the object it belongs to. Its value depends on where it is used.&lt;/p&gt;

&lt;p&gt;This keyword will take the value of the owner of the function and point to the owner of the function. The value of this keyword is not static, it depends on the way the function is called.&lt;/p&gt;

&lt;p&gt;If we'll do a simple &lt;code&gt;console.log(this)&lt;/code&gt; in the browser, the output will be the global object(window object) which shows that the this keyword will point to the object that called the function.&lt;/p&gt;

&lt;p&gt;A function can be called commonly in 4 ways(there are other ways):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As a method: In the following code example, the this keyword points to the detail object because it’s the detail object that is called the function and hence is the owner object.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use strict'
const detail = {
  name: "samurai",
  year: "2020",
  calcAge: function () {
    return 2077 - this.year;
  },
};
detail.calcAge();//57
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;As a simple function call in strict mode.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use strict'
function sum() {
  let add = 2 + 2;
  console.log("sum of two numbers is" + add);
  console.log(this);
}
sum();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a normal function, this keyword will point to the window object but if strict mode is used then it will be undefined.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Arrow functions: They don't get their own this keyword. Instead, the surrounding or parent function is the one that gets pointed by the this keyword due to lexical scope.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As an event listener: In this case, the this keyword points to &lt;br&gt;
the handler function attached to the event.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An important point we have to remember that this keyword will not point to the function we are using it in but to the object which called the function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br&gt;
1.This refers to the owner object or the object that called the function.&lt;br&gt;
2.The value of this keyword depends on where it is used.&lt;br&gt;
3.If &lt;code&gt;'use strict'&lt;/code&gt; is in the code then this will point to undefined else to the window object for a simple function call.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Framework VS Library</title>
      <dc:creator>Gaurav</dc:creator>
      <pubDate>Sun, 08 Aug 2021 06:52:39 +0000</pubDate>
      <link>https://dev.to/crazysamurai/framework-vs-library-46pb</link>
      <guid>https://dev.to/crazysamurai/framework-vs-library-46pb</guid>
      <description>&lt;p&gt;Let us start with the similarity between the two that is they both are &lt;em&gt;reusable code&lt;/em&gt; written to solve a common problem and make sure the code is DRY. Assume some developer who encountered a particular problem with the program and realized that it is a very common issue and requires a lot of time and effort to resolve, so he created a library or a framework to solve the issue once and for all. &lt;/p&gt;

&lt;p&gt;Now to the main difference between the two can be explained with the term &lt;em&gt;Inversion of Control&lt;/em&gt; (IoC) which simply means who controls who during the development process or in simpler words it defines the relationship between the library, framework, and code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BEqOg4zu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a2oqnolebf0e2nonss8l.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BEqOg4zu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a2oqnolebf0e2nonss8l.jpeg" alt="Inversion of control"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Code Controls Library
&lt;/h3&gt;

&lt;p&gt;A piece of code that you require multiple times, but you must use the library to keep your code DRY. Most programming languages support libraries like React in the case of JavaScript. With a library, you can choose where to use it in your code and adjust it according to your code.&lt;/p&gt;

&lt;p&gt;Compare this library to an actual library where you can go and pick up any book that you want and read it. In the same way, you can choose any library that suits your need and use it in your code by calling specific functions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Framework Controls Code
&lt;/h3&gt;

&lt;p&gt;A framework defines the architecture for your program and uses the code when needed. It is a collection of libraries that work together. Angular is an example of a JavaScript framework. &lt;br&gt;
A framework provides most tools required to build an application and tells you where to put your code. &lt;/p&gt;

&lt;p&gt;We can understand it by thinking of a blueprint for a building as a framework. The blueprint is how the building is planned to be constructed and the people who are going to live in it have to adjust according to it. &lt;/p&gt;

&lt;p&gt;Basically, it controls your code which means it is in charge.&lt;/p&gt;

&lt;h3&gt;
  
  
  To sum it up
&lt;/h3&gt;

&lt;p&gt;There may be other small differences between the two but the main difference we need to know is the inversion of control i.e. &lt;strong&gt;who controls who&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code controls library &lt;/li&gt;
&lt;li&gt;Framework controls code&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>todayilearned</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
