<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[C Programming මුල සිට ඉගෙනගනිමු (part 3 - Operators)]]></title><description><![CDATA[<p dir="auto">සුබ දවසක් ඔයාලට.  කලින් දවසේ මන් ඔයාලට කියලා දුන්නා variables කියන්නේ මොනාද ඒවා වැඩ කරන්නේ කොහොමද කියලා. අද මන් කියලා දෙන්න යන්නේ C programming වල එන operators<br />
ගැනයි</p>
<p dir="auto"><strong>Operators</strong></p>
<ul>
<li>
<p dir="auto">operator එකක් කියන්නේ කිසියම් අගයක් හෝ විචල්‍යයක්(variable) හසුරුවන කිසියම් සංකේතයකටයි.<br />
උදා -: +, -, /, *, =, &gt;, &lt;.......</p>
</li>
<li>
<p dir="auto">C programming වල අපි ප්‍රධාන වශයෙන් operators වර්ග 4ක් ගැන අධ්‍යනය කරනවා</p>
<pre><code>  1. Arithmetic Operators -: ගණිතමය ක්‍රියාකාරකම් සඳහා මේවා යොදා ගනී. (උදා -: +, -, *, /, %)
  2. Assignment Operators -: යම් කිසි අගයක් variable එකකට assign කරන්න මේවා යොදා ගනී. (උදා -: =, +=, -=, *=, /=, %=)
  3. Relational Operators -: මෙහෙයුම් දෙකක් අතර සම්බන්ධතාවය පරීක්ෂා කිරීමට මේවා යොදා ගනී. (උදා -: ==, &gt;=, &lt;=, !=, &gt;, &lt;)
  4. Logical Operators    -: සරලව කිව්වොත් AND, OR, NOT වලට තමා logical pperators කියන්නේ(උදා -: &amp;&amp;, ||, !)
</code></pre>
</li>
</ul>
<p dir="auto"><strong>Arithmetic Operators</strong></p>
<ul>
<li>කලින් කිව්වා වගේ මේවා යොදා ගන්නේ ගණිතමය ක්‍රියාකාරකම් සඳහා වේ.</li>
</ul>
<pre><code>	    operator		         meaning			example
		+			එකතු කිරීම			3 + 2 = 5
		-			අඩු කිරීම			3 - 2 = 1
		*			ගුණ කිරීම			3 * 2 = 6
		/			බෙදීම				4 / 2 = 2
		%			බෙදීමෙන් පසු ඉතුරු		3 % 2 = 1, 4 % 2 = 0
</code></pre>
<ul>
<li>අපි දැන් මෙම operators භාවිතා කරලා programm එකක් ලියමු.</li>
</ul>
<pre><code>	#include &lt;stdio.h&gt;

	int main()
	{
		int num1 = 3, num2 = 2;
		int ans;
		
		ans = num1 + num2;
		printf("num1 + num2 = %d\n", ans);
		
		ans = num1 - num2;
		printf("num1 - num2 = %d\n", ans);
		
		ans = num1 * num2;
		printf("num1 * num2 = %d\n", ans);
		
		ans = num1 / num2;
		printf("num1 / num2 = %d\n", ans);
		
		ans = num1 % num2;
		printf("reminder    = %d\n", ans);
		
		return 0;
	}
</code></pre>
<ul>
<li>මෙය run කල පසු output එක වන්නේ</li>
</ul>
<pre><code>	num1 + num2 = 5                                                                                                       
	num1 - num2 = 1                                                                                                       
	num1 * num2 = 6                                                                                                       
	num1 / num2 = 1                                                                                                       
	reminder    = 1 
</code></pre>
<p dir="auto"><strong>විශේෂ</strong></p>
<ul>
<li>ඔයාලට මෙතන පේනවා ඇති බෙදීම වෙන තැන උත්තරය 1.5 ලැබිය යුතු වුවත් අපිට ලැබුනේ 1 පමණක් බව. මේකට ප්‍රධාන හේතුව වන්නේ අපේ <code>ans, num1, num2</code> යන variables සේරම <code>integers</code><br />
වීමයි. <code>integers</code> වලින් output කරන්නේ පූර්ණ සංඛ්‍යා විතරයි. මේ ප්‍රශ්නය මඟහැර ගන්න මේ පියවර අනුගමනය කරන්න</li>
</ul>
<pre><code>	#include &lt;stdio.h&gt;

	int main()
	{
		int num1 = 3, num2 = 2;
		int ans;
		float answer;
		
		answer = num1 / (float)num2; //මෙහිදී අපි තාවකාලිකව num2 ව float අගයක් බවට පත්කරනවා.
		printf("num1 / num2 = %.2f\n", answer);
		
		answer = (float)num1 / num2; //මෙහිදී අපි තාවකාලිකව num1 ව float අගයක් බවට පත්කරනවා.
		printf("num1 / num2 = %.2f\n", answer);
		
		return 0;
	}
</code></pre>
<ul>
<li>මෙය run කල පසු output එක වන්නේ</li>
</ul>
<pre><code>	num1 / num2 = 1.50                                                                                                                          
	num1 / num2 = 1.50 
</code></pre>
<ul>
<li>
<p dir="auto">තවදුරටත් Arithmetic Operators ගැන කතා කිරීමේදී අපිට හමුවනවා Increment and Decrement Operators යන වර්ග දෙක.<br />
උදා -: num1 = 5 ලෙස ගනිමු.</p>
</li>
<li>
<p dir="auto">num++ --&gt; num = num + 1;</p>
</li>
</ul>
<ol>
<li>ans = num1++ --&gt; මෙහි තේරුම වන්නේ</li>
</ol>
<pre><code>ans = num1;
num1 = num1 + 1;
</code></pre>
<ol start="2">
<li>ans = ++num1 --&gt; මෙහි තේරුම වන්නේ</li>
</ol>
<pre><code>num1 = num1 + 1;
ans = num1;
</code></pre>
<ul>
<li>මෙය භාවිතා කොට programm එකක් ලියමු.</li>
</ul>
<pre><code>	#include &lt;stdio.h&gt;

	int main()
	{
		int num1 = 3;
		int num2 = 3;
		int num3 = 3;
		int num4 = 3;
		
		int ans;
		
		ans = num1++;
		printf("answer = %d\n", ans);
		
		ans = ++num2;
		printf("answer = %d\n", ans);
		
		ans = num3--;
		printf("answer = %d\n", ans);
		
		ans = --num4;
		printf("answer = %d\n", ans);
	   
		return 0;
	}
</code></pre>
<ul>
<li>මෙය run කල පසු output එක වන්නේ</li>
</ul>
<pre><code>	answer = 3                                                                                                                                  
	answer = 4                                                                                                                                  
	answer = 3                                                                                                                                  
	answer = 2 
</code></pre>
<p dir="auto"><strong>Assignment Operators</strong></p>
<ul>
<li>යම් කිසි අගයක් variable එකකට assign කරන්න මේවා යොදා ගනී</li>
</ul>
<pre><code>    Operator	       Example		Meaning
	=		a = b		a = b
	+=		a += b		a = a +	b
	-+		a -= b		a = a - b
	*=		a *= b		a = a * b
	/=		a /= b		a = a / b
	%=		a %= b		a = a % b
</code></pre>
<ul>
<li>අපි දැන් මෙම operators භාවිතා කරලා programm එකක් ලියමු.</li>
</ul>
<pre><code>	#include &lt;stdio.h&gt;

	int main()
	{
		int ans;
		int num1 = 4;
		
		ans = num1; 	// ans = 4
		printf("answer = %d\n", ans);
		
		ans += num1; 	//ans = 4 + 4 = 8
		printf("answer = %d\n", ans);
		
		ans -= num1; 	//ans = 8 - 4 = 4
		printf("answer = %d\n", ans);
		
		ans *= num1; 	// ans = 4 * 4 = 16
		printf("answer = %d\n", ans);
		
		ans /= num1; 	// ans = 16 / 4 = 4
		printf("answer = %d\n", ans);
		
		ans %= num1; 	// ans = 4 % 4 = 0
		printf("answer = %d\n", ans);
	   
		return 0;
	}
</code></pre>
<ul>
<li>මෙය run කල පසු output එක වන්නේ</li>
</ul>
<pre><code>	answer = 4                                                                                                                                    
	answer = 8                                                                                                                                    
	answer = 4                                                                                                                                    
	answer = 16                                                                                                                                   
	answer = 4                                                                                                                                    
	answer = 0  
</code></pre>
<p dir="auto"><strong>Relational Operators</strong></p>
<ul>
<li>
<p dir="auto">මෙහෙයුම් දෙකක් අතර සම්බන්ධතාවය පරීක්ෂා කිරීමට මේවා යොදා ගනී.</p>
</li>
<li>
<p dir="auto">සම්බන්ධතාවය සත්‍ය නම් output ලෙස 1 ලැබේ.(එනම් එම condition එක true වේ)</p>
</li>
<li>
<p dir="auto">සම්බන්ධතාවය අසත්‍ය නම් output ලෙස 0 ලැබේ.(එනම් එම condition එක false වේ)</p>
</li>
</ul>
<pre><code>     Operator	         Meaning								Example
	==		සමාන වේද			5 == 3 පහ කිසිසේත්ම තුනට සමාන නොවේ, එනම් මෙය false වේ. එබැවින් output එක 0 වේ.
							5 == 5 පහ හැමවිටම පහට සමාන වේ. මෙය true වේ. එබැවින් output එක 1 වේ.
							
	&gt;		විශාල වේද			5 &gt; 3 පහ හැමවිටම තුනට වඩා විශාල වේ. එබැවින් output එක 1 වේ.
							5 &gt; 7 පහ කිසිවිටකත් හතට වඩා විශාල නොවේ. එබැවින් output එක 0 වේ.
							
	&lt;		කුඩා වේද			5 &lt; 7 පහ හැමවිටම හතට වඩා කුඩා වේ. output = 1
							5 &lt; 3 පහ කිසිවිටකත් තුනට වඩා කුඩා නොවේ. output = 0
							
	!=		අසමාන වේද			5 != 3 පහ සෑම විටම තුනට අසමාන වේ. එබැවින් මෙය සත්‍ය වේ. output = 1
							5 != 5 පහ සෑම විටම පහට සමාන වේ. එබැවින් මෙය අසත්‍ය වේ. output = 0
							
	&gt;=		විශාල හෝ සමාන වේද	        5 &gt;= 3 පහ තුනට සමාන නොවුනත් තුනට වඩා විශාල වේ. එබැවින් මෙය සත්‍ය වේ. output = 1
							5 &gt;= 5 පහ පහට වඩා විශාල නොවුනත් පහට සමාන වේ. එබැවින් මෙය සත්‍ය වේ. output = 1
							5 &gt;= 7 පහ හතට වඩා විශාලවත් සමානවත් වන්නේ නැත. එබැවින් මෙය අසත්‍ය වේ. output = 0
							
	&lt;=		කුඩා හෝ සමාන වේද	        5 &lt;= 7 පහ හතට සමාන නොවුනත් හතට වඩා කුඩා වේ. එබැවින් මෙය සත්‍ය වේ. output = 1
							5 &lt;= 5 පහ පහට වඩා කුඩා නොවුනත් පහට සමාන වේ. එබැවින් මෙය සත්‍ය වේ. output = 1
							5 &lt;= 3 පහ තුනට වඩා කුඩාවත් සමානවත් වන්නේ නැත. එබැවින් මෙය අසත්‍ය වේ. output = 0
</code></pre>
<ul>
<li>අපි දැන් මෙම operators භාවිතා කරලා programm එකක් ලියමු.</li>
</ul>
<pre><code>	#include &lt;stdio.h&gt;

	int main()
	{
		int ans;
		
		ans = (5 == 5);
		printf("(5 == 5)answer = %d\n", ans);
		
		ans = (5 == 3);
		printf("(5 == 3)answer = %d\n\n", ans);
		
		ans = (5 &gt; 3);
		printf("(5 &gt; 3)answer = %d\n", ans);
		
		ans = (5 &gt; 7);
		printf("(5 &gt; 7)answer = %d\n\n", ans);
		
		ans = (5 != 3);
		printf("(5 != 3)answer = %d\n", ans);
		
		ans = (5 != 5);
		printf("(5 != 5)answer = %d\n\n", ans);
		
		ans = (5 &gt;= 3);
		printf("(5 &gt;= 3)answer = %d\n", ans);
		
		ans = (5 &gt;= 5);
		printf("(5 &gt;= 5)answer = %d\n", ans);
		
		ans = (5 &gt;= 7);
		printf("(5 &gt;= 7)answer = %d\n\n", ans);
		
		ans = (5 &lt;= 5);
		printf("(5 &lt;= 5)answer = %d\n", ans);
		
		ans = (5 &lt;= 7);
		printf("(5 &lt;= 7)answer = %d\n", ans);
		
		ans = (5 &lt;= 3);
		printf("(5 &lt;= 3)answer = %d\n", ans);
	   
		return 0;
	}
</code></pre>
<ul>
<li>මෙය run කල පසු output එක වන්නේ</li>
</ul>
<pre><code>(5 == 5)answer = 1                                                                                                                            
(5 == 3)answer = 0                                                                                                                            
                                                                                                                                              
(5 &gt; 3)answer = 1                                                                                                                             
(5 &gt; 7)answer = 0                                                                                                                             
                                                                                                                                              
(5 != 3)answer = 1                                                                                                                            
(5 != 5)answer = 0                                                                                                                            
                                                                                                                                              
(5 &gt;= 3)answer = 1                                                                                                                            
(5 &gt;= 5)answer = 1                                                                                                                            
(5 &gt;= 7)answer = 0                                                                                                                            
                                                                                                                                              
(5 &lt;= 5)answer = 1                                                                                                                            
(5 &lt;= 7)answer = 1                                                                                                                            
(5 &lt;= 3)answer = 0 
</code></pre>
<p dir="auto"><strong>Logical Operators</strong></p>
<ul>
<li>
<p dir="auto">සරලව කිව්වොත් AND, OR, NOT වලට තමා logical pperators කියන්නේ</p>
</li>
<li>
<p dir="auto"><strong>AND(ගුණ කිරීම)</strong></p>
</li>
</ul>
<pre><code>	x		y		output
	0		0		  0
	0		1		  0
	1		0		  0
	1		1		  1
</code></pre>
<ul>
<li><strong>OR(එකතු කිරීම)</strong></li>
</ul>
<pre><code>	x		y		output
	0		0		  0
	0		1		  1
	1		0		  1
	1		1		  1
</code></pre>
<ul>
<li><strong>NOT(ප්‍රතිවිරුද්ධ binary number එක)</strong></li>
</ul>
<pre><code>	x		output
	0		  1
	1		  0
</code></pre>
<ul>
<li>මෙම operators C programming වල භාවිතා වන්නේ මේ ආකාරයෙනි.</li>
</ul>
<pre><code>      Operator		                        Meaning													Example
	&amp;&amp;			සියලු කාරණා සත්‍ය නම් සත්‍ය වේනම්			((5 &gt; 3) &amp;&amp; (5 &lt; 7)). (5 &gt; 3) හා (5 &lt; 7) යන කාරණා දෙකම සත්‍ය වේ. එබැවින් output එක 1 වේ.
										          ((5 == 3) &amp;&amp; (5 &lt; 7)). (5 &lt; 7) සත්‍ය වුවත් (5 == 3) සත්‍ය නොවේ. එබැවින් output එක 0 වේ.
										          ((5 == 3) &amp;&amp; (5 &lt; 3)). (5 == 3) හා (5 &lt; 3) යන දෙකම අස්ත්‍ය වේ. එබැවින් output එක 0 වේ.
										
	||			සියලු කාරණා වලින් එකක් හෝ සත්‍ය වේනම්		((5 &gt; 3) &amp;&amp; (5 &lt; 7)). (5 &gt; 3) හා (5 &lt; 7) යන කාරණා දෙකම සත්‍ය වේ. එබැවින් output එක 1 වේ.
										         ((5 == 3) &amp;&amp; (5 &lt; 7)). (5 == 3) අසත්‍ය වුවත් (5 &lt; 7) සත්‍ය වේ. එබැවින් output එක 1 වේ.
										          ((5 == 3) &amp;&amp; (5 &lt; 3)). (5 == 3) හා (5 &lt; 3) යන දෙකම අස්ත්‍ය වේ. එබැවින් output එක 0 වේ.
											
	!			දී ඇති කාරණය සත්‍ය නම් එය අසත්‍යක් ලෙස ගනී	(!(5 == 3)). පහට තුන අසමාන හා කාරණය අසත්‍ය නමුත් එය සත්‍යක් ලෙස සලකයි. එබැවින් output එක 1 වේ.
												        (!(5 == 5)). පහට පහ සමාන හා කාරණය සත්‍ය නමුත් එය අසත්‍යක් ලෙස සලකයි. එබැවින් output එක 0 වේ.
</code></pre>
<ul>
<li>අපි දැන් logical operators භාවිතා කරලා programm එකක් ලියමු.</li>
</ul>
<pre><code>	#include &lt;stdio.h&gt;

	int main()
	{
		int ans;
		
		ans = (5 &gt; 3) &amp;&amp; (5 &lt; 7);
		printf("(5 &gt; 3) &amp;&amp; (5 &lt; 7)answer  = %d\n", ans);
		
		ans = (5 == 3) &amp;&amp; (5 &lt; 7);
		printf("(5 == 3) &amp;&amp; (5 &lt; 7)answer = %d\n", ans);
		
		ans = (5 == 3) &amp;&amp; (5 &lt; 3);
		printf("(5 == 3) &amp;&amp; (5 &lt; 3)answer = %d\n\n", ans);
		
		ans = (5 &gt; 3) || (5 &lt; 7);
		printf("(5 &gt; 3) || (5 &lt; 7)answer   = %d\n", ans);
		
		ans = (5 == 3) || (5 &lt; 7);
		printf("(5 == 3) || (5 &lt; 7)answer  = %d\n", ans);
		
		ans = (5 == 3) || (5 &lt; 3);
		printf("(5 == 3) || (5 &lt; 3)answer  = %d\n\n", ans);
		
		ans = !(5 == 3);
		printf("!(5 == 3)answer  = %d\n", ans);
		
		ans = !(5 == 5);
		printf("!(5 == 5)answer  = %d\n", ans);
	   
		return 0;
	}
</code></pre>
<ul>
<li>මෙය run කල පසු output එක වන්නේ</li>
</ul>
<pre><code>(5 &gt; 3) &amp;&amp; (5 &lt; 7)answer  = 1                                                                                                                
(5 == 3) &amp;&amp; (5 &lt; 7)answer = 0                                                                                                                
(5 == 3) &amp;&amp; (5 &lt; 3)answer = 0                                                                                                                
                                                                                                                                             
(5 &gt; 3) || (5 &lt; 7)answer   = 1                                                                                                               
(5 == 3) || (5 &lt; 7)answer  = 1                                                                                                               
(5 == 3) || (5 &lt; 3)answer  = 0                                                                                                               
                                                                                                                                             
!(5 == 3)answer  = 1                                                                                                                         
!(5 == 5)answer  = 0
</code></pre>
<ul>
<li>
<p dir="auto">මූලාශ්‍ර -: <a href="https://www.programiz.com/c-programming/c-operators" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.programiz.com/c-programming/c-operators</a></p>
</li>
<li>
<p dir="auto">C programm එකක් windows වල  run කරන විදිහ --&gt; <a href="https://bit.ly/2O6rLXR" target="_blank" rel="noopener noreferrer nofollow ugc">https://bit.ly/2O6rLXR</a></p>
</li>
</ul>
<p dir="auto">ඔබට අවශ්‍යනම් ඔබේ බ්‍රව්සර් එක හරහා online C programms run කරන්න පුලුවන්. එහෙම කරන්න පුලුවන් ලින්ක්ස් මන් පහතින් දාන්නම්</p>
<ul>
<li><a href="https://www.onlinegdb.com/online_c_compiler" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.onlinegdb.com/online_c_compiler</a></li>
<li><a href="https://www.tutorialspoint.com/compile_c_online.php" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.tutorialspoint.com/compile_c_online.php</a></li>
<li><a href="https://repl.it/languages/c" target="_blank" rel="noopener noreferrer nofollow ugc">https://repl.it/languages/c</a></li>
</ul>
<p dir="auto">සරලව මුල ඉදන්  C programming ඉගෙන ගන්න පුලුවන් හොදම site දෙකත් මන් දාන්නම්</p>
<ul>
<li><a href="https://www.geeksforgeeks.org/c-programming-language/" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.geeksforgeeks.org/c-programming-language/</a></li>
<li><a href="https://www.tutorialspoint.com/cprogramming/index.htm" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.tutorialspoint.com/cprogramming/index.htm</a></li>
</ul>
<p dir="auto">කලින් ලිපි වල වගේ මේ ලිපියෙත් ඉල්ලනවා අඩු පාඩු තිබ්බොත් පහලින් කමෙන්ට් එකක් දාන්න. තව වැඩි දියුණු වෙන්න ඕන ඒවා තියෙනවනම් ඒවත් දාන්න.</p>
]]></description><link>https://lankadevelopers.lk/topic/439/c-programming-ම-ල-ස-ට-ඉග-නගන-ම-part-3-operators</link><generator>RSS for Node</generator><lastBuildDate>Sat, 14 Mar 2026 05:11:45 GMT</lastBuildDate><atom:link href="https://lankadevelopers.lk/topic/439.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 25 Nov 2019 09:07:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C Programming මුල සිට ඉගෙනගනිමු (part 3 - Operators) on Tue, 26 Nov 2019 14:36:49 GMT]]></title><description><![CDATA[<p dir="auto">Keep it up bro</p>
]]></description><link>https://lankadevelopers.lk/post/2529</link><guid isPermaLink="true">https://lankadevelopers.lk/post/2529</guid><dc:creator><![CDATA[imadusanka]]></dc:creator><pubDate>Tue, 26 Nov 2019 14:36:49 GMT</pubDate></item><item><title><![CDATA[Reply to C Programming මුල සිට ඉගෙනගනිමු (part 3 - Operators) on Mon, 25 Nov 2019 10:25:27 GMT]]></title><description><![CDATA[<p dir="auto">supiri bro</p>
]]></description><link>https://lankadevelopers.lk/post/2522</link><guid isPermaLink="true">https://lankadevelopers.lk/post/2522</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Mon, 25 Nov 2019 10:25:27 GMT</pubDate></item><item><title><![CDATA[Reply to C Programming මුල සිට ඉගෙනගනිමු (part 3 - Operators) on Mon, 25 Nov 2019 10:01:48 GMT]]></title><description><![CDATA[<p dir="auto">Niyamai bro. Digatama karamu wade . Supiri</p>
]]></description><link>https://lankadevelopers.lk/post/2521</link><guid isPermaLink="true">https://lankadevelopers.lk/post/2521</guid><dc:creator><![CDATA[root]]></dc:creator><pubDate>Mon, 25 Nov 2019 10:01:48 GMT</pubDate></item></channel></rss>