<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Arya Farzan&#039;s Blog</title>
	<atom:link href="http://aryafarzan.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://aryafarzan.wordpress.com</link>
	<description>Arya Farzan&#039;s weblog</description>
	<lastBuildDate>Tue, 06 Apr 2010 06:11:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='aryafarzan.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Arya Farzan&#039;s Blog</title>
		<link>http://aryafarzan.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://aryafarzan.wordpress.com/osd.xml" title="Arya Farzan&#039;s Blog" />
	<atom:link rel='hub' href='http://aryafarzan.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Dynamic Memory Management Overview with C++ 1</title>
		<link>http://aryafarzan.wordpress.com/2010/04/06/dynamic-memory-management-overview-with-c-1/</link>
		<comments>http://aryafarzan.wordpress.com/2010/04/06/dynamic-memory-management-overview-with-c-1/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 06:11:31 +0000</pubDate>
		<dc:creator>aryafarzan</dc:creator>
				<category><![CDATA[OOP344]]></category>

		<guid isPermaLink="false">http://aryafarzan.wordpress.com/?p=58</guid>
		<description><![CDATA[Allocating memory Dynamic Memory allocation is done by using the keyword &#8220;new&#8221; in c++. When creating dynamic memory a pointer is always needed.  Let us start by looking at one very simple example. (the code below does not deallocate memory which I will get to next.) main(){ int* iPtr; iPtr = new int; *iPtr = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=58&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Allocating memory</h3>
<p>Dynamic Memory allocation is done by using the keyword &#8220;new&#8221; in c++. When creating dynamic memory a pointer is <strong>always</strong> needed.  Let us start by looking at one very simple example. (the code below does not deallocate memory which I will get to next.)</p>
<blockquote><address>main(){</address>
<address> int* iPtr;<br />
iPtr = new int;<br />
*iPtr = 10 </address>
<address> cout &lt;&lt; *iPtr &lt;&lt; endl </address>
<address>}</address>
</blockquote>
<p>so there you have it, a simple dynamically allocated int. The program above does not give us any advanges, but I used it since its a good example for learning purposes.</p>
<h3>Deallocating memory</h3>
<p>It is very important to give the memory back to the OS after we are done with the memory we need. Memory is given back to the OS by using the keyword &#8220;delete&#8221;. It is very simple to use, in the example I did not deallocate memory back to the OS, which makes it unusable until the OS is restarted.  Here is an modified version of the program above which deallocates memory.</p>
<blockquote><address>main(){</address>
<address>int* iPtr;<br />
iPtr = new int;<br />
*iPtr = 10</address>
<address>cout &lt;&lt; *iPtr &lt;&lt; endl</address>
<address>delete *iPtr //simply remove the allocated memory pointed by *iPtr</address>
<address>}</address>
</blockquote>
<address><span style="font-style:normal;">Keep in mind that &#8220;delete *iPtr&#8221; does not delete the pointer, but it deletes what is it pointing to.</span></address>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aryafarzan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aryafarzan.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aryafarzan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aryafarzan.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aryafarzan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aryafarzan.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aryafarzan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aryafarzan.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aryafarzan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aryafarzan.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aryafarzan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aryafarzan.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aryafarzan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aryafarzan.wordpress.com/58/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=58&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aryafarzan.wordpress.com/2010/04/06/dynamic-memory-management-overview-with-c-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>43.751000 -79.443000</georss:point>
		<geo:lat>43.751000</geo:lat>
		<geo:long>-79.443000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2c71ae2845df28dbc9279c89f310648d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aryafarzan</media:title>
		</media:content>
	</item>
		<item>
		<title>Function Templates Example</title>
		<link>http://aryafarzan.wordpress.com/2010/04/06/function-templates-example/</link>
		<comments>http://aryafarzan.wordpress.com/2010/04/06/function-templates-example/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 05:52:55 +0000</pubDate>
		<dc:creator>aryafarzan</dc:creator>
				<category><![CDATA[OOP344]]></category>

		<guid isPermaLink="false">http://aryafarzan.wordpress.com/?p=53</guid>
		<description><![CDATA[It is common to see functions that do almost the same thing but for different data types. We don&#8217;t need to write that code many times and just change the data types. The correct solution is to use function templates. I have written a swap function to demonstrate the use of function templates. template &#60;template [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=53&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It is common to see functions that do almost the same thing but for different data types. We don&#8217;t need to write that code many times and just change the data types. The correct solution is to use function templates.  I have written a swap function to demonstrate the use of function templates.</p>
<blockquote><p>template &lt;template T&gt;<br />
void swap(T a, T b){<br />
T temp;<br />
temp = a;<br />
a = b;<br />
b = temp;<br />
}</p></blockquote>
<p>we the function template above, we can pass it an int or float and the compiler will automatically create separate functions as needed.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aryafarzan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aryafarzan.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aryafarzan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aryafarzan.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aryafarzan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aryafarzan.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aryafarzan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aryafarzan.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aryafarzan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aryafarzan.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aryafarzan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aryafarzan.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aryafarzan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aryafarzan.wordpress.com/53/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=53&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aryafarzan.wordpress.com/2010/04/06/function-templates-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>43.751000 -79.443000</georss:point>
		<geo:lat>43.751000</geo:lat>
		<geo:long>-79.443000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2c71ae2845df28dbc9279c89f310648d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aryafarzan</media:title>
		</media:content>
	</item>
		<item>
		<title>C++ Reference Operator</title>
		<link>http://aryafarzan.wordpress.com/2010/03/19/51/</link>
		<comments>http://aryafarzan.wordpress.com/2010/03/19/51/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 06:14:12 +0000</pubDate>
		<dc:creator>aryafarzan</dc:creator>
				<category><![CDATA[OOP344]]></category>

		<guid isPermaLink="false">http://aryafarzan.wordpress.com/2010/03/19/51/</guid>
		<description><![CDATA[Reference is a C++ feature, it is not available in the C programming language. A reference is less powerful but safer than the pointer. Reference is having two names for the same variable. Let us start by looking at some examples. int A = 5; int&#38; rA = A; cout &#60;&#60; rA &#60;&#60; endl; A [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=51&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Reference is a C++ feature, it is not available in the C programming language. A reference is less powerful but safer than the pointer. Reference is having two names for the same variable. Let us start by looking at some examples.</p>
<blockquote><p>int A = 5;<br />
int&amp; rA = A;</p>
<p>cout &lt;&lt; rA &lt;&lt; endl;</p>
<p>A = 7;</p>
<p>cout &lt;&lt; rA &lt;&lt; endl;</p></blockquote>
<p>Output:</p>
<blockquote><address>5</address>
<address>7</address>
</blockquote>
<p>No matter which variable&#8217;s value gets changed both A and rA change.</p>
<p>References can be used to replace pointers in some cases. As you may recall functions in c/c++ can only return one value and programmers use pointers in order to get around that! References can be used instead of pointers and you do not have to use the * operator in your functions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aryafarzan.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aryafarzan.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aryafarzan.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aryafarzan.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aryafarzan.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aryafarzan.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aryafarzan.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aryafarzan.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aryafarzan.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aryafarzan.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aryafarzan.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aryafarzan.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aryafarzan.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aryafarzan.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=51&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aryafarzan.wordpress.com/2010/03/19/51/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>43.751000 -79.443000</georss:point>
		<geo:lat>43.751000</geo:lat>
		<geo:long>-79.443000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2c71ae2845df28dbc9279c89f310648d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aryafarzan</media:title>
		</media:content>
	</item>
		<item>
		<title>Passing arguments to a C program from terminal</title>
		<link>http://aryafarzan.wordpress.com/2010/02/21/passing-arguments-to-a-c-program-from-terminal/</link>
		<comments>http://aryafarzan.wordpress.com/2010/02/21/passing-arguments-to-a-c-program-from-terminal/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 00:51:18 +0000</pubDate>
		<dc:creator>aryafarzan</dc:creator>
				<category><![CDATA[OOP344]]></category>

		<guid isPermaLink="false">http://aryafarzan.wordpress.com/?p=47</guid>
		<description><![CDATA[Have you ever wondered how some UNIX commands take arguments? It can be done very easily with C. You can code the rm, cp, ect commands in no time. Here is a sample code which you can use to understand passing arguments. int main(int argc, char* argv[]){ int i; for(i = 0;i&#60;argc; i++){ printf(&#34;%d: %s\n&#34;, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=47&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Have you ever wondered how some UNIX commands take arguments? It can be done very easily with C.</p>
<p>You can code the rm, cp, ect commands in no time. Here is a sample code which you can use to understand passing arguments.</p>
<pre>
int main(int argc, char* argv[]){
  int i;
  for(i = 0;i&lt;argc; i++){
    printf(&quot;%d: %s\n&quot;, i+1, argv[i]);
  }
  return 0;
}</pre>
<p>argc is the number of arguments being passed in, and argv is a char pointer array which has the arguments.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aryafarzan.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aryafarzan.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aryafarzan.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aryafarzan.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aryafarzan.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aryafarzan.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aryafarzan.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aryafarzan.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aryafarzan.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aryafarzan.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aryafarzan.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aryafarzan.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aryafarzan.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aryafarzan.wordpress.com/47/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=47&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aryafarzan.wordpress.com/2010/02/21/passing-arguments-to-a-c-program-from-terminal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>43.751000 -79.443000</georss:point>
		<geo:lat>43.751000</geo:lat>
		<geo:long>-79.443000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2c71ae2845df28dbc9279c89f310648d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aryafarzan</media:title>
		</media:content>
	</item>
		<item>
		<title>enum intro in C</title>
		<link>http://aryafarzan.wordpress.com/2010/02/20/enum-in-c/</link>
		<comments>http://aryafarzan.wordpress.com/2010/02/20/enum-in-c/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 23:56:56 +0000</pubDate>
		<dc:creator>aryafarzan</dc:creator>
				<category><![CDATA[OOP344]]></category>

		<guid isPermaLink="false">http://aryafarzan.wordpress.com/?p=41</guid>
		<description><![CDATA[Enums can be used to reduce #define statements in a C program, although they can have more uses. Here is an example of enum. #include int main() { enum Days{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday}; Days TheDay; int j = 0; printf("Please enter the day of the week (0 to 6)\n"); scanf("%d",&#38;j); TheDay = Days(j); if(TheDay == Sunday &#124;&#124; TheDay [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=41&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Enums can be used to reduce #define statements in a C program, although they can have more uses. </p>
<p>Here is an example of enum.</p>
<pre>
#include
int main()
{
enum Days{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday};

Days TheDay;
int j = 0;
printf("Please enter the day of the week (0 to 6)\n");
scanf("%d",&amp;j);
TheDay = Days(j);

if(TheDay == Sunday || TheDay == Saturday)
printf("Hurray it is the weekend\n");
else
printf("Curses still at work\n");

return 0;
}
</pre>
<p>One thing to keep in mind is that enums start from 0 so in the following line of code</p>
<pre>enum Days{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday};</pre>
<p>Sunday is assigned 0, Monday is assigned 1 and so on..</p>
<p>It is possible to make them start at a different number if we assign a number to it as shown below.</p>
<pre>enum Days{Sunday = 1,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday};</pre>
<p>In the example above, Sunday would have the value 1, Monday would have 2 and so on&#8230;.</p>
<p>Feel free to ask any questions in the comment box below.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aryafarzan.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aryafarzan.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aryafarzan.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aryafarzan.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aryafarzan.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aryafarzan.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aryafarzan.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aryafarzan.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aryafarzan.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aryafarzan.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aryafarzan.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aryafarzan.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aryafarzan.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aryafarzan.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=41&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aryafarzan.wordpress.com/2010/02/20/enum-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>43.751000 -79.443000</georss:point>
		<geo:lat>43.751000</geo:lat>
		<geo:long>-79.443000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2c71ae2845df28dbc9279c89f310648d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aryafarzan</media:title>
		</media:content>
	</item>
		<item>
		<title>Pointers to functions in C/C++ intro</title>
		<link>http://aryafarzan.wordpress.com/2010/02/10/pointers-to-functions-in-cc-intro/</link>
		<comments>http://aryafarzan.wordpress.com/2010/02/10/pointers-to-functions-in-cc-intro/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 16:20:36 +0000</pubDate>
		<dc:creator>aryafarzan</dc:creator>
				<category><![CDATA[OOP344]]></category>

		<guid isPermaLink="false">http://aryafarzan.wordpress.com/?p=26</guid>
		<description><![CDATA[Pointers to functions are a very interesting and elegant programming technique. They can be used to replace long switch or if statements! Anyone can start using pointers to functions all you have to do is to understand what they are and to learn its syntax. What is a Function Pointer? Function pointers are simply pointers [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=26&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Pointers to functions are a very interesting and elegant programming technique. They can be used to replace long switch or if statements!</p>
<p>Anyone can start using pointers to functions all you have to do is to understand what they are and to learn its syntax.</p>
<h5>What is a Function Pointer?</h5>
<p>Function pointers are simply pointers that point to a function! Functions have addresses in memory just as variables do.</p>
<h5>Syntax</h5>
<p>The syntax can be a little strange if you are seeing for the first time but its very easy to grasp.</p>
<p>Suppose we have the following function</p>
<p><code><br />
int add(int a, int b){<br />
  return a+b;<br />
}<br />
</code></p>
<p>we can start creating a pointers to function by writing<br />
<code><br />
  int (*fptr)(int, int);<br />
</code><br />
<b><em>int is the return type of the function</em></b> and (int, int) is the arguments the function accepts.</p>
<p>The next step is to give our pointer to function the function&#8217;s address. We do that with the following code<br />
<code><br />
  fptr = add;<br />
</code></p>
<p>Now that fptr points to the &#8220;add&#8221; function we can actually start calling out function using the fptr pointer. We use the code below to do it.</p>
<p><code><br />
 int c = 0;<br />
 c = (*fptr)(a, b);<br />
</code></p>
<p>As you can see pointers functions are easy to learn <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I will make more posts soon to show how you can get rid of a long switch statement by using pointers to functions. I have also posted a compilable example below so you can experiment with.</p>
<p><code><br />
/* Author: Fardad Soleimanloo */<br />
#include<br />
int add(int a, int b){<br />
  return a+b;<br />
}<br />
int main(){<br />
  int (*fptr)(int, int);<br />
  int a = 10;<br />
  int b = 20;<br />
  int c;<br />
  fptr = add;<br />
  c = (*fptr)(a, b);<br />
  printf("%d\n", c);<br />
  return 0;<br />
}<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aryafarzan.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aryafarzan.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aryafarzan.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aryafarzan.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aryafarzan.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aryafarzan.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aryafarzan.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aryafarzan.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aryafarzan.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aryafarzan.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aryafarzan.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aryafarzan.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aryafarzan.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aryafarzan.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=26&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aryafarzan.wordpress.com/2010/02/10/pointers-to-functions-in-cc-intro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>43.751000 -79.443000</georss:point>
		<geo:lat>43.751000</geo:lat>
		<geo:long>-79.443000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2c71ae2845df28dbc9279c89f310648d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aryafarzan</media:title>
		</media:content>
	</item>
		<item>
		<title>Week 3 Challenge</title>
		<link>http://aryafarzan.wordpress.com/2010/01/29/week-3-challenge/</link>
		<comments>http://aryafarzan.wordpress.com/2010/01/29/week-3-challenge/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 02:25:52 +0000</pubDate>
		<dc:creator>aryafarzan</dc:creator>
				<category><![CDATA[OOP344]]></category>

		<guid isPermaLink="false">http://aryafarzan.wordpress.com/?p=22</guid>
		<description><![CDATA[By using only the function in biof.c you can print integers by using the function below void bio_putint(int val){ bio_putch(val); }<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=22&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>By using only the function in biof.c you can print integers by using the function below</p>
<address>void bio_putint(int val){</address>
<address> bio_putch(val);</address>
<address>}</address>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aryafarzan.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aryafarzan.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aryafarzan.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aryafarzan.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aryafarzan.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aryafarzan.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aryafarzan.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aryafarzan.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aryafarzan.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aryafarzan.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aryafarzan.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aryafarzan.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aryafarzan.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aryafarzan.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=22&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aryafarzan.wordpress.com/2010/01/29/week-3-challenge/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<georss:point>43.751000 -79.443000</georss:point>
		<geo:lat>43.751000</geo:lat>
		<geo:long>-79.443000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2c71ae2845df28dbc9279c89f310648d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aryafarzan</media:title>
		</media:content>
	</item>
		<item>
		<title>Using &amp;&amp; instead of &#8220;if statment&#8221; in C/C++</title>
		<link>http://aryafarzan.wordpress.com/2010/01/27/using-instead-of-if-statment-in-cc/</link>
		<comments>http://aryafarzan.wordpress.com/2010/01/27/using-instead-of-if-statment-in-cc/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 19:54:14 +0000</pubDate>
		<dc:creator>aryafarzan</dc:creator>
				<category><![CDATA[OOP344]]></category>

		<guid isPermaLink="false">http://aryafarzan.wordpress.com/?p=18</guid>
		<description><![CDATA[C/C++ is a lazy language. It will only execute code when it has to!  When using AND if the first condition is false it will skip the second one.  The first example below uses an if statement and the second one uses AND which is a little faster. #include &#60;stdio.h&#62; int main(){ int number[10] = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=18&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>C/C++ is a lazy language. It will only execute code when it has to!  When using AND if the first condition is false it will skip the second one.  The first example below uses an if statement and the second one uses AND which is a little faster.</p>
<p><code><br />
#include &lt;stdio.h&gt;</code></p>
<p>int main(){<br />
int number[10] = {5, 1, 8, 3, 6, 5, 3, 8, 4, 6};<br />
int i = 0;<br />
while(i &lt; 10){  if(number[i] &gt; 5)<br />
printf(&#8220;%d\n&#8221;, number[i]);<br />
i++;<br />
}<br />
return 0;<br />
}</p>
<p>The above program takes <strong><span style="color:#ff0000;">0m0.004s</span></strong> to execute.</p>
<p>The program below is using &#8220;AND&#8221; instead of if statement</p>
<p><code><br />
#include &lt;stdio.h&gt;</code></p>
<p>int main(){<br />
int number[10] = {5, 1, 8, 3, 6, 5, 3, 8, 4, 6};<br />
int i = 0;</p>
<p>while(i &lt; 10){  number[i] &gt; 5 &amp;&amp;  printf(&#8220;%d\n&#8221;, number[i]);<br />
i++;<br />
}<br />
return 0;<br />
}</p>
<p>The program above executes in <span style="color:#ff0000;"><strong>0m0.003s<span style="color:#000000;"> </span></strong></span></p>
<p><span style="color:#ff0000;"><strong><span style="color:#000000;">Using AND can have some performance advantage over if statements, but it is only faster by a tiny amount.<br />
</span></strong></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aryafarzan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aryafarzan.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aryafarzan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aryafarzan.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aryafarzan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aryafarzan.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aryafarzan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aryafarzan.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aryafarzan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aryafarzan.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aryafarzan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aryafarzan.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aryafarzan.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aryafarzan.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=18&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aryafarzan.wordpress.com/2010/01/27/using-instead-of-if-statment-in-cc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<georss:point>43.751000 -79.443000</georss:point>
		<geo:lat>43.751000</geo:lat>
		<geo:long>-79.443000</geo:long>
		<media:content url="http://0.gravatar.com/avatar/2c71ae2845df28dbc9279c89f310648d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aryafarzan</media:title>
		</media:content>
	</item>
		<item>
		<title>Pointers in C/C++</title>
		<link>http://aryafarzan.wordpress.com/2010/01/26/pointers-in-cc/</link>
		<comments>http://aryafarzan.wordpress.com/2010/01/26/pointers-in-cc/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 18:37:28 +0000</pubDate>
		<dc:creator>aryafarzan</dc:creator>
				<category><![CDATA[OOP344]]></category>
		<category><![CDATA[addresses]]></category>
		<category><![CDATA[pointers]]></category>

		<guid isPermaLink="false">http://aryafarzan.wordpress.com/?p=10</guid>
		<description><![CDATA[Pointers are sometimes confusing to C/C++ programmers at first, but they don&#8217;t have to be! Pointers are just like any other variable in C/C++ but instead of holding an actual value they hold an address. I will use some simple code to show you how pointers work. Take a look at the code below. int [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=10&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Pointers are sometimes confusing to C/C++ programmers at first, but they don&#8217;t have to be! Pointers are just like any other variable in C/C++ but instead of holding an actual value they hold an address. I will use some simple code to show you how pointers work. Take a look at the code below.</p>
<p><code><br />
int number = 4;<br />
int* pNumber = &amp;number;<br />
</code></p>
<p>int* pNumber = &amp;number creates an integer pointer and assigns number&#8217;s address to it. In C/C++ the character &#8216;&amp;&#8217; means the &#8220;address of&#8221;. The simple program below will give you a better understanding of addresses.</p>
<p><code><br />
#include &lt;stdio.h&gt;<br />
</code></p>
<p>int main()<br />
{<br />
int number = 4;<br />
int* pNumber = &amp;number;<br />
printf(&#8220;%u, %u\n&#8221;, &amp;number, pNumber);</p>
<p>return 0;<br />
}</p>
<p>The output would be:</p>
<blockquote><p>3214459548, 3214459548</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aryafarzan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aryafarzan.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aryafarzan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aryafarzan.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aryafarzan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aryafarzan.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aryafarzan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aryafarzan.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aryafarzan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aryafarzan.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aryafarzan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aryafarzan.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aryafarzan.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aryafarzan.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=10&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aryafarzan.wordpress.com/2010/01/26/pointers-in-cc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2c71ae2845df28dbc9279c89f310648d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aryafarzan</media:title>
		</media:content>
	</item>
		<item>
		<title>Assigning integers to char type in C/C++</title>
		<link>http://aryafarzan.wordpress.com/2010/01/19/assigning-integers-to-char-type-in-cc/</link>
		<comments>http://aryafarzan.wordpress.com/2010/01/19/assigning-integers-to-char-type-in-cc/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 16:14:27 +0000</pubDate>
		<dc:creator>aryafarzan</dc:creator>
				<category><![CDATA[OOP344]]></category>

		<guid isPermaLink="false">http://aryafarzan.wordpress.com/?p=5</guid>
		<description><![CDATA[In c/c++ the char type can be used to store a single character or small integers. Have a look at the program below and determine what the value of &#8220;ch&#8221; would be without running the program. #include &#60;stdio.h&#62; int main(){ char ch = 127; ch++; return 0; } What would the value of ch be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=5&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In c/c++ the char type can be used to store a single character or small integers.</p>
<p>Have a look at the program below and determine what the value of &#8220;ch&#8221; would be without running the program.</p>
<p>#include &lt;stdio.h&gt;<br />
<code><br />
int main(){</code></p>
<p>char ch = 127;<br />
ch++;</p>
<p>return 0;<br />
}</p>
<p>What would the value of ch be when the program is executed? Most people would guess it would be 128, but the right answer is -128.</p>
<p>The reason behind it is because a signed char type in c/c++ only accepts values from -128 to 127 and when ch++ is executed 127 goes to the next avaialble number which is -128.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aryafarzan.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aryafarzan.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aryafarzan.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aryafarzan.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aryafarzan.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aryafarzan.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aryafarzan.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aryafarzan.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aryafarzan.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aryafarzan.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aryafarzan.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aryafarzan.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aryafarzan.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aryafarzan.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aryafarzan.wordpress.com&amp;blog=11415380&amp;post=5&amp;subd=aryafarzan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aryafarzan.wordpress.com/2010/01/19/assigning-integers-to-char-type-in-cc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2c71ae2845df28dbc9279c89f310648d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aryafarzan</media:title>
		</media:content>
	</item>
	</channel>
</rss>
