<?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: Sujith V S</title>
    <description>The latest articles on DEV Community by Sujith V S (@sujithvsuresh).</description>
    <link>https://dev.to/sujithvsuresh</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%2F715933%2F6e61467b-7f32-4683-bc95-c2b98d1bd294.jpeg</url>
      <title>DEV Community: Sujith V S</title>
      <link>https://dev.to/sujithvsuresh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sujithvsuresh"/>
    <language>en</language>
    <item>
      <title>Get All Docker Commands</title>
      <dc:creator>Sujith V S</dc:creator>
      <pubDate>Tue, 25 Feb 2025 05:12:49 +0000</pubDate>
      <link>https://dev.to/sujithvsuresh/-l7l</link>
      <guid>https://dev.to/sujithvsuresh/-l7l</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/sujithvsuresh" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F715933%2F6e61467b-7f32-4683-bc95-c2b98d1bd294.jpeg" alt="sujithvsuresh"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/sujithvsuresh/all-docker-commands-dbb" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;All Docker Commands&lt;/h2&gt;
      &lt;h3&gt;Sujith V S ・ Feb 25&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#docker&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#kubernetes&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>docker</category>
      <category>kubernetes</category>
    </item>
    <item>
      <title>All Docker Commands</title>
      <dc:creator>Sujith V S</dc:creator>
      <pubDate>Tue, 25 Feb 2025 05:12:30 +0000</pubDate>
      <link>https://dev.to/sujithvsuresh/all-docker-commands-dbb</link>
      <guid>https://dev.to/sujithvsuresh/all-docker-commands-dbb</guid>
      <description>&lt;p&gt;&lt;code&gt;docker --version&lt;/code&gt;: Check the Docker version.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker help&lt;/code&gt;: Display help information for Docker.&lt;/p&gt;

&lt;h2&gt;
  
  
  Working with Images:
&lt;/h2&gt;

&lt;p&gt;docker pull: Pull an image from a registry.&lt;br&gt;
&lt;code&gt;docker pull &amp;lt;image-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker images&lt;/code&gt;: List all images on the local system.&lt;/p&gt;

&lt;p&gt;docker build: Build an image from a Dockerfile.&lt;br&gt;
&lt;code&gt;docker build -t &amp;lt;image-name&amp;gt; .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker rmi: Remove one or more images.&lt;br&gt;
&lt;code&gt;docker rmi &amp;lt;image-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker tag: Tag an image with a new name.&lt;br&gt;
&lt;code&gt;docker tag &amp;lt;source-image&amp;gt; &amp;lt;target-image&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Working with Containers:
&lt;/h2&gt;

&lt;p&gt;docker run: Run a command in a new container.&lt;br&gt;
&lt;code&gt;docker run -it &amp;lt;image-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker ps: List all running containers.&lt;br&gt;
&lt;code&gt;docker ps&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker ps -a: List all containers, including stopped ones.&lt;br&gt;
&lt;code&gt;docker ps -a&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker start: Start one or more stopped containers.&lt;br&gt;
&lt;code&gt;docker start &amp;lt;container-id&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker stop: Stop one or more running containers.&lt;br&gt;
&lt;code&gt;docker stop &amp;lt;container-id&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker restart: Restart a container.&lt;br&gt;
&lt;code&gt;docker restart &amp;lt;container-id&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker rm: Remove one or more containers.&lt;br&gt;
&lt;code&gt;docker rm &amp;lt;container-id&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker logs: Fetch the logs of a container.&lt;br&gt;
&lt;code&gt;docker logs &amp;lt;container-id&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker exec: Run a command in a running container.&lt;br&gt;
&lt;code&gt;docker exec -it &amp;lt;container-id&amp;gt; &amp;lt;command&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Networking:
&lt;/h2&gt;

&lt;p&gt;docker network ls: List all networks.&lt;br&gt;
&lt;code&gt;docker network ls&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker network create: Create a new network.&lt;br&gt;
&lt;code&gt;docker network create &amp;lt;network-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker network inspect: Display detailed information on one or more networks.&lt;br&gt;
&lt;code&gt;docker network inspect &amp;lt;network-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker network rm: Remove one or more networks.&lt;br&gt;
&lt;code&gt;docker network rm &amp;lt;network-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Volumes:
&lt;/h2&gt;

