<?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: Richard Toth</title>
    <description>The latest articles on DEV Community by Richard Toth (@tothricsaj).</description>
    <link>https://dev.to/tothricsaj</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F98036%2Fa72d6c3e-dff4-407e-915c-9aa098c20d8b.jpg</url>
      <title>DEV Community: Richard Toth</title>
      <link>https://dev.to/tothricsaj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tothricsaj"/>
    <language>en</language>
    <item>
      <title>Little help to learn - C++ tales #2</title>
      <dc:creator>Richard Toth</dc:creator>
      <pubDate>Thu, 02 Jul 2026 09:25:01 +0000</pubDate>
      <link>https://dev.to/tothricsaj/little-help-to-learn-c-tales-2-17h4</link>
      <guid>https://dev.to/tothricsaj/little-help-to-learn-c-tales-2-17h4</guid>
      <description>&lt;h3&gt;
  
  
  Intro
&lt;/h3&gt;

&lt;p&gt;Learning a new programming language is not the easiest thing. In fact, it can be pretty frustrating, especially if that language is C++.&lt;/p&gt;

&lt;p&gt;That's why I decided to put together a little helper.&lt;/p&gt;

&lt;p&gt;Since I decided to learn C++, I wanted to do it in a more organized way, and I thought I'd share my learning environment in the hope that it might help others as well.&lt;/p&gt;

&lt;p&gt;So, here is my &lt;a href="https://github.com/tothricsaj/cpp_learn/tree/template" rel="noopener noreferrer"&gt;cpp_learn repo&lt;/a&gt;. Let's take a closer look.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is this?
&lt;/h3&gt;

&lt;p&gt;This is a template for studying C++ and experimenting with code. It contains two main folders: &lt;code&gt;examples&lt;/code&gt; and &lt;code&gt;experiments&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The difference between these two folders isn't huge—it's mostly about mindset. I put structured, comprehensive, and reusable code into &lt;code&gt;examples&lt;/code&gt;, while everything else goes into &lt;code&gt;experiments&lt;/code&gt;. Of course, you're free to use the structure in whatever way works best for you.&lt;/p&gt;

&lt;h3&gt;
  
  
  How does it work?
&lt;/h3&gt;

&lt;p&gt;If you check out the repository, you'll find a simple &lt;code&gt;Makefile&lt;/code&gt;. Although compiling and linking are important parts of C++ development (and software development in general), I wanted to focus only on the language itself. Having the build process already set up makes learning much easier, and I believe it also makes the whole process a bit faster.&lt;/p&gt;

&lt;p&gt;The Makefile provides a few simple commands for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;building everything&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;building a single file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;listing available examples&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;running a built executable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;building and running a single file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;cleaning generated files&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find all the details in the repository's README.&lt;/p&gt;

&lt;h3&gt;
  
  
  Outro
&lt;/h3&gt;

&lt;p&gt;I hope this little project helps you learn this wonderful—and wonderfully brain-melting—language. And if you're still hesitating, maybe it will make getting started with C++ a little less intimidating.&lt;/p&gt;

&lt;p&gt;Feel free to fork the repository or download it and start using it. If you find an issue or have an idea for improvement, let me know.&lt;/p&gt;

&lt;p&gt;Oh, I almost forgot—other branches contain my personal learning journey, and things can get pretty messy there. Browse them at your own risk. 😄&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>programming</category>
    </item>
    <item>
      <title>Static in the house - C++ tales #1</title>
      <dc:creator>Richard Toth</dc:creator>
      <pubDate>Wed, 17 Jun 2026 08:48:15 +0000</pubDate>
      <link>https://dev.to/tothricsaj/static-in-the-house-c-tales-1-3dgh</link>
      <guid>https://dev.to/tothricsaj/static-in-the-house-c-tales-1-3dgh</guid>
      <description>&lt;h3&gt;
  
  
  What is static
&lt;/h3&gt;

&lt;p&gt;In C++, &lt;code&gt;static&lt;/code&gt; is a keyword that primarily affects a variable's storage duration. A variable declared as &lt;code&gt;static&lt;/code&gt; exists for the entire lifetime of the program.&lt;/p&gt;

&lt;p&gt;However, there is a little more to it. Depending on where it is used, &lt;code&gt;static&lt;/code&gt; can also affect a symbol's visibility, which is known as &lt;em&gt;linkage&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Static: The Local Hero
&lt;/h3&gt;

&lt;p&gt;When a variable is declared inside a function, it can only be accessed within that function. This is true for both automatic and static local variables. The difference lies in their lifetime. Automatic variables are created every time the function is called and destroyed when the function returns. A local static variable, on the other hand, is initialized only once and remains alive until the program terminates.&lt;/p&gt;

