<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MaxoTech Blog &#187; Programming</title>
	<atom:link href="http://maxotek.net/blog/tag/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://maxotek.net/blog</link>
	<description>Technology Blog</description>
	<lastBuildDate>Wed, 29 Jun 2011 07:44:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Programming Tutorial &#8211; Lesson 1: Instructions</title>
		<link>http://maxotek.net/blog/programming-tutorial-lesson-1-instructions-t65.html</link>
		<comments>http://maxotek.net/blog/programming-tutorial-lesson-1-instructions-t65.html#comments</comments>
		<pubDate>Tue, 15 Jul 2008 14:19:36 +0000</pubDate>
		<dc:creator>partho</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://maxotek.net/blog/?p=65</guid>
		<description><![CDATA[Programming or coding as some call it, is the backbone of the software industry. It comprises of writing Programs &#8211; lines of instructions. These instructions are fed to the computer for processing and output. Sounds simple, doesn&#8217;t it? Well, trust me, its no Rocket science. But, I have seen students think of it as such [...]]]></description>
			<content:encoded><![CDATA[<p>Programming or coding as some call it, is the backbone of the software industry. It comprises of writing Programs &#8211; lines of instructions. These instructions are fed to the computer for processing and output. Sounds simple, doesn&#8217;t it? Well, trust me, its no Rocket science. But, I have seen students think of it as such and ultimately scraping the entire idea of learning how to program.</p>
<p>Many courses being taught at the higher levels of education, today, don&#8217;t start off at the absolute beginning of Programming. For a person who has no prior experience in programming, knowing the basics is very essential. In these series of tutorials, I will take you on the journey that I did, back at school and learned whatever little of Programming, that I know today. We will begin by using <a href="http://en.wikipedia.org/wiki/Logo_(programming_language)">LOGO</a>, the programming language. I believe it will impart good insights into the bare-bones of Programming.</p>
<p>We need to know a few terms before we begin using LOGO. Don&#8217;t worry these are no jargons, only the bare minimals.</p>
<h5>Instruction</h5>
<p>An instruction is a command to the computer which causes a certain action to be performed.</p>
<h5>Program</h5>
<p>Lines of instruction that are executed or processed by the computer one by one.</p>
<p>We will need the MSWLogo software to go any further. You can get it from <a href="http://www.softronix.com/download/mswlogo65.exe">here</a>. Once installed, start Microsoft Windows Logo from the start menu. The application is composed of a pair of Windows. The upper one with a white background and a Triangle in the middle is your drawing area.</p>
<p><img src="/images/blog/pgming_tut_lesson_1_logo_main_window.png" alt="" /></p>
<p>The lower one titled <strong>Commander</strong> is where you will write the instructions and feed it to the computer.</p>
<p><img src="/images/blog/pgming_tut_lesson_1_logo_commander_window.png" alt="" /></p>
<p>LOGO is a programming language that works on turtle graphics. A triangle shaped object (the Turtle) is used to draw lines &amp; curves on the screen. To draw these lines you instruct the turtle to move forward or backward and while doing so, it leaves a line behind. Try typing the instruction given below in the textbox to the right of the Execute button in the Commander window and then press enter or click on Execute.</p>

<div class="wp_syntax"><div class="code"><pre class="logo"><span style="color: #993333; font-weight: bold;">FORWARD</span> <span style="color: #cc66cc;">50</span></pre></div></div>

<p><img src="/images/blog/pgming_tut_lesson_1_example_1.png" alt="" /></p>
<p>As you can see, the turtle moved upward, or forward in its own orientation, leaving behind the black line. The instruction we provided is composed of two parts: <strong>FORWARD</strong> &#8211; the command to make the turtle go forward and <strong>50</strong> the distance it moved forward by. Now type in the following command and press enter.</p>

<div class="wp_syntax"><div class="code"><pre class="logo"><span style="color: #993333; font-weight: bold;">BACK</span> <span style="color: #cc66cc;">100</span></pre></div></div>

<p><img src="/images/blog/pgming_tut_lesson_1_example_2.png" alt="" /></p>
<p>The turtle comes back 100 units drawing over the old line and extending it by 50 at the bottom. Unlike in real life, an overwrite on the same line doesn&#8217;t make the line thicker. Let us try some more tricks, type in the following instruction and press enter.</p>

<div class="wp_syntax"><div class="code"><pre class="logo"><span style="color: #993333; font-weight: bold;">RIGHT</span> <span style="color: #cc66cc;">90</span></pre></div></div>

<p><img src="/images/blog/pgming_tut_lesson_1_example_3.png" alt="" /></p>
<p>This makes the turtle turn right (clockwise) by 90 degrees allowing us to draw a horizontal line. The <strong>RIGHT</strong> command is followed by an angle in degrees. The turtle can turn in any direction with this. But, we have a command to make it turn the other way too &#8211; the <strong>LEFT</strong> command. Now execute the following command.</p>

<div class="wp_syntax"><div class="code"><pre class="logo"><span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">100</span></pre></div></div>

<p><img src="/images/blog/pgming_tut_lesson_1_example_4.png" alt="" /></p>
<p>FD command is an alias (another name) for the FORWARD command and it provides the exact same functionality. The Aliases for the commands are given in the table below.</p>
<table class="joomlaTable" border="0">
<tbody>
<tr>
<th>Command</th>
<th>Alias</th>
</tr>
<tr>
<td>FORWARD</td>
<td>FD</td>
</tr>
<tr>
<td>BACK</td>
<td>BK</td>
</tr>
<tr>
<td>RIGHT</td>
<td>RT</td>
</tr>
<tr>
<td>LEFT</td>
<td>LT</td>
</tr>
</tbody>
</table>
<p>Lets complete our diagram by executing these instructions one by one.</p>

<div class="wp_syntax"><div class="code"><pre class="logo"><span style="color: #993333; font-weight: bold;">LT</span> <span style="color: #cc66cc;">90</span>
<span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">100</span>
<span style="color: #993333; font-weight: bold;">RT</span> <span style="color: #cc66cc;">270</span>
<span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">100</span></pre></div></div>

<p><img src="/images/blog/pgming_tut_lesson_1_example_5.png" alt="" /></p>
<p>There we have it; Mr. Paniter has drawn us our very own Square. The third instruction, RT 270 can be replaced by an equivalent LT 90. You can provide a negative value to the FD and BK commands to make them go the opposite way. You can even give negative angles or angles greater than 360 degrees and make the poor turtle go round and round (apparently, the slow dude turns so fast, we won&#8217;t be able to see it spin its head off, or maybe it has some sharp geomerty skills and does only one round).</p>
<h5>Drawing dashed lines or discontinous figures</h5>
<p>Did I mention how the turtle goes about drawing all those lines? The guy uses a pen! Not your average pen that runs out of ink every second day, though. Just as we raise our pen in between writing two words, you can make the turtle raise its pen and move to some place else. During this movement, it won&#8217;t draw a line. We use the <strong>PENUP</strong> command to raise the pen up. While in this state, moving in no direction will result in a line being drawn. To lower the pen use the <strong>PENDOWN </strong>command. When the pen has been lowered, lines will again begin to be drawn following an FD OR BK command (unless offcourse if you move it by 0 units).</p>
<p><strong>Note:</strong> <em>PENUP &amp; PENDOWN commands are not followed by any numbers. You can also use their aliases PU &amp; PD.</em></p>
<p>Clear the screen using the <strong>CS</strong> command and execute the following instruction to draw a dashed line.</p>

<div class="wp_syntax"><div class="code"><pre class="logo"><span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">30</span>
<span style="color: #993333; font-weight: bold;">PU</span>
<span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">30</span>
<span style="color: #993333; font-weight: bold;">PD</span>
<span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">30</span>
<span style="color: #993333; font-weight: bold;">PU</span>
<span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">30</span>
<span style="color: #993333; font-weight: bold;">PD</span>
<span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">30</span></pre></div></div>

<p><img src="/images/blog/pgming_tut_lesson_1_example_6.png" alt="" /></p>
<h5>Chaining Instuctions in one line</h5>
<p>You can write multiple instuctions in one line. For example, the dashed line can be drawn using the following command.</p>

<div class="wp_syntax"><div class="code"><pre class="logo">CS <span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">30</span> <span style="color: #993333; font-weight: bold;">PU</span> <span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">30</span> <span style="color: #993333; font-weight: bold;">PD</span> <span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">30</span> <span style="color: #993333; font-weight: bold;">PU</span> <span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">30</span> <span style="color: #993333; font-weight: bold;">PD</span> <span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">30</span></pre></div></div>

<h5>The REPEAT command</h5>
<p>The REPEAT command is used to repeat a series of instructions a given number of times. For example, you can use the following code to draw a square.</p>

<div class="wp_syntax"><div class="code"><pre class="logo"><span style="color: #993333; font-weight: bold;">REPEAT</span> <span style="color: #cc66cc;">4</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">100</span> <span style="color: #993333; font-weight: bold;">RT</span> <span style="color: #cc66cc;">90</span><span style="color: #66cc66;">&#93;</span></pre></div></div>

<p>The dashed line can be drawn with the REPEAT command.</p>

<div class="wp_syntax"><div class="code"><pre class="logo">CS <span style="color: #993333; font-weight: bold;">REPEAT</span> <span style="color: #cc66cc;">3</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">PD</span> <span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">30</span> <span style="color: #993333; font-weight: bold;">PU</span> <span style="color: #993333; font-weight: bold;">FD</span> <span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#93;</span></pre></div></div>

<p>The REPEAT command is followed by a number specifying how many times to repeat the steps and the set of instructions to be repeated. The instructions to be repeated are enclosed between the square brackets [ and ].</p>
<h5>Syntax</h5>
<p>Syntax is the grammar of instructions. Every command has a syntax. For example, the FD command is followed by a number, whereas the syntax of PU &amp; PD commands don&#8217;t contain any numbers following them. We can express these syntax in general forms:-</p>
<table class="joomlaTable" border="0">
<tbody>
<tr>
<th>Command</th>
<th>Syntax</th>
</tr>
<tr>
<td>FD</td>
<td>FD distance</td>
</tr>
<tr>
<td>RT</td>
<td>RT angle</td>
</tr>
<tr>
<td>REPEAT</td>
<td>REPEAT count [ instructions ]</td>
</tr>
</tbody>
</table>
<p>Syntax helps us understand the structure of the command, how its written/used. Every Programming language has its own set of commands, statements &amp; their corresponding syntaxes.</p>
<p><strong>Note:</strong> <em>Description of statements is not relevant to the LOGO language. We will go through it in a later tutorial.</em></p>
<p>In this tutorial we have seen what instructions are and how to write them for the LOGO language. The LOGO language offers more than what we have covered here. But, our aim was only to get familiar with instructions. In the next tutorial we will be continuing our journey into the world of Programming.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxotek.net/blog/programming-tutorial-lesson-1-instructions-t65.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Tutorial : Lesson 02 &#8211; Variables &amp; Operators</title>
		<link>http://maxotek.net/blog/c-tutorial-lesson-02-variables-operators-t28.html</link>
		<comments>http://maxotek.net/blog/c-tutorial-lesson-02-variables-operators-t28.html#comments</comments>
		<pubDate>Mon, 09 Apr 2007 12:41:57 +0000</pubDate>
		<dc:creator>partho</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://maxotek.net/blog/?p=28</guid>
		<description><![CDATA[Variables A Variable is a named location that stores a value. Although variables are physically stored in the RAM, their actual memory address is not known to the programmer. We can use the variables via the name we give them. These are the rules for naming a variable:- The name must begin with a letter [...]]]></description>
			<content:encoded><![CDATA[<div class="tutnav"></div>
<h5 id="cVariables">Variables</h5>
<p>A Variable is a named location that stores a value. Although variables are physically stored in the RAM, their actual memory address is not known to the programmer. We can use the variables via the name we give them. These are the rules for naming a variable:-
<ul>
<li>The name must begin with a letter or an underscore &#038; can be followed by a sequence of letters (A-Z), digits (0-9) or underscore (_)
</li>
<li>Special Characters such as ? &#8211;   * / \ ! @ # $ % ^ ( ) [ ] { } , ; : . cannot be used in the variable name.
</li>
<li>A variable name must not be the same as a reserved keyword such as using, public, etc.
</li>
<li>The name can contain any number of the allowed characters
</li>
<li>Variables with the same scope cannot have the same name
</li>
</ul>
<p><i>Note: C# being a case-sensitive language, two variables such as var1 and Var1 would be different.</i></p>
<p>Any Variable has a type associated with it, which basically restricts the type of value it can store. The table below shows the Data types available in C#, the size they occupy in the memory and the values they can contain.</p>
<table width="85%" align="center" border="2" class="joomlaTable">
<tr>
<h3>
<th>Type</th>
<th>Size</th>
<th>Range of values</th>
</h3>
</tr>
<tr>
<td>char</td>
<td>2</td>
<td>0 and 65536</td>
</tr>
<tr>
<td>int</td>
<td>4</td>
<td>-2,147,483,648 and 2,147,483,647</td>
</tr>
<tr>
<td>float</td>
<td>4</td>
<td>-3.402823E+38 and -1.401298E-45 (For Negative Values)<br />
1.401298E-45 and 3.402823E+38 (For Positive values Values)</td>
</tr>
<tr>
<td>double</td>
<td>8</td>
<td>-1.79769313486232E308 and 4.94065645841247E-324 (For Negative Values)<br />
4.94065645841247E-324 and 1.79769313486232E308 (For Positive values Values)</td>
</tr>
<tr>
<td>bool</td>
<td>1</td>
<td>true or false</td>
</tr>
<tr>
<td>string</td>
<td>Depends on length of the string</td>
<td>0-2 million Unicode Characters</td>
</tr>
</table>
<p><br/></p>
<h5>Variable Declaration</h5>
<p>Before we can use a variable, we need to declare it. Declaration of variables are done using the syntax:-<br />
<strong>&lt;Data Type&gt; &lt;Variable Name&gt;;</strong></p>
<p>For Example:-</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="csharp"><span style="color: #FF0000;">int</span> Age<span style="color: #008000;">;</span>
<span style="color: #FF0000;">char</span> Sex<span style="color: #008000;">;</span>
<span style="color: #FF0000;">string</span> Name<span style="color: #008000;">;</span>
<span style="color: #FF0000;">bool</span> IsMarried<span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Variables of the same data type can also be declared using the syntax:-<br />
<strong>&lt;Data Type&gt; &lt;Variable 1&gt;, &lt;Variable 2&gt;, .. and so on;<br />
</strong></p>
<p>Example:-</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp"><span style="color: #FF0000;">int</span> Age, RollNum<span style="color: #008000;">;</span></pre></td></tr></table></div>

<h5>Initialization</h5>
<p>While declaring a variable, it is possible to assign an initial value to it. This operation is called Initialization and it has the following syntax:-<br />
<strong>&lt;Data Type&gt; &lt;Variable Name&gt; = &lt;Value&gt;;</strong></p>
<p>Example:-</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="csharp"><span style="color: #FF0000;">int</span> Age <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">char</span> Sex <span style="color: #008000;">=</span> <span style="color: #666666;">'M'</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">string</span> Name <span style="color: #008000;">=</span> <span style="color: #666666;">'Max Steel'</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">bool</span> IsMarried <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Multiple variables of the same data type can also be initialized in a single line of code using the syntax:-<br />
<strong>&lt;data type&gt; &lt;variable 1&gt; = &lt;value&gt;, &lt;variable 2&gt; = &lt;value&gt;;</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp"><span style="color: #FF0000;">int</span> Age <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>, RollNum <span style="color: #008000;">=</span> <span style="color: #FF0000;">69</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<h5>Value Types</h5>
<p>Values can be stored in variables by two methods which are: by value and by reference. Value types store the supplied value directly in the memory whereas reference types store a reference to the memory where the actual value is located. The benefit of the reference type is that changes made to any alias of the variable will reflect across all of its aliases.</p>
<h5>Accepting Values in Variables</h5>
<p>To input values from the user at runtime, we use the <strong>Console.ReadLine()</strong> function. For Example:- <strong>string FirstName = Console.ReadLine();</strong> The above statement would declare a string variable FirstName and store the value retrieved from the user in it.</p>
<p>Note: <strong>Console.ReadLine()</strong> returns value as a string. Therefore, one must use type casting to convert the value to the required type. We use the member functions of the <strong>Convert</strong> class to do this. For Example: <strong>int Age = Convert.ToInt32(Console.ReadLine());</strong>. Similarly, there are other functions such as <strong>ToChar()</strong>, <strong>ToString</strong>, etc for conversion to other data types.</p>
<h5 id="cOperators">Operators</h5>
<p>Similar to mathematics, every programming language has its own set of operators, be it arithmetic or logical. Operators enable us to perform operations on 1 or more values (operands) and calculate the result.</p>
<h5>Usage</h5>
<p>Depending on the number of operands they take, operators can be either unary or binary.<br />
The use of an operator takes one of the following form:-</p>
<p><strong>Unary Usage</strong></p>
<ul>
<li>
&lt;Operator&gt; &lt;Operand&gt;<br />
Example: ++A;
</li>
<li>
&lt;Operand&gt; &lt;Operator&gt;<br />
Example: A++;
</li>
</ul>
<p><strong>Binary Usage</strong></p>
<ul>
<li>
&lt;Operand 1&gt; &lt;Operator&gt; &lt;Operand 2&gt;<br />
Example: A + B;
</li>
</ul>
<h5>Classification</h5>
<p>The operators in C# can be classified as follows:-</p>
<p><strong>Arithmetic operators</strong> &#8211; Just what the name suggests, these operators are used to perform arithmetic operations.</p>
<table width="90%" align="center" border="2" class="joomlaTable">
<tr>
<th>Operator</th>
<th>Usage</th>
<th>Utility</th>
<th>Type</th>
</tr>
<tr>
<td>+</td>
<td>A + B</td>
<td>Add two numbers</td>
<td>Binary</td>
</tr>
<tr>
<td>-</td>
<td>A &#8211; B</td>
<td>Subtract a number from another </td>
<td>Binary</td>
</tr>
<tr>
<td>*</td>
<td>A * B </td>
<td>Multiply two numbers </td>
<td>Binary</td>
</tr>
<tr>
<td>/</td>
<td>A / B </td>
<td>Divide a number with another </td>
<td>Binary</td>
</tr>
<tr>
<td>%</td>
<td>A % B </td>
<td>Remainder of the operation A / B </td>
<td>Binary</td>
</tr>
</table>
<p><strong>Arithmetic Assignment Operators</strong> &#8211; These can be considered as shortcuts as they are used to perform both arithmetic and assignment operations in a single step.</p>
<table width="90%" align="center" border="2" class="joomlaTable">
<tr>
<th>Operator</th>
<th>Usage</th>
<th>Utility</th>
<th>Type</th>
</tr>
<tr>
<td>=</td>
<td>A = 69 </td>
<td>Store the value 69 into A </td>
<td>Binary</td>
</tr>
<tr>
<td>+=</td>
<td>A += B </td>
<td>Equivalent to A = A + B </td>
<td>Binary</td>
</tr>
<tr>
<td>-=</td>
<td>A -= B </td>
<td>Equivalent to A = A &#8211; B </td>
<td>Binary</td>
</tr>
<tr>
<td>*=</td>
<td>A *= B </td>
<td>Equivalent to A = A * B </td>
<td>Binary</td>
</tr>
<tr>
<td>/=</td>
<td>A /= B </td>
<td>Equivalent to A = A / B </td>
<td>Binary</td>
</tr>
<tr>
<td>%=</td>
<td>A %= B </td>
<td>Equivalent to A = A % B </td>
<td>Binary</td>
</tr>
</table>
<p><strong>Increment / Decrement Operators</strong> &#8211; These operators are used to increment or decrement the value of an operand by 1.</p>
<table width="90%" align="center" border="2" class="joomlaTable">
<tr>
<th>Operator</th>
<th>Usage</th>
<th>Utility</th>
<th>Type</th>
</tr>
<tr>
<td>++</td>
<td>++A or A++ </td>
<td>
<p>Increments the value of A by 1 </p>
</td>
<td>Unary</td>
</tr>
<tr>
<td>
<pre>--</pre>
</td>
<td>
<pre>--A or A--</pre>
</td>
<td>Decrements the value of A by 1 </td>
<td>Unary</td>
</tr>
</table>
<p><strong>Difference between Pre &#038; Post Increment/Decrement</strong><br />
Consider the following code snippet:-</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp"><span style="color: #FF0000;">int</span> A <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">int</span> B <span style="color: #008000;">=</span> A<span style="color: #008000;">++;</span>
<span style="color: #FF0000;">int</span> C <span style="color: #008000;">=</span> <span style="color: #008000;">++</span>A<span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>At the very first line, we have used the Arithmetic Assignment operator, <strong>=</strong> to assign the value of 0 to A. In the proceeding lines we have used both Pre &#038; Post increment. At line 2 <strong>int B = A++;</strong> the operation being post increment, the value of A i.e 0 is assigned to B followed by the increment of A&#8217;s value. At line 3 <strong>int C = ++A;</strong> the current value of A, i.e. 1 is incremented by 1 following which the new value of A is assigned to C. Therefore, the value of A = 2, B = 0 and C = 2.</p>
<p>What will be the output of the following code?</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp"><span style="color: #FF0000;">int</span> A <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">int</span> B <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>A<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">--</span>A<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Value of B = {0}&quot;</span>, B<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>At line, 1, A gets initialized to 5. The next line is a bit tricky. Here, The RHS should be evaluated like 5 + 4 because A++ is post increment and this operation should occur after the line of statement. But, this is not the case, instead it takes place in the same line but after the evaluation of the sub-expression (A++). Hence, the expression will be evaluated as 5 + 5 and the output will be 10.</p>
<p><strong>Comparison Operators</strong> &#8211; These operators are to compare two values and return the result as either <strong>&#8216;true&#8217;</strong> or <strong>&#8216;false&#8217;</strong>.</p>
<table width="90%" align="center" border="2" class="joomlaTable">
<tr>
<th>Operator</th>
<th>Usage</th>
<th>Utility</th>
<th>Type</th>
</tr>
<tr>
<td>&lt;</td>
<td>A &lt; B </td>
<td>
<p>Compares if A is less than B </p>
</td>
<td>Binary</td>
</tr>
<tr>
<td>&gt;</td>
<td>A &gt; B </td>
<td>Compares if B is less than A </td>
<td>Binary</td>
</tr>
<tr>
<td>&lt;=</td>
<td>A &lt;= B </td>
<td>Compares if A is less than or equal to B </td>
<td>Binary</td>
</tr>
<tr>
<td>&gt;=</td>
<td>A &gt;= B </td>
<td>Compares if A is greater than or equal to B </td>
<td>Binary</td>
</tr>
<tr>
<td>==</td>
<td>A == B </td>
<td>Compares if A is equal to B </td>
<td>Binary</td>
</tr>
<tr>
<td>!=</td>
<td>A != B </td>
<td>Compares if A is not equal  to B </td>
<td>Binary</td>
</tr>
</table>
<p><strong>Logical Operators</strong> &#8211; These operators are used to perform logical operations and return the result as either <strong>&#8216;true&#8217;</strong> or <strong>&#8216;false&#8217;</strong>.</p>
<table width="90%" align="center" border="2" class="joomlaTable">
<tr>
<th>Operator</th>
<th>Usage</th>
<th>Utility</th>
<th>Type</th>
</tr>
<tr>
<td>&amp;&amp;</td>
<td>A &amp;&amp; B </td>
<td>
<p>Returns true if Both A and B are true </p>
</td>
<td>Binary</td>
</tr>
<tr>
<td>||</td>
<td>A || B </td>
<td>Return true if either A or B are true </td>
<td>Binary</td>
</tr>
<tr>
<td>!</td>
<td> !A </td>
<td>Returns True if A is false </td>
<td>Unary</td>
</tr>
<tr>
<td>^</td>
<td>A ^ B </td>
<td>Returns true when A and B do not match i.e one is true and the other is false </td>
<td>Binary</td>
</tr>
</table>
<p><br/></p>
<h5>Displaying Variables</h5>
<p>We us the WriteLine method to display the value stored in variables.</p>
<p><strong>Displaying Single Variable</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="csharp"><span style="color: #FF0000;">int</span> A <span style="color: #008000;">=</span> <span style="color: #FF0000;">6</span><span style="color: #008000;">;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>A<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p><strong>Displaying Multiple Variables</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="csharp"><span style="color: #FF0000;">int</span> A <span style="color: #008000;">=</span> <span style="color: #FF0000;">6</span>, B <span style="color: #008000;">=</span> <span style="color: #FF0000;">9</span><span style="color: #008000;">;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0},{1}&quot;</span>, A, B<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Notice the code <strong>&#8220;{0},{1}&#8221;</strong>. This is the format for the output to be generated by WriteLine. Since, we are displaying two variables, we need to specify the format accordingly. Here {0} and {1} represent where the proceeding variables A &#038; B will be displayed. Now take a look at the following code snippet:-</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="csharp"><span style="color: #FF0000;">int</span> A <span style="color: #008000;">=</span> <span style="color: #FF0000;">6</span>, B <span style="color: #008000;">=</span> <span style="color: #FF0000;">9</span><span style="color: #008000;">;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;The value of A = {0} and B = {1}&quot;</span>, A, B<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>The output of these lines would be: <strong>The value of A = 6 and B = 9</strong>. As you can see, the {0} and {1} are replaced by the variables A and B. <strong>0</strong> and <strong>1</strong> correspond to the index of the variables following the format, starting from 0.</p>
<h5 id="cComments">Comments</h5>
<p>Software applications are made by a group of coders. Each one of them handles various aspects of the application. Its important to write descriptive texts in order to help other coders understand, the mechanism of the codes you have written. We use comments denoted by // or /* and */ for this very purpose. Example usage:-</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp"><span style="color: #008080; font-style: italic;">// This is a comment</span>
<span style="color: #008080; font-style: italic;">/* These are two lines
of comments */</span></pre></td></tr></table></div>

<p>Note: The compiler ignores all comment entries. // is used for single line of comment while /* and */ are used for multiple lines.</p>
<h5>What&#8217;s in a Semicolon?</h5>
<p>Whitespace except when used inside quotes, is ignored in C#. All statements in C# are terminated by using the semicolon. This allow spanning of codes across multiple lines.</p>
<p>The following lines of code are functionally equivalent.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp"><span style="color: #FF0000;">int</span> A <span style="color: #008000;">=</span> <span style="color: #FF0000;">6</span>, B <span style="color: #008000;">=</span> <span style="color: #FF0000;">9</span><span style="color: #008000;">;</span> Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;A   B = {0}&quot;</span>, A   B<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> Console.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp"><span style="color: #FF0000;">int</span> A <span style="color: #008000;">=</span> <span style="color: #FF0000;">6</span>, B <span style="color: #008000;">=</span> <span style="color: #FF0000;">9</span><span style="color: #008000;">;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;The sum of {0} and {1} = {2}&quot;</span>, A, B, A   B<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Console.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<div class="tutnav"></div>
]]></content:encoded>
			<wfw:commentRss>http://maxotek.net/blog/c-tutorial-lesson-02-variables-operators-t28.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