&lt;p&gt;docker volume ls: List all volumes.&lt;br&gt;
&lt;code&gt;docker volume ls&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker volume create: Create a new volume.&lt;br&gt;
&lt;code&gt;docker volume create &amp;lt;volume-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker volume inspect: Display detailed information on one or more volumes.&lt;br&gt;
&lt;code&gt;docker volume inspect &amp;lt;volume-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker volume rm: Remove one or more volumes.&lt;br&gt;
&lt;code&gt;docker volume rm &amp;lt;volume-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker Compose:
&lt;/h2&gt;

&lt;p&gt;docker-compose up: Build, create, start, and attach to containers.&lt;br&gt;
&lt;code&gt;docker-compose up&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker-compose down: Stop and remove containers, networks, images, and volumes.&lt;br&gt;
&lt;code&gt;docker-compose down&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker-compose build: Build or rebuild services.&lt;br&gt;
&lt;code&gt;docker-compose build&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker-compose ps: List containers.&lt;br&gt;
&lt;code&gt;docker-compose ps&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker-compose exec: Execute a command in a running container.&lt;br&gt;
&lt;code&gt;docker-compose exec &amp;lt;service-name&amp;gt; &amp;lt;command&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker System Management:
&lt;/h2&gt;

&lt;p&gt;docker system df: Show docker disk usage.&lt;br&gt;
&lt;code&gt;docker system df&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;docker system prune: Remove unused data.&lt;br&gt;
&lt;code&gt;docker system prune&lt;/code&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>kubernetes</category>
    </item>
    <item>
      <title>Pagination CDN setup guide for ejs template engine.</title>
      <dc:creator>Sujith V S</dc:creator>
      <pubDate>Sun, 08 Sep 2024 18:42:20 +0000</pubDate>
      <link>https://dev.to/sujithvsuresh/pagination-cdn-setup-guide-229a</link>
      <guid>https://dev.to/sujithvsuresh/pagination-cdn-setup-guide-229a</guid>
      <description>&lt;p&gt;To implement pagination in the ejs template engine, follow these steps.&lt;/p&gt;

&lt;p&gt;Step 1: Include the Pagination CDN&lt;br&gt;
Add the following script at the bottom of your EJS file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdn.jsdelivr.net/gh/SujithVSuresh/pagination-cdn@master/pagination.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Add Pagination Controls to Your Template&lt;br&gt;
Add the following code where you want the pagination buttons to appear:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          &amp;lt;div class="d-flex justify-content-center"&amp;gt;
            &amp;lt;nav aria-label="Page navigation example"&amp;gt;
              &amp;lt;ul class="pagination"&amp;gt;
                &amp;lt;li class="page-item" id="prevBtn"&amp;gt;&amp;lt;a class="page-link text-black" href="#"&amp;gt;Previous&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
                &amp;lt;% for(let i=1; i&amp;lt;= totalPages; i++){ %&amp;gt;
                &amp;lt;li class="page-item pagenationBtn" data-page-no="&amp;lt;%= i %&amp;gt;"&amp;gt;&amp;lt;a class="page-link text-black"&amp;gt;&amp;lt;%= i %&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
                &amp;lt;% } %&amp;gt;
                &amp;lt;li class="page-item" total-pages="&amp;lt;%= totalPages %&amp;gt;" id="nxtBtn"&amp;gt;&amp;lt;a class="page-link text-black" href="#"&amp;gt;Next&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
              &amp;lt;/ul&amp;gt;
            &amp;lt;/nav&amp;gt;
          &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code provides the interface for pagination. Ensure that you align and style the content properly according to your application's design.&lt;/p&gt;

&lt;p&gt;Step 3: Install and setup paginationx npm package for nodejs. &lt;a href="https://dev.to/sujithvsuresh/npm-package-cdn-for-pagination-in-javascript-nodejs-5164"&gt;Follow this guide&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>pagination</category>
      <category>ecommerce</category>
    </item>
    <item>
      <title>NPM Package &amp; CDN for Pagination in Javascript / Nodejs</title>
      <dc:creator>Sujith V S</dc:creator>
      <pubDate>Sun, 08 Sep 2024 18:33:46 +0000</pubDate>
      <link>https://dev.to/sujithvsuresh/npm-package-cdn-for-pagination-in-javascript-nodejs-5164</link>
      <guid>https://dev.to/sujithvsuresh/npm-package-cdn-for-pagination-in-javascript-nodejs-5164</guid>
      <description>&lt;p&gt;Hello, I am someone who dislikes repetitive tasks, so to streamline the process of implementing pagination, I developed an npm package named paginationx for the backend use and a CDN for frontend integration. These tools simplify pagination setup and save time by eliminating the need to write the same code repeatedly.&lt;/p&gt;

