<?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: SwagatikaBehera</title>
    <description>The latest articles on DEV Community by SwagatikaBehera (@swagatikabehera).</description>
    <link>https://dev.to/swagatikabehera</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%2F700970%2F14233ed4-970e-4f86-979e-566f11834e6c.png</url>
      <title>DEV Community: SwagatikaBehera</title>
      <link>https://dev.to/swagatikabehera</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/swagatikabehera"/>
    <language>en</language>
    <item>
      <title>Understanding a++ and ++a</title>
      <dc:creator>SwagatikaBehera</dc:creator>
      <pubDate>Tue, 16 Nov 2021 12:26:27 +0000</pubDate>
      <link>https://dev.to/swagatikabehera/understanding-a-and-a-27f3</link>
      <guid>https://dev.to/swagatikabehera/understanding-a-and-a-27f3</guid>
      <description>&lt;p&gt;lets define it first:&lt;br&gt;
&lt;strong&gt;++a&lt;/strong&gt;    here first variable value increment by 1, then value is assigned.(pre increment)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a++&lt;/strong&gt;    here value of variable is assigned first, then increment by 1.(post increment)&lt;/p&gt;

&lt;p&gt;eg:  suppose, a = 5&lt;br&gt;
++a = 1 + 5 = 6&lt;br&gt;
a++ = 5 + 1 = 6&lt;br&gt;
It seem to be same, right!&lt;/p&gt;

&lt;p&gt;But Its actual difference can be seen in expression,&lt;br&gt;
lets understand with some steps by taking an expression:&lt;br&gt;
eg: a = 5&lt;br&gt;
x = a++ + ++a&lt;br&gt;
steps:&lt;br&gt;
1) 1st evaluate all the pre Operation.&lt;br&gt;
2) Place variable value.&lt;br&gt;
3) Evaluate post Operation.&lt;/p&gt;

&lt;p&gt;first, a = 1 + 5 = 6 (because of ++a in 2nd term, a value incremented to 6 from 5 by 1)&lt;/p&gt;

&lt;p&gt;second, x = 6 + 6 = 12 (now a value is 6 which we assigned to x)&lt;/p&gt;

&lt;p&gt;third, a = 6 + 1 = 7 (because of a++ in 1st term, a value increment to 7 from 6 by 1)&lt;/p&gt;

&lt;p&gt;so, x=12 , a=7&lt;/p&gt;

&lt;p&gt;Similarly it will happen with decrement operation,&lt;br&gt;
&lt;strong&gt;--a&lt;/strong&gt;    here first variable value decrement by 1, then value is assigned.(pre decrement)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a--&lt;/strong&gt;    here value of variable is assigned first, then decrement by 1.(post decrement)&lt;/p&gt;

&lt;p&gt;eg: a = 6&lt;br&gt;
x = a++ + a--&lt;br&gt;
first, no pre Operation.&lt;br&gt;
Second, x = 6 + 6 = 12 (a value is assigned which is 6).&lt;br&gt;
Third, a = 6 + 1 = 7( because of 1st term a++)&lt;br&gt;
           7 + (-1) = 6( because of 2nd term a--)&lt;/p&gt;

&lt;p&gt;so, x=12 , a=6&lt;/p&gt;

&lt;p&gt;eg: a = 6&lt;br&gt;
x = ++a + a-- + --a - a++ + a++&lt;br&gt;
first, a = 1 + 6 = 7&lt;br&gt;
         (-1) + 7 = 6&lt;br&gt;
second, x = 6 + 6 + 6 - 6 + 6 = 18&lt;br&gt;
third, a = 6 + (-1) = 5&lt;br&gt;
           5 + 1 = 6&lt;br&gt;
           6 + 1 = 7&lt;/p&gt;

&lt;p&gt;so, x=18 , a=7&lt;/p&gt;

&lt;p&gt;eg: a = 6&lt;br&gt;
x = ++a + --a&lt;br&gt;
first, a = 1 + 6 = 7&lt;br&gt;
           (-1) + 7 = 6&lt;br&gt;
second, x = 6 + 6 = 12&lt;br&gt;
third, no post operation.&lt;/p&gt;

&lt;p&gt;so, x=12 , a=6&lt;/p&gt;

&lt;p&gt;eg: given a = 5&lt;br&gt;
find x, y, a&lt;br&gt;
x = a++&lt;br&gt;
y = ++a&lt;/p&gt;

&lt;p&gt;x = 5 (first a value is assigned to x and later a will increment by 1, a = 5 + 1 = 6)&lt;br&gt;
y = 1 + 6 = 7 (here first a value increment by 1 then value is assigned)&lt;/p&gt;

&lt;p&gt;so, x=5 , y=7 , a=7&lt;/p&gt;

&lt;p&gt;Hope you understand completely!&lt;/p&gt;

</description>
      <category>unaryoperator</category>
      <category>loops</category>
      <category>increment</category>
      <category>decrement</category>
    </item>
  </channel>
</rss>