&lt;p&gt;Although the variable continues to exist after the function returns, it is still only accessible from within the function where it was declared. Because its lifetime extends beyond the function call, a local static variable is not typically stored on the stack. It also preserves its value between function calls.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example time
&lt;/h3&gt;

&lt;p&gt;Here is a little showcase code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;cstdio&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;test_static&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;count&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;other_count&lt;/span&gt;&lt;span class="p"&gt;{};&lt;/span&gt;

  &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;other_count&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;"The test_static func is called %d times!!!&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;count&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;"This is other_count &amp;gt;&amp;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;other_count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&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="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;test_static&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="n"&gt;test_static&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="n"&gt;test_static&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;...and the output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;The test_static func is called 1 &lt;span class="nb"&gt;times&lt;/span&gt;&lt;span class="o"&gt;!!!&lt;/span&gt;
This is other_count &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; 1
&lt;span class="nt"&gt;-------------------------------------------------------&lt;/span&gt;
The test_static func is called 2 &lt;span class="nb"&gt;times&lt;/span&gt;&lt;span class="o"&gt;!!!&lt;/span&gt;
This is other_count &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; 1
&lt;span class="nt"&gt;-------------------------------------------------------&lt;/span&gt;
The test_static func is called 3 &lt;span class="nb"&gt;times&lt;/span&gt;&lt;span class="o"&gt;!!!&lt;/span&gt;
This is other_count &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; 1
&lt;span class="nt"&gt;-------------------------------------------------------&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we have a &lt;em&gt;test_static&lt;/em&gt; function with a static and automatic variable: &lt;em&gt;count&lt;/em&gt; and &lt;em&gt;other_count&lt;/em&gt;. In the output, it can be easily what happens with this two little guy. The count - what is a static variable of the test_static funtion - keeps the value and in every function call  it is incremented and keeps and increase the value while the other_count is incremented, too although it cannot keep the own value between the function calls.&lt;/p&gt;

&lt;h3&gt;
  
  
  Static, the member
&lt;/h3&gt;

&lt;p&gt;The behavior of the static is pretty similar in classes but have some differencies, too.&lt;/p&gt;

&lt;p&gt;Let's check this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PlanetOfTheSolarSystem&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;our_star&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;planet_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;PlanetOfTheSolarSystem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;planet_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="nf"&gt;get_planet_name&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="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;planet_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;PlanetOfTheSolarSystem&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;our_star&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"Sun (other name is Sol)"&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;PlanetOfTheSolarSystem&lt;/em&gt; class has two variable &lt;em&gt;our_star&lt;/em&gt; and the &lt;em&gt;planet_name&lt;/em&gt;. While the planet_name is declared in the constructor, the static varialbe - our_star - is declared outside of the class, and a different syntax is used to it. The reason is the static member belongs to class and not to the object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;print_planets_star&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;planet_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;star_of_the_planet&lt;/span&gt;&lt;span class="p"&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;"Star of the %s is %s&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;planet_name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c_str&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;star_of_the_planet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c_str&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="p"&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="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;PlanetOfTheSolarSystem&lt;/span&gt; &lt;span class="n"&gt;venus&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"Venus"&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="n"&gt;PlanetOfTheSolarSystem&lt;/span&gt; &lt;span class="n"&gt;earth&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"Earth"&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="n"&gt;print_planets_star&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;venus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_planet_name&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;venus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;our_star&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;print_planets_star&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;earth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_planet_name&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;earth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;our_star&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Star of the Venus is Sun &lt;span class="o"&gt;(&lt;/span&gt;other name is Sol&lt;span class="o"&gt;)&lt;/span&gt;
Star of the Earth is Sun &lt;span class="o"&gt;(&lt;/span&gt;other name is Sol&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example code and the output show us the essence of the static member. The venus and the earth objects point to same variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In a nutshell, &lt;code&gt;static&lt;/code&gt; is an essential C++ feature for creating data that must persist throughout the program's execution. When used inside functions, it allows values to survive between function calls. When used as a class member, it creates data shared by all instances of the class. In other contexts, it can also affect symbol visibility and linkage.&lt;/p&gt;

&lt;p&gt;Understanding &lt;code&gt;static&lt;/code&gt; is important because it appears frequently in real-world C++ code and forms the basis of several common programming techniques and design patterns.&lt;/p&gt;

&lt;p&gt;Thanks for reading, and keep learning!&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>programing</category>
    </item>
  </channel>
</rss>