&lt;p&gt;In this article will be doing only 2 steps, &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To setup the npm package for the nodejs backend.&lt;/li&gt;
&lt;li&gt;To setup the cdn for pagination in the ejs template frontend.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;1. NPM Package Implementation&lt;/strong&gt;&lt;br&gt;
To use the paginationx npm package for Node.js, follow these steps:&lt;/p&gt;

&lt;p&gt;Step 1: Install Paginationx npm package&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i paginationx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Import the module and use them in your controller.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const pagination = require("paginationx")

const users = async (req, res) =&amp;gt; {
  try {
    const paginate = await pagination(User, 2, req.query)

    res.render("admin/user", {
      users: paginate.data,
      totalPages: paginate.totalPages,

    });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
};

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

&lt;/div&gt;



&lt;p&gt;In the code above, we are passing three arguments to the pagination function:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First argument: The model name representing the data that we need to apply pagination to.&lt;/li&gt;
&lt;li&gt;Second argument: Number of items to be shown on a single page.&lt;/li&gt;
&lt;li&gt;Third argument (optional): Pass the req.query data. Use req.query only if you are using the pagination CDN to handle pagination on the frontend.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The pagination function (const paginate = await pagination(User, 2, req.query)) returns paginated data and total pages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To access the paginated data, use pagination.data.&lt;/li&gt;
&lt;li&gt;To access the total number of pages, use pagination.totalPages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Step 3: Pass the paginated data and total pages count to the ejs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
      users: paginate.data,
      totalPages: paginate.totalPages,
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Key for passing total pages should exactly be totalPages.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;2. Pagination CDN Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To implement pagination in the ejs template engine, follow these steps.&lt;/p&gt;

&lt;p&gt;Step 1: Include the Pagination CDN&lt;br&gt;
Add the following script at the bottom of your EJS file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdn.jsdelivr.net/gh/SujithVSuresh/pagination-cdn@master/pagination.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Add Pagination Controls to Your Template&lt;br&gt;
Add the following code where you want the pagination buttons to appear:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          &amp;lt;div class="d-flex justify-content-center"&amp;gt;
            &amp;lt;nav aria-label="Page navigation example"&amp;gt;
              &amp;lt;ul class="pagination"&amp;gt;
                &amp;lt;li class="page-item" id="prevBtn"&amp;gt;&amp;lt;a class="page-link text-black" href="#"&amp;gt;Previous&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
                &amp;lt;% for(let i=1; i&amp;lt;= totalPages; i++){ %&amp;gt;
                &amp;lt;li class="page-item pagenationBtn" data-page-no="&amp;lt;%= i %&amp;gt;"&amp;gt;&amp;lt;a class="page-link text-black"&amp;gt;&amp;lt;%= i %&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
                &amp;lt;% } %&amp;gt;
                &amp;lt;li class="page-item" total-pages="&amp;lt;%= totalPages %&amp;gt;" id="nxtBtn"&amp;gt;&amp;lt;a class="page-link text-black" href="#"&amp;gt;Next&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
              &amp;lt;/ul&amp;gt;
            &amp;lt;/nav&amp;gt;
          &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code provides the interface for pagination. Ensure that you align and style the content properly according to your application's design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to customise the pagination button?&lt;/strong&gt;&lt;br&gt;
You can give custom styles to the pagination button, but you have to strictly include some of the class, id and properties, inorder to make that pagination works properly in the frontend.&lt;br&gt;
Here we have three kinds of button:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Previous button&lt;/li&gt;
&lt;li&gt;Collection of page number button&lt;/li&gt;
&lt;li&gt;Next button&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Next lets look what all id, class and properties should be included in each of these button to make it work well.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Previous button:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;li id="prevBtn"&amp;gt;&amp;lt;a&amp;gt;Previous&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code can be considered as the base cod for the previous button section. Inside the li tag an id with name 'prevBtn' should be provided.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Page number button:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;% for(let i=1; i&amp;lt;= totalPages; i++){ %&amp;gt;
     &amp;lt;li class="pagenationBtn" data-page-no="&amp;lt;%= i %&amp;gt;"&amp;gt;
     &amp;lt;a&amp;gt;&amp;lt;%= i %&amp;gt;&amp;lt;/a&amp;gt;
     &amp;lt;/li&amp;gt;
&amp;lt;% } %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code can be considered as the base code for the page number button section. li tag should be inside the for loop to show all the page number available. In the li tag you should include the class named 'pagenationBtn' and the &lt;code&gt;data-page-no="&amp;lt;%= i %&amp;gt;"&lt;/code&gt; attribute.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next button:
The below code can be considered as the base code for the next button. In the li tag you should include the id named 'nxtBtn' and the total-pages="&amp;lt;%= totalPages %&amp;gt;" attribute.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;li total-pages="&amp;lt;%= totalPages %&amp;gt;" id="nxtBtn"&amp;gt;&amp;lt;a&amp;gt;Next&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






</description>
      <category>pagination</category>
      <category>npm</category>
      <category>node</category>
      <category>ecommerce</category>
    </item>
    <item>
      <title>Pointer and Array in C programming.</title>
      <dc:creator>Sujith V S</dc:creator>
      <pubDate>Thu, 04 Jan 2024 23:49:00 +0000</pubDate>
      <link>https://dev.to/sujithvsuresh/pointer-and-array-in-c-programming-p1p</link>
      <guid>https://dev.to/sujithvsuresh/pointer-and-array-in-c-programming-p1p</guid>
      <description>&lt;p&gt;&lt;strong&gt;Printing corresponding address of each element of an array.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {

    int numbers[5] = {1, 2, 5, 8, 3};

    for (int i=0; i&amp;lt;5; i++){
        printf("%d = %p\n", numbers[i], &amp;amp;numbers[i]);
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 = 0x7ffffa8cf140
2 = 0x7ffffa8cf144
5 = 0x7ffffa8cf148
8 = 0x7ffffa8cf14c
3 = 0x7ffffa8cf150
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Printing array elements address without index value.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {

    int numbers[5] = {1, 2, 5, 8, 3};

    printf("Array address: %p", numbers);
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Array address: 0x7ffcf4fe97c0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The memory address of the first array element and the address of the array is the same.This is because the address of the array always points to the first element of the array.&lt;/li&gt;
&lt;li&gt;Also in the above code to print the array address we have used only the name of the array instead of the &lt;code&gt;&amp;amp;&lt;/code&gt; sign. This is because in most context array names are by default converted to pointers and we can directly use name of the array without &lt;code&gt;&amp;amp;&lt;/code&gt; sign.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Print other array elements address without index value&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;printf("Array address: %p", numbers + 1);&lt;/code&gt; - this will print the second element.&lt;br&gt;
&lt;code&gt;printf("Array address: %p", numbers + 2);&lt;/code&gt; - this will print the third element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Printing array element's memory address using for loop without index value.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {

    int numbers[5] = {1, 2, 5, 8, 3};

    for (int i=0; i&amp;lt;5; i++){
        printf("%d = %p\n", numbers[i], numbers + i);
    }

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

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
1 = 0x7ffccb8a1d70&lt;br&gt;
2 = 0x7ffccb8a1d74&lt;br&gt;
5 = 0x7ffccb8a1d78&lt;br&gt;
8 = 0x7ffccb8a1d7c&lt;br&gt;
3 = 0x7ffccb8a1d80&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Access array element using pointer.&lt;/strong&gt;&lt;br&gt;
In order to use array elements using pointers, we have to use &lt;code&gt;*(numbers + i)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {

    int numbers[5] = {1, 2, 5, 8, 3};

    for (int i=0; i&amp;lt;5; i++){
        printf("%d = %p\n", *(numbers + i), numbers + i);
    }

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

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 = 0x7fff49ac30b0
2 = 0x7fff49ac30b4
5 = 0x7fff49ac30b8
8 = 0x7fff49ac30bc
3 = 0x7fff49ac30c0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Change array elements using pointers *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {

    int numbers[5] = {1, 2, 5, 8, 3};

    *numbers = 76;
    *(numbers + 1) = 89;

    printf("%d ", *numbers);
    printf("%d", *(numbers+1));

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

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Pointers in C programming.</title>
      <dc:creator>Sujith V S</dc:creator>
      <pubDate>Thu, 04 Jan 2024 11:56:33 +0000</pubDate>
      <link>https://dev.to/sujithvsuresh/pointers-in-c-programming-3ngp</link>
      <guid>https://dev.to/sujithvsuresh/pointers-in-c-programming-3ngp</guid>
      <description>&lt;p&gt;Pointer in c allow us to work directly with the computer memory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Memory Addresses
&lt;/h2&gt;

&lt;p&gt;In c programming whenever we declare a variable a space will be allocated in the memory for the variable and C allows us to access the address of the variable. We use &lt;code&gt;&amp;amp;&lt;/code&gt; with variable name to access the memory address.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {
    int age = 25;
    printf("%p", &amp;amp;age);
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0x7ffcad58272c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The format specifier &lt;code&gt;%p&lt;/code&gt;(pointers) and &lt;code&gt;&amp;amp;&lt;/code&gt; is used to get the memory address where 25 is located.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;scanf("%d", &amp;amp;age);&lt;/code&gt;- with scanf we are instructing the compiler to store the input value at the memory address specified by this &amp;amp;age.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pointer Variable
&lt;/h2&gt;

&lt;p&gt;The pointer variable stores the memory addresses of the available value.&lt;br&gt;
Example: &lt;code&gt;int* ptr;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Assigning value(memory address) to a pointer variable&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {
    int age = 25;
    printf("%p", &amp;amp;age);

    int* ptr = &amp;amp;age; //assigned value.

    printf("\n%p", ptr);
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Access value using pointer&lt;/strong&gt;&lt;br&gt;
Here we are trying to access the value of a variable using pointer variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {
    int age = 25;

    int* ptr = &amp;amp;age; 

    printf("Address: %p\n", ptr);

    printf("Value: %d", *ptr); 

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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;printf("Value: %d", *ptr);&lt;/code&gt;- it gives the value stored in a memory address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Change value using pointer&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {
    int age = 25;

    int* ptr = &amp;amp;age; 

    *ptr = 31; 

    printf("%d", age);

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

&lt;/div&gt;



&lt;p&gt;In the above code, the initially assigned value is 25.&lt;br&gt;
&lt;code&gt;*ptr = 31;&lt;/code&gt; - it assigns a new value pointed by the ptr variable.&lt;br&gt;
&lt;code&gt;printf("%d", age);&lt;/code&gt; - now the value is changes to 31. because it points directly to the address and change the value to 31.&lt;/p&gt;




&lt;p&gt;&lt;code&gt;int* ptr = 32;&lt;/code&gt; (Invalid)&lt;br&gt;
&lt;code&gt;ptr&lt;/code&gt; is a pointer and it can only store memory address. And if we try to assign a value or number to it then it will become invalid.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;*ptr = &amp;amp;number;&lt;/code&gt; (invalid)&lt;br&gt;
&lt;code&gt;*ptr&lt;/code&gt; stores the value and if we try to assign a memory address then it becomes invalid.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ptr = &amp;amp;number;&lt;/code&gt; (valid) - assigning address.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;*ptr = number;&lt;/code&gt; (valid) - assigning value.&lt;/p&gt;

</description>
      <category>pointers</category>
      <category>memory</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>String functions in C programming.</title>
      <dc:creator>Sujith V S</dc:creator>
      <pubDate>Wed, 03 Jan 2024 14:01:49 +0000</pubDate>
      <link>https://dev.to/sujithvsuresh/string-functions-in-c-programming-28hh</link>
      <guid>https://dev.to/sujithvsuresh/string-functions-in-c-programming-28hh</guid>
      <description>&lt;p&gt;To use the string functions, we have to use &lt;code&gt;&amp;lt;string.h&amp;gt;&lt;/code&gt; header file.&lt;/p&gt;

&lt;h2&gt;
  
  
  strlen()
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;string.h&amp;gt;

int main() {
    char str[] = "Hello, World!";
    int length = strlen(str);
    printf("Length of the string: %d\n", length);
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  strcpy()
&lt;/h2&gt;

&lt;p&gt;This function is used to copy one string to another.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;string.h&amp;gt;

int main() {
    char food[] = "Pizza";
    char bestFood[strlen(food)];
    strcpy(bestFood, food);
    printf("%s", bestFood);
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;strcpy(bestFood, food);&lt;/code&gt;&lt;br&gt;
Here first argument is the variable we want to put the copied string. Second argument is the variable in which we want to copy the string. &lt;/p&gt;
&lt;h2&gt;
  
  
  strcat()
&lt;/h2&gt;

&lt;p&gt;This is used to join two string together.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;string.h&amp;gt;

int main() {
    char str1[] = "Hello, ";
    char str2[] = "world!";

    strcat(str1, str2);

    printf("%s", str1);

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

&lt;/div&gt;



&lt;p&gt;To concatenate second string to the first string.&lt;/p&gt;

&lt;h2&gt;
  
  
  strcmp()
&lt;/h2&gt;

&lt;p&gt;String comparison function to check if two strings are equal. If this function returns 0 then it can be considered as equal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;string.h&amp;gt;

int main() {
    char text1[] = "abcd";
    char text2[] = "abcd";

    int result = strcmp(text1, text2);

    printf("%d", result);

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

&lt;/div&gt;






&lt;p&gt;These are just a few examples, and there are more string manipulation functions available in the C standard library &lt;code&gt;&amp;lt;string.h&amp;gt;&lt;/code&gt;&lt;/p&gt;

</description>
      <category>string</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>String in C programming.</title>
      <dc:creator>Sujith V S</dc:creator>
      <pubDate>Wed, 03 Jan 2024 13:44:41 +0000</pubDate>
      <link>https://dev.to/sujithvsuresh/string-in-c-programming-1egj</link>
      <guid>https://dev.to/sujithvsuresh/string-in-c-programming-1egj</guid>
      <description>&lt;p&gt;String is a collection of characters that are used to represent textual data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {
    char str[] = "Sujith";
    printf("%s", str);
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;%s&lt;/code&gt; format specifier for printing string.&lt;/li&gt;
&lt;li&gt;Every string in c ends with \0. This null character helps the compiler to know the end of the string. So actual size of the string will be 1 greater than the total no;of character in the string. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  String Input
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {

    char str[20];

    printf("Enter your name here: ");

    scanf("%s", str);

    printf("%s", str);

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

&lt;/div&gt;



&lt;p&gt;In order to take the input, we don't need to use &lt;code&gt;&amp;amp;&lt;/code&gt; for string because &lt;code&gt;str&lt;/code&gt; is an array and it already points to the first element of &lt;code&gt;str&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The scanf method can only take input until it encounters white spaces. So not possible to take input like "Steve Jobs". So to take all the inputs we can use:&lt;br&gt;
&lt;code&gt;fgets(str, sizeof(str), stdin)&lt;/code&gt;&lt;br&gt;
str - string name&lt;br&gt;
sizeof(str) - size of string.&lt;br&gt;
stdin - it means standard input. It denotes we are taking input from the keyboard. &lt;/p&gt;

&lt;h2&gt;
  
  
  Access characters of string
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {

    char str[] = "Sujith";

    printf("%c", str[0]); 

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

&lt;/div&gt;



&lt;p&gt;Since we are only printing single character use %c format specifier&lt;/p&gt;

&lt;h2&gt;
  
  
  Changing elements of a string.
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {

    char str[] = "Sujith";

    str[2] = 'J';
    str[4] = 'T';

    printf("%s", str);
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>string</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Multi-dimensional Array</title>
      <dc:creator>Sujith V S</dc:creator>
      <pubDate>Wed, 03 Jan 2024 05:59:17 +0000</pubDate>
      <link>https://dev.to/sujithvsuresh/multi-dimensional-array-3mdi</link>
      <guid>https://dev.to/sujithvsuresh/multi-dimensional-array-3mdi</guid>
      <description>&lt;p&gt;Each element of multi dimensional array is an array. This is why it is called as array of arrays.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;br&gt;
&lt;code&gt;int arr[2][3];&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;int - datatype&lt;br&gt;
arr - name of array.&lt;br&gt;
2 - there will be two arrays inside this array.&lt;br&gt;
3 - each array will have 3 elements.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;int arr[2][3] = {{1,2,3}, {6,7,8}};&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Access array elements
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int arr[2][3] = {{1,2,3}, {6,7,8}};

    printf("%d ", arr[0][0]); 
    printf("%d ", arr[1][2]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here 1 is the second array and 2 is the third element in this array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Change array values.
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main() {

    int arr[2][3] = {{1,2,3}, {6,7,8}};

    arr[0][2] = 7;
    arr[1][1] = 8;

    printf("%d", arr[0][2]);
    printf("%d", arr[1][1]);

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Multidimensional array using for loop
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {

    int arr[2][3] = {{1,2,3}, {6,7,8}};

    for(int i=0; i&amp;lt;2; i++){
        for(int j=0; j&amp;lt;3; j++){
            printf("%d ", arr[i][j]);
        }
    }

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

&lt;/div&gt;



&lt;p&gt;First for loop for each arrays inside and the second for loop is for the elements inside each array.&lt;/p&gt;

</description>
      <category>array</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Array in C programming.</title>
      <dc:creator>Sujith V S</dc:creator>
      <pubDate>Wed, 27 Dec 2023 11:38:31 +0000</pubDate>
      <link>https://dev.to/sujithvsuresh/array-in-c-programming-37g3</link>
      <guid>https://dev.to/sujithvsuresh/array-in-c-programming-37g3</guid>
      <description>&lt;p&gt;An array is a collection of single type of data.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;br&gt;
&lt;code&gt;datatype arrayName[arraySize];&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Assigning values to array.
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;int age[5] = {56, 45, 87, 23, 54};&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can also remove the size of the array so that the compiler will automatically determine the size of the array by counting the elements inside thew curly bracket.&lt;br&gt;
&lt;code&gt;int age[] = {56, 45, 87};&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If the size of an array is 5 and we adds only 3 value to it then the remaining two values will be occupied by 0.&lt;br&gt;
&lt;code&gt;int age[5] = {56, 45, 87};&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Access array elements.
&lt;/h2&gt;

&lt;p&gt;In c programming each element of an array is represented with a value known as index value. Index value starts with 0, therefore the first element of an array will have the index value 0.&lt;/p&gt;

&lt;p&gt;To access the element in an array we use: &lt;br&gt;
&lt;code&gt;arrayName[index]&lt;/code&gt;&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int age[5] = {56, 45, 87, 89, 54};

printf("%d", age[0]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Assign values using index number.
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int age[5];

age[0] = 22;
age[1] = 65;
age[2] = 43;
age[3] = 56;
age[4] = 26;
age[5] = 89;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Assign values to an array from user input
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int age[5];

printf("Enter 5 input values: ");
scanf("%d", &amp;amp;age[0]);
scanf("%d", &amp;amp;age[1]);
scanf("%d", &amp;amp;age[2]);
scanf("%d", &amp;amp;age[3]);
scanf("%d", &amp;amp;age[4]);
scanf("%d", &amp;amp;age[5]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Changing array elements.
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {

    int age[5] = {4, 56, 8, 43, 6};

    //changing array elements.
    age[2] = 26;

    printf("%d", age[2]);

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

&lt;/div&gt;



&lt;p&gt;In the above code, we have changed the value 8 to 26. The index value of 8 is 2.&lt;/p&gt;

&lt;h2&gt;
  
  
  Loops in array
&lt;/h2&gt;

&lt;p&gt;We can use loops in C programming to assign or print values in an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {

    int age[5];

    for(int i=0; i&amp;lt;5; i++){
        scanf("%d", &amp;amp;age[i]);
    }

    for(int i=0; i&amp;lt;5; i++){
        printf("%d", age[i]);
    }

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Index out of Bound Error
&lt;/h2&gt;

&lt;p&gt;If we try to access array outside of its bound or limit or allocated memory space then it can cause error.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int age[5];

for(int i=0; i&amp;lt;5; i++){
        scanf("%d", &amp;amp;age[i]);
    }

for(int i=0; i&amp;lt;6; i++){
   printf("%d ", age[i]);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8 6 5 4 3 32764 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code the size of an array is 5. And in the second loop we are trying to access the 6th element of the array  named age. Therefore this caused the index out of bound error and prints the value 32764.&lt;/p&gt;

</description>
      <category>array</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Recursion in C programming.</title>
      <dc:creator>Sujith V S</dc:creator>
      <pubDate>Wed, 27 Dec 2023 11:08:26 +0000</pubDate>
      <link>https://dev.to/sujithvsuresh/recursion-in-c-programming-3p8p</link>
      <guid>https://dev.to/sujithvsuresh/recursion-in-c-programming-3p8p</guid>
      <description>&lt;p&gt;A function that calls itself is called recursion function.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void recurse(){
    ....
    recurse();
    ...    
}

int main(){
    ....
    recurse();
    ....
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code the function recurse() will call itself again and again.&lt;br&gt;
To prevent it we can add if else statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void recurse(){
    if(condition){
    ....
    }
    else{
    recurse();
    }
    ...    
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Task 1: Program to find the sum of n natural numbers.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {

    int number, result;

    printf("Enter a number: ");

    scanf("%d", &amp;amp;number);

    result = findSum(number);

    printf("Sum = %d", result);

    return 0;
}

int findSum(int num){
    if(num!=0){
        return num + findSum(num - 1);
    }else{
        return 0;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Task 2: Program to find the factorial of a number:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {

    int number, result;

    printf("Enter a number: ");

    scanf("%d", &amp;amp;number);

    result = findSum(number);

    printf("Sum = %d", result);

    return 0;
}

int findSum(int num){
    if(num!=0){
        return num * findSum(num - 1);
    }else{
        return 1;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>c</category>
    </item>
    <item>
      <title>Standard library functions in C programming.</title>
      <dc:creator>Sujith V S</dc:creator>
      <pubDate>Thu, 21 Dec 2023 18:11:26 +0000</pubDate>
      <link>https://dev.to/sujithvsuresh/standard-library-functions-in-c-programming-3egg</link>
      <guid>https://dev.to/sujithvsuresh/standard-library-functions-in-c-programming-3egg</guid>
      <description>&lt;p&gt;Standard library functions are predefined function which is already defined inside a file and we can directly use them in our program.&lt;/p&gt;

&lt;h2&gt;
  
  
  Input / Output functions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;printf()&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;printf()&lt;/code&gt; is a standard library function which is defined in the &lt;code&gt;stdio.h&lt;/code&gt; header file. So that is why &lt;code&gt;&amp;lt;stdio.h&amp;gt;&lt;/code&gt; is included in our program file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {

    printf("Hello world");

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Other I/O functions in C are:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;scanf()&lt;/code&gt;: Reads formatted input from the console.&lt;br&gt;
&lt;code&gt;getchar()&lt;/code&gt;: Reads a single character from the console.&lt;br&gt;
&lt;code&gt;putchar()&lt;/code&gt;: Writes a single character to the console.&lt;br&gt;
&lt;code&gt;fopen()&lt;/code&gt;: Opens a file.&lt;br&gt;
&lt;code&gt;fclose()&lt;/code&gt;: Closes a file.&lt;br&gt;
&lt;code&gt;fread()&lt;/code&gt;: Reads data from a file.&lt;br&gt;
&lt;code&gt;fwrite()&lt;/code&gt;: Writes data to a file.&lt;/p&gt;
&lt;h2&gt;
  
  
  Mathematical functions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;sqrt()&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;sqrt()&lt;/code&gt; is a standard library function which is defined in the &lt;code&gt;&amp;lt;math.h&amp;gt;&lt;/code&gt; header file. It is used to calculate the square root of a number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;math.h&amp;gt;

int main() {

    int num = 25;
    printf("Square root %lf", sqrt(num));

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;cbrt()&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;cbrt()&lt;/code&gt; is a standard library function which is defined in the &lt;code&gt;&amp;lt;math.h&amp;gt;&lt;/code&gt; header file. It is used to calculate the cube root of a number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;math.h&amp;gt;
int main() {

    int num = 27;
    printf("Cube root %lf", cbrt(num));

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;pow(a, b)&lt;/strong&gt;&lt;br&gt;
In C, &lt;code&gt;pow(a, b)&lt;/code&gt; is used to calculate the a raised to the power of b. It's available in the &lt;code&gt;&amp;lt;math.h&amp;gt;&lt;/code&gt; header file and takes two arguments.&lt;br&gt;
a: The base value &lt;br&gt;
b: The exponent&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;math.h&amp;gt;
int main() {

    int a = 5;
    int b = 2;

    double result = pow(a, b);
    printf("Power: %lf", result);

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Other mathematical functions in C are:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;abs()&lt;/code&gt;: Returns the absolute value of a number.&lt;br&gt;
&lt;code&gt;sin()&lt;/code&gt;: Calculates the sine of an angle.&lt;br&gt;
&lt;code&gt;cos()&lt;/code&gt;: Calculates the cosine of an angle.&lt;/p&gt;
&lt;h2&gt;
  
  
  Character handling functions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;toupper()&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;toupper()&lt;/code&gt; is a standard library function which is defined in the &lt;code&gt;&amp;lt;ctype.h&amp;gt;&lt;/code&gt; header file. It is used to convert a lowercase letter to its uppercase equivalent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;ctype.h&amp;gt;

int main() {
    char alpha = 'e';
    char upper = toupper(alpha);
    printf("%c", upper);
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Other character handling functions in C are:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;isalpha()&lt;/code&gt;: Checks if a character is an alphabet.&lt;br&gt;
&lt;code&gt;isdigit()&lt;/code&gt;: Checks if a character is a digit.&lt;br&gt;
&lt;code&gt;isupper()&lt;/code&gt;: Checks if a character is uppercase.&lt;br&gt;
&lt;code&gt;islower()&lt;/code&gt;: Checks if a character is lowercase.&lt;br&gt;
&lt;code&gt;tolower()&lt;/code&gt;: Converts a character to lowercase.&lt;/p&gt;




&lt;p&gt;Apart from the standard library functions that are mentioned above, there are many other standard library functions in C programming which are used for important operations. The remaining functions will be discussed in the upcoming posts.&lt;/p&gt;

</description>
      <category>functions</category>
      <category>library</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
