Assignment Operators in C, all in one

C Programming Language Operators and Enums in C Language (Article) Operators and Enums in C Language (Program)

891

Program:

<span class="com">//Assignment operator </span><span class="pln">

</span><span class="com">#include</span><span class="str">"stdio.h"</span><span class="pln">
</span><span class="kwd">void</span><span class="pln"> main</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
 </span><span class="kwd">int</span><span class="pln"> a </span><span class="pun">=</span><span class="pln"> </span><span class="lit">21</span><span class="pun">;</span><span class="pln">
   </span><span class="kwd">int</span><span class="pln"> c </span><span class="pun">;</span><span class="pln">

   c </span><span class="pun">=</span><span class="pln">  a</span><span class="pun">;</span><span class="pln">
   printf</span><span class="pun">(</span><span class="str">" =  Operator Example : Value of c = %d\n"</span><span class="pun">,</span><span class="pln"> c </span><span class="pun">);</span><span class="pln">

   c </span><span class="pun">+=</span><span class="pln">  a</span><span class="pun">;</span><span class="pln">
   printf</span><span class="pun">(</span><span class="str">" += Operator Example : Value of c = %d\n"</span><span class="pun">,</span><span class="pln"> c </span><span class="pun">);</span><span class="pln">

   c </span><span class="pun">-=</span><span class="pln">  a</span><span class="pun">;</span><span class="pln">
   printf</span><span class="pun">(</span><span class="str">" -= Operator Example : Value of c = %d\n"</span><span class="pun">,</span><span class="pln"> c </span><span class="pun">);</span><span class="pln">

   c </span><span class="pun">*=</span><span class="pln">  a</span><span class="pun">;</span><span class="pln">
   printf</span><span class="pun">(</span><span class="str">" *= Operator Example : Value of c = %d\n"</span><span class="pun">,</span><span class="pln"> c </span><span class="pun">);</span><span class="pln">

   c </span><span class="pun">/=</span><span class="pln">  a</span><span class="pun">;</span><span class="pln">
   printf</span><span class="pun">(</span><span class="str">" /= Operator Example : Value of c = %d\n"</span><span class="pun">,</span><span class="pln"> c </span><span class="pun">);</span><span class="pln">

   c  </span><span class="pun">=</span><span class="pln"> </span><span class="lit">200</span><span class="pun">;</span><span class="pln">
   c </span><span class="pun">%=</span><span class="pln">  a</span><span class="pun">;</span><span class="pln">
   printf</span><span class="pun">(</span><span class="str">" %= Operator Example : Value of c = %d\n"</span><span class="pun">,</span><span class="pln"> c </span><span class="pun">);</span><span class="pln">

   c </span><span class="pun">&lt;&lt;=</span><span class="pln">  </span><span class="lit">2</span><span class="pun">;</span><span class="pln">
   printf</span><span class="pun">(</span><span class="str">" &lt;&lt;= Operator Example, Value of c = %d\n"</span><span class="pun">,</span><span class="pln"> c </span><span class="pun">);</span><span class="pln">

   c </span><span class="pun">&gt;&gt;=</span><span class="pln">  </span><span class="lit">2</span><span class="pun">;</span><span class="pln">
   printf</span><span class="pun">(</span><span class="str">" &gt;&gt;= Operator Example, Value of c = %d\n"</span><span class="pun">,</span><span class="pln"> c </span><span class="pun">);</span><span class="pln">

   c </span><span class="pun">&amp;=</span><span class="pln">  </span><span class="lit">2</span><span class="pun">;</span><span class="pln">
   printf</span><span class="pun">(</span><span class="str">" &amp;= Operator Example, Value of c = %d\n"</span><span class="pun">,</span><span class="pln"> c </span><span class="pun">);</span><span class="pln">

   c </span><span class="pun">^=</span><span class="pln">  </span><span class="lit">2</span><span class="pun">;</span><span class="pln">
   printf</span><span class="pun">(</span><span class="str">" - ^= Operator Example, Value of c = %d\n"</span><span class="pun">,</span><span class="pln"> c </span><span class="pun">);</span><span class="pln">

   c </span><span class="pun">|=</span><span class="pln">  </span><span class="lit">2</span><span class="pun">;</span><span class="pln">
   printf</span><span class="pun">(</span><span class="str">" |= Operator Example : Value of c = %d\n"</span><span class="pun">,</span><span class="pln"> c </span><span class="pun">);</span><span class="pln">

</span><span class="pun">}</span>

Output:

 =  Operator Example : Value of c = 21
 += Operator Example : Value of c = 42
 -= Operator Example : Value of c = 21
 *= Operator Example : Value of c = 441
 /= Operator Example : Value of c = 21
 = Operator Example : Value of c = 11
 <<= Operator Example, Value of c = 44
 >>= Operator Example, Value of c = 11
 &= Operator Example, Value of c = 2
 - ^= Operator Example, Value of c = 0
 |= Operator Example : Value of c = 2
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.