<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8742182865769537021</id><updated>2025-09-14T07:31:03.526-04:00</updated><category term="beginning"/><category term="functions"/><category term="Math"/><category term="Opinions"/><category term="Pointers"/><category term="School"/><category term="arguments programming functions"/><category term="introduction"/><category term="main"/><category term="malloc c c++ dynamic memory tips tricks sizeof()"/><category term="memory"/><title type='text'>C Lessons and Tips</title><subtitle type='html'>...and of course whatever else is on my mind</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>15</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-3877734578930714112</id><published>2011-04-04T22:34:00.002-04:00</published><updated>2011-04-06T01:14:08.212-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="School"/><title type='text'>Exam Cheatsheet</title><content type='html'>So my exam for Computer Programming II is this Thursday, and having looked at the course outline my prof made for us, it clearly states that we are allowed to bring in &quot;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;...one page during the exam time to assist you in memorizing some syntactic matters.&quot; So basically this means that we can bring in a page full of examples of everything we learned this semester. Hopefully nobody reminds her about this and makes her&amp;nbsp;&lt;/span&gt;change&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;her mind... She&#39;s pretty cool though, so I&#39;m sure if we all show up with them, she&#39;ll be cool with it.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;Anyway, I decided to share mine with everyone here! Feel free to use it as a reference, or even as study help for your own class!&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://toasterfiles.99k.org/files/COMP1431SHEET.doc&quot;&gt;Download Link&amp;nbsp;1&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Calling by reference:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;int x=0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;int *ptr;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;ptr=&amp;amp;x;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //ptr now points to x&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;void function(int *y)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *y++;&amp;nbsp;&amp;nbsp; //y points to x&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;int arr[5];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;arr[3]; //same as *(arr+3)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;pointer to function:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;double (*fp)(double,double);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;fp=pow; //fp now acts like pow&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Useful String Functions:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;int atoi( const char *nPtr )&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;char *gets( char *s );&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;char *strcpy( char *s1, const char *s2 )&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;char *strcat( char *s1, const char *s2 )&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;char *strstr( const char *s1, const char *s2 );&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Structs:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;typedef struct dummyname&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int x;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //elements&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;}StructName;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;StructName identifier;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;indentifier.element=value;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Dynamic Memory:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;ptr = (int*)malloc(5*sizeof(int));&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;Linked Lists:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;typedef struct node&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char data;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct node *next;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;}Node;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;Node *p;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;p=(Node*)malloc(sizeof(Node));&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;p-&amp;gt;data=’a’;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;p-&amp;gt;next=head;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;head=p;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Enum:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;typedef enum dummyname&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sun,mon,tues...&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;}Weekday;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;(sun=0,mon=1,....)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;force values:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;enum{sun=5,mon=8,...};&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Union:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;As large as its largest element.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;Holds one at a time.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;Declare like a struct.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Preprocessor:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;#define SQUARE(x) ((x)*(x))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;#undef&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;#if, #ifdef, #else, #endif&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;#define TOKCAT(x,y) x ## y&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Variable Length Args:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;int funct(int n,...)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; va_list args;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; va_start(args,n);//n is first param&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;loop()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; variable=va_arg(args,type);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; va_end(args);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Command Line Args:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;int main(int argc,char *argv[])&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;iostream:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;using namespace std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;cout&amp;lt;&amp;lt;”stuff”;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;cin&amp;gt;&amp;gt;variables;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Default Args:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;int func(int x=1);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Templates:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;template &amp;lt;class T&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;T square(T value)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return value*value;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;int x=square(5);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;float y=square(5);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Classes:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;Class ClassName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;public:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm; text-indent: 36.0pt;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;void func();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; const int x;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;private:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void inlineFunct(){return 0;};&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //private ones&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;};&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;void ClassName::funct()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;//constuctor&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;ClassName::ClassName()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{/*default values*/}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;//destructor&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;ClassName::~ClassName(){}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;Data Initializer:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;ClassName::ClassName()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :x(0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{/*default values*/}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Composition:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;Class1::Class1(Class2 &amp;amp;identifier)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Friend Functions:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;class ClassName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; friend void func();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;public:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;private:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;void func(ClassName name)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //access private stuff&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;new and delete:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;int ptr = new int(3.141592654);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;int arr = new int[10];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;delete []arr;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Static Class Members:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;ClassName::var&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;InstanceName.var&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;ClassName::ClassName()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var++;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;line-height: 115%;&quot;&gt;Operator Overloading:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;class ClassName&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm; margin-left: 36.0pt; margin-right: 0cm; margin-top: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;friend ostream&amp;amp; operator&amp;lt;&amp;lt;( ostream&amp;amp;, const ClassName&amp;amp;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;ClassName&amp;amp; ClassName::operator=(const ClassName x)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var1=x.var1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm; text-indent: 36.0pt;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;return *this;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;ostream&amp;amp; operator&amp;lt;&amp;lt;(ostream &amp;amp;o, const ClassName x)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o&amp;lt;&amp;lt;x.var1&amp;lt;&amp;lt;etc;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm; text-indent: 36.0pt;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;return o;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0cm;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; line-height: 115%;&quot;&gt;}&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/3877734578930714112/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/04/exam-cheatsheet.html#comment-form' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/3877734578930714112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/3877734578930714112'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/04/exam-cheatsheet.html' title='Exam Cheatsheet'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-2280817741570280312</id><published>2011-04-03T23:32:00.001-04:00</published><updated>2011-04-03T23:40:48.262-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Pointers"/><title type='text'>The Basics of Pointers - Part 1</title><content type='html'>Now, we&#39;ve learned to deal with variables. In most programming languages, you&#39;ll be able to deal with &quot;references&quot; to variables (more of why we would want to do this in the next post), such a thing in C is called a pointer. Let&#39;s just jump right into the code, shall we?&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int x;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int *ptr;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Here, we are declaring an integer called x, and after that, we declared what is called &quot;a pointer to integer&quot;. A pointer is declared by specifying the type, and then putting an asterisk before the desired identifier. Note that both of the following are correct syntax which do the exact same thing.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int *ptr1;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int* ptr2;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
It doesn&#39;t matter is the asterisk goes before or after the space.&lt;br /&gt;
&lt;br /&gt;
Last time, we learned about memory addresses. Basically, a pointer can be thought of as a variable which holds a memory address of a specific type of variable. Remember how we used &quot;&amp;amp;&quot; to access the memory location of a variable? Well here&#39;s where it comes into play. Let&#39;s say we have:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int x=5;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int *ptr;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;ptr = &amp;amp;x;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This would make ptr point to x. In a way, this means that we can indirectly access the content of x. To do this, we put an asterisk in front of the pointer&#39;s&amp;nbsp;identifier. For example, using the code above...&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;printf(&quot;%d&quot;,*ptr);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;Result: 5&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In the same way, we can modify the content of x by using the pointer.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;*ptr = 42;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;printf(&quot;%d&quot;,x);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Result: 42&lt;br /&gt;
&lt;br /&gt;
By putting the star in front of your pointer&#39;s identifier, it is like saying: &quot;The content of...&quot;&lt;br /&gt;
&lt;br /&gt;
Note that in order for a pointer to work properly, it must be declared properly as well. By this, I mean that you cannot reference a float from a pointer to integer. This:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float y;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int *ptr3;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;ptr3 = y;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
will cause a compilation error. Why?&lt;br /&gt;
&lt;br /&gt;
When you declare variables, bytes of memory are taken up. The amount of bytes is determined by what type of variable it is. An integer will typically take up 4 bytes, while a floating point number will take up 8. This means that when we have a pointer to integer, the pointer is expecting a memory address such that 4 bytes after it are taken up. In this example, it sees that it would need 8 bytes, that is, a pointer to integer would only hold half the data, and would be full after &quot;filling up&quot; half way. The compiler sees that this is a problem, and reports and error.&lt;br /&gt;
&lt;br /&gt;
So we know about using pointers now. Great. So why would we ever want to do this?&lt;br /&gt;
Stay tuned.</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/2280817741570280312/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/04/basics-of-pointers-part-1.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/2280817741570280312'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/2280817741570280312'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/04/basics-of-pointers-part-1.html' title='The Basics of Pointers - Part 1'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-2810350732897254490</id><published>2011-03-31T23:44:00.003-04:00</published><updated>2011-03-31T23:45:19.665-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="memory"/><title type='text'>Memory Addresses</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: white;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;When you declare a variable of any type, memory is taken up. Each variable then has what is called a &quot;memory address&quot; which is an indication of where it is stored in memory. The memory address of any variable is indicated in hexadecimal (or honestly, some other number base, it may be octal, but that&#39;s not really important for now). Accessing the memory address of any variable is easy.&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-size: 13px; line-height: 18px;&quot;&gt;int x;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-size: 13px; line-height: 18px;&quot;&gt;&amp;amp;x &amp;nbsp;//is the memory address of x&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;So you may be asking yourself why you would ever need to know things like this.&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;WELL&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;A simple application in which you&#39;re basically required to use memory addresses is the use of &amp;nbsp;scanf().&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;scanf() can be thought of doing the opposite of printf(). Instead of outputting information to the user, it takes information from the user and stored it in variables. Here&#39;s how we would ask the user to store a value for an integer x;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-size: 13px; line-height: 18px;&quot;&gt;int x;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-size: 13px; line-height: 18px;&quot;&gt;printf(&quot;Input a value for x: &quot;);&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-size: 13px; line-height: 18px;&quot;&gt;scanf(&quot;%d&quot;,&amp;amp;x);&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; font-family: &#39;trebuchet ms&#39;, verdana, arial, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Notice how the format string for scanf() is exactly the same as printf(). The main difference here is that the second parameter is asking &quot;where do you want to store this value&quot;. The obvious answer is &quot;in x,&quot; but really, you&#39;re going to want to be storing it in the space that x is occupying in memory - its memory address. Also notice how we cannot print to the screen using scanf. In order to let the user know what he is supposed to input, we must use printf() to print instructions as the program executes.&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/2810350732897254490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/memory-addresses.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/2810350732897254490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/2810350732897254490'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/memory-addresses.html' title='Memory Addresses'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-6002267294074772491</id><published>2011-03-28T20:50:00.000-04:00</published><updated>2011-03-28T20:50:10.885-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="beginning"/><title type='text'>Nested Loops</title><content type='html'>Just a quick post today on nested loops.&lt;br /&gt;
&lt;br /&gt;
The basic concept is that you will have one (or more) loop inside of another loop. Each internal loop will run and terminate, and then any external loops will then run. Here&#39;s an example:&lt;br /&gt;
&lt;br /&gt;
for(int i=0;i&amp;lt;5;i++)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; printf(&quot;i = %d\n&quot;,i); &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int j=0;j&amp;lt;5;j++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;j = %d\n&quot;,j);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The output would be:&lt;br /&gt;
&lt;br /&gt;
i = 0&lt;br /&gt;
j = 0&lt;br /&gt;
j = 1&lt;br /&gt;
j = 2&lt;br /&gt;
j = 3&lt;br /&gt;
j = 4&lt;br /&gt;
i =1&lt;br /&gt;
j = 0&lt;br /&gt;
j = 1&lt;br /&gt;
j = 2&lt;br /&gt;
j = 3&lt;br /&gt;
j = 4&lt;br /&gt;
i =2&lt;br /&gt;
j = 0&lt;br /&gt;
j = 1&lt;br /&gt;
j = 2&lt;br /&gt;
j = 3&lt;br /&gt;
j = 4&lt;br /&gt;
i =3&lt;br /&gt;
j = 0&lt;br /&gt;
j = 1&lt;br /&gt;
j = 2&lt;br /&gt;
j = 3&lt;br /&gt;
j = 4&lt;br /&gt;
i =4&lt;br /&gt;
j = 0&lt;br /&gt;
j = 1&lt;br /&gt;
j = 2&lt;br /&gt;
j = 3&lt;br /&gt;
j = 4&lt;br /&gt;
&lt;br /&gt;
So you see that it is really much like a normal loop. Each time a loop runs, it must execute all the code contained within its scope before looping again - even if it contains another loop.&lt;br /&gt;
&lt;br /&gt;
This is just a quick basic concept that should be understood. This is very useful when dealing with multi-dimensional arrays (matrices), but I&#39;ll come to that in another lesson.&lt;br /&gt;
&lt;br /&gt;
Sorry for the short post! I need to get back to studying for exams.</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/6002267294074772491/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/nested-loops.html#comment-form' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/6002267294074772491'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/6002267294074772491'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/nested-loops.html' title='Nested Loops'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-3332999734618772336</id><published>2011-03-25T17:09:00.000-04:00</published><updated>2011-03-25T17:09:50.839-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="beginning"/><title type='text'>Loops</title><content type='html'>Loops are useful for running one or more lines of code repeatedly. The basis of how a loop works is similar to an if statement: There is a condition, and if the condition fails, the loop stops. The first loop I&#39;ll show you is a called a while loop, here&#39;s its syntax:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;while(&lt;i&gt;condition&lt;/i&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//code&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Pretty simple. Let&#39;s see this in an example&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int i=0;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;while(i&amp;lt;10)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;printf(&quot;%d\n&quot;,i);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;i++;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
(For those who don&#39;t know, i++ is the same as saying i=i+1 or i+=1. It means &quot;increment i&quot;)&lt;br /&gt;
This will print out the numbers 0 to 9.&lt;br /&gt;
Basically we start by initializing an integer to 0. We tell our while loop &quot;Loop the code while the value of i is less than 10&quot;. In the first pass, the condition passes the test because 0&amp;lt;10. Good! So we go ahead and call our printf function. Here&#39;s the important part: we increment i by 1. So now the value of i is equal to 1 and we return to the beginning of the while loop and run the condition again. Now we&#39;re asking &quot;Is 1 less than 10?&quot; Yes it is. We run the loop again. printf, increment, loop again: &quot;Is 2 less than 10&quot; Yes....you get the idea.&lt;br /&gt;
Let&#39;s look at the last pass through the loop, when i is equal to 9. &quot;Is 9 less than 10?&quot; Yes, so go into the loop, call printf and increment i. Now we go back to the top yet again, but this time we ask &quot;Is 10 less than 10?&quot;&lt;br /&gt;
The answer of course is NO, so we skip the loop entirely, just as we would if a condition in an if statement failed.&lt;br /&gt;
&lt;br /&gt;
This is a simple use for a while loop, and in fact, while loops using a simple incrementing variable can be rewritten as another type of loop: a for loop. The syntax is a little more complicated, but in the end, for loops generally end up being easier to manage.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;for(&lt;i&gt;initial state&lt;/i&gt;;&lt;i&gt;terminating condition&lt;/i&gt;;&lt;i&gt;increment&lt;/i&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//code goes here&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Let&#39;s look back at our while loop example for a sec. See how we declared an integer i before the loop? That&#39;s our initial state. We then had a condition in the while loop. That of course is the terminating condition. At the end of the while loop, we increased the value of i. That&#39;s our increment.&lt;br /&gt;
&lt;br /&gt;
Here&#39;s the same loop above rewritten as a for loop:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;for(int i=0;i&amp;lt;10;i++)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;printf(&quot;%d\n&quot;,i);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Both loops essentially do the exact same thing. The real difference for you is that in a for loop, all the useful loop information is stored in the&amp;nbsp;parentheses&amp;nbsp;after the word &quot;for&quot;.&lt;br /&gt;
Note that in the for loop, I declared my incrementing variable inside the parentheses. This is a matter of preference, but I do it whenever possible. Basically, I&#39;m saying that the following is still correct:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int i;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;for(i=0;i&amp;lt;10;i++)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;printf(&quot;%d\n&quot;,i);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
While this is still correct, I find it very beneficial to declare your incrementing variable inside your loop. This way, the variable &quot;dies&quot; after the loop ends. This means that you can reuse that variable name for other loops and you don&#39;t have to worry about this loose variable floating around your program. This means that I could do this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;for(int i=0;i&amp;lt;200;i++)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//run some code&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;for(int i=0;i&amp;lt;42;i++)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//run some different code&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;And I won&#39;t have to worry about which variable I used before. Again, it really is a matter of preference. I showed you mine.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;When writing loops, you&#39;ll likely accidentally code an infinite loop at some point. For example, take a look at this:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int x=5;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int y=2;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;while(x==5)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;printf(&quot;...&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;y++;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;With a quick look at the code, you&#39;ll see that our condition is always true! This means that the loop will never end. Likewise, the following will be an infinite loop.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;while(1)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//code&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Thinking back to our logical operators, a logical statement return a value of 1 if true or 0 if false. Thus, our condition is interpreted as &quot;While &#39;a true statement&#39;, run this code.&quot; No wonder it will loop forever!&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;It is also important to check your for loops for infinite loops, since for loops especially are usually not meant to be infinite.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;for(int i=0;i&amp;gt;-1;i++)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;will be an infinite loop since we are looping as long as i is greater than -1 and each time the loop runs, i is incremented. An infinite for loop can also be forced by writing:&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;for( ; ; )&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;No initial state, no terminating condition, no increment. The loop has noting to worry about and will go on forever.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Next time, I&#39;ll talk about nested loops&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/3332999734618772336/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/loops.html#comment-form' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/3332999734618772336'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/3332999734618772336'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/loops.html' title='Loops'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-3328480700396277798</id><published>2011-03-23T20:27:00.000-04:00</published><updated>2011-03-23T20:27:56.454-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="beginning"/><title type='text'>More conditions</title><content type='html'>So yesterday, we looked at if statements and how to use them with simple conditions. To make our conditions more complicated, we need to make use of more of the logical operators. I&#39;ll give a real life example:&lt;br /&gt;
&lt;br /&gt;
&quot;It is sunny and I am not indoors.&quot;&lt;br /&gt;
&lt;br /&gt;
A pretty simple statement. Not thinking about coding right now, let&#39;s let:&lt;br /&gt;
p = It is sunny&lt;br /&gt;
q = I am indoors&lt;br /&gt;
&lt;br /&gt;
If we wanted to write this as a condition for an if statement, we would have:&lt;br /&gt;
&lt;br /&gt;
p &amp;amp;&amp;amp; !q&lt;br /&gt;
&lt;br /&gt;
Pretty simple, right? Now let&#39;s look at the statement:&lt;br /&gt;
&lt;br /&gt;
&quot;It is sunny or cloudy, but not raining.&quot;&lt;br /&gt;
&lt;br /&gt;
An important note about logic: BUT has the same logical meaning as AND. So we have:&lt;br /&gt;
&lt;br /&gt;
&quot;It is sunny or cloudy, and not raining.&quot;&lt;br /&gt;
&lt;br /&gt;
Now, an important point about how this statement is interpreted. Do you remember BEDMAS, the order of operations when doing arithmetic? This states that certain operators must be evaluated before others (the order is: brackets, exponents, division/multiplication, addition/subtraction). Well logical operators also possess a precedence factor as you&#39;ll see. Let&#39;s look at our statement again. It states that it is sunny or &amp;nbsp;cloudy, but not raining. At first glance, it may seem at though the condition first checks to see whether it is sunny or cloudy, and then checks to see if it is raining. i.e. this:&lt;br /&gt;
&lt;br /&gt;
(sunny or cloudy) and raining&lt;br /&gt;
&lt;br /&gt;
In fact, when dealing with logic, I like to think of AND as a multiplication symbol and OR as addition (there&#39;s a discrete mathematical property that actually says this, but I won&#39;t get into that). In other words, AND will precede OR when dealing with operations, so our original statement actually means this:&lt;br /&gt;
&lt;br /&gt;
sunny or (cloudy and raining)&lt;br /&gt;
&lt;br /&gt;
See how it completely changes the sense of our condition? It&#39;s like comparing:&lt;br /&gt;
&lt;br /&gt;
(5 * 5) + 10 = 250&lt;br /&gt;
and&lt;br /&gt;
5 * (5 + 10) = 75&lt;br /&gt;
&lt;br /&gt;
Just a note to be careful when coding.&lt;br /&gt;
Great, now that that&#39;s out of the way, you are legally entitled to see some code.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s say we are writing a program in which we are asking the user for a time in hours and minutes. Obviously, we don&#39;t want to deal with hours greater than the number of hours in a day or minutes greater than 60, so a common fix is to set a default value if the user enters invalid data. We&#39;ll work from hours 0 to 23&lt;br /&gt;
&lt;br /&gt;
int hour,min;&lt;br /&gt;
//prompt user for data&lt;br /&gt;
if(hour&amp;lt;0 || hour&amp;gt;23)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;hour=1;&lt;br /&gt;
}&lt;br /&gt;
if(min&amp;lt;1 || min&amp;gt;60)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;min=0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Notice how we cannot use mathematical notation like: 0&amp;lt;hour&amp;lt;23. Instead, we must explicitly show each condition we want to include.&lt;br /&gt;
&lt;br /&gt;
I hope this has been useful!&lt;br /&gt;
&lt;br /&gt;
Next time, I&#39;ll talk about loops.</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/3328480700396277798/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/more-conditions.html#comment-form' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/3328480700396277798'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/3328480700396277798'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/more-conditions.html' title='More conditions'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-8761031749721792954</id><published>2011-03-22T20:21:00.000-04:00</published><updated>2011-03-22T20:21:55.175-04:00</updated><title type='text'>Boolean logic and if statements</title><content type='html'>Without the need to make &quot;decisions&quot;, your program will just be a linear stream of code that always outputs the same type of data. To check conditions, we use the &lt;i&gt;if&lt;/i&gt; statement.&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Before even talking about the statement itself, it is&amp;nbsp;necessary&amp;nbsp;to cover certain aspects of boolean logic. There are certain operators that you must know when dealing with logic.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Greater than &amp;gt;&lt;/div&gt;&lt;div&gt;Less than &amp;lt;&lt;/div&gt;&lt;div&gt;Negation !&lt;/div&gt;&lt;div&gt;Equality check ==&lt;/div&gt;&lt;div&gt;Inequality&amp;nbsp;check !=&lt;/div&gt;&lt;div&gt;Greater than or equal to &amp;gt;=&lt;/div&gt;&lt;div&gt;Less than of equal to &amp;lt;=&lt;/div&gt;&lt;div&gt;And &amp;amp;&amp;amp;&lt;/div&gt;&lt;div&gt;Or ||&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Standard parentheses will also come in handy when dealing with large conditions.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;This seems like an eyesore right now, but I&#39;m sure you&#39;ll soon find this natural.&amp;nbsp;The basic structure of the if statement is as follows:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;if(condition)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//result&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Seems pretty simple, right?&lt;/div&gt;&lt;div&gt;Let&#39;s say I have some integer x, and I want to print a line of text only if the value of x is currently greater than 5. We would have:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;if(x&amp;gt;5)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;printf(&quot;This will get printed!!&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Easy!&lt;/div&gt;&lt;div&gt;Likewise, if we wanted to check if it was strictly equal to 5:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;if(x==5)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;printf(&quot;It is equal to 5!&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The basic idea behind this boolean logic is that if the statement contained within the parentheses is true, then the condition returns a value of 1. If false, a value of 0 is returned.&lt;/div&gt;&lt;div&gt;This is very important, as new programmers often make a silly mistake, I will show you:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;//This is a very common programming mistake&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;if(x=5)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;printf(&quot;What&#39;s wrong here?&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Can you see the difference? Rather than using the comparison operator, I used the assignment operator! Here, we are actually assigning a value to x, not comparing one! Although it is just a one character difference, it completely changes the meaning of the statement. Instead of having the condition return true or false (1 or 0), the condition is returning the assigned value of x, 5! The if statement also interprets this as a &quot;true&quot; value. In other words, no matter what the value of x was before the if statement ran, it will now be 5 when it does run, and hence, it will always return true, defeating the purpose of writing the statement altogether!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The beauty of if statements is that they don&#39;t simply end if your condition is false. There&#39;s also the option of passing the flow of control to an &quot;else&quot; which runs if the first condition is not true. For example:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;if(8&amp;lt;5)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//this will always be false&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//run some code!&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;This way, you can use the else as a &quot;default&quot; execution.&lt;/div&gt;&lt;div&gt;But wait, there&#39;s more! You can combine ifs and elses to create a string of conditions&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;if(&lt;i&gt;condition&lt;/i&gt;)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;else if(&lt;i&gt;another condition&lt;/i&gt;)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;else if(&lt;i&gt;yet another condition&lt;/i&gt;)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;...this can go on for a while&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Notice how each consecutive else if will be run if the previous condition is not true. And that in this case, if none of them are true, then the else block will run. Note that it is not necessary to terminate with an else block. Hope this has been useful! Next time, I&#39;ll talk more about logic and how to create more complex conditions.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/8761031749721792954/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/boolean-logic-and-if-statements.html#comment-form' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/8761031749721792954'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/8761031749721792954'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/boolean-logic-and-if-statements.html' title='Boolean logic and if statements'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-1282473327492237666</id><published>2011-03-20T22:55:00.000-04:00</published><updated>2011-03-20T22:55:25.989-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="functions"/><title type='text'>Scopes</title><content type='html'>When programming, it is important to know which variables you can use where. I&#39;ll explain.&lt;br /&gt;
Let&#39;s say you declare a global integer x, and you define a function myFunct(). In the definition of myFunct(). You would obviously be able to use this integer x. But does it go the other way around? That is, can you use variable declared inside a function outside the function?&lt;br /&gt;
Simple answer. No.&lt;br /&gt;
&lt;br /&gt;
When you call a function, the &quot;flow&quot; of your program halts so that it can go run your function and then return with the results. Let&#39;s say we have a function add2()&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int add2(int x)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;int y = 2;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return x+y;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Yes, I know there&#39;s no reason to declare this variable y, but it&#39;s for the sake of the example. In this case, The variable called y only &quot;lives&quot; until the end of the function. After that, this variable no longer exists, and hence it can no longer be referred to (Things like this can be overcome using the &quot;static&quot; keyword. I&#39;ll mention this sometime). In fact, this variable x no longer exists either. x is just a temporary holder for a value that is used while the function is running!&lt;br /&gt;
Functions are just one example of where knowledge of a scope could be useful. Let&#39;s say you were running a for loop.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int i;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;for(i=0;i&amp;lt;5;i++)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//do stuff&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Clearly, this is just an average for loop. Runs whatever code between its curly brackets 5 times. Now check this out:&lt;br /&gt;
&lt;br /&gt;
f&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;or(int i=0;i&amp;lt;5;i++)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//do other stuff&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Can you see the difference?&lt;br /&gt;
The difference is that in the first case, the variable i would be usable even after the for loop was executed. In the second case, i &quot;dies&quot; as soon as the loop terminates. Personally, I like to use the second method just because it allows me to use the same identifier for all my loops (assuming they&#39;re not nested) without fear of that identifier already being declared and used for another loop. I also just find it neater ;)</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/1282473327492237666/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/scopes.html#comment-form' title='37 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/1282473327492237666'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/1282473327492237666'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/scopes.html' title='Scopes'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>37</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-885240111311504058</id><published>2011-03-18T15:34:00.001-04:00</published><updated>2011-03-18T15:35:07.887-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="beginning"/><category scheme="http://www.blogger.com/atom/ns#" term="functions"/><title type='text'>Simple Functions</title><content type='html'>Functions are the basis for writing programs in C. &amp;nbsp;They allow you to efficiently run repeated lines of code. For example, take a look at this mathematical function:&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;f(x) = x&lt;sup&gt;2&lt;/sup&gt;&lt;br /&gt;
&lt;br /&gt;
This function takes any real number x and squares it. Another way of writing this function could be:&lt;br /&gt;
&lt;br /&gt;
f(x) = x*x&lt;br /&gt;
&lt;br /&gt;
In C. Functions have 3 &quot;Parts&quot;:&lt;br /&gt;
1) The function prototype which tells the program what to expect when the function is defined.&lt;br /&gt;
2) The function definition which tells the program how to execute the function.&lt;br /&gt;
3) The function call, which actually runs the function.&lt;br /&gt;
&lt;br /&gt;
For this example, let&#39;s look at this square example. To declare a function, you must specify its return type (more on this is a sec) and then give the function an identifier and specify its parameter type. The parameters are the values that get passed into and used by the function (in f(x), our parameter is x). Here&#39;s a function prototype for our square function.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int square(int);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Later in your program, usually after your main method (unless you decide to declare it before, in which case a function prototype is not necessary), you will include your function definition. Here&#39;s the definition for square.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int square(int x)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return x*x;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
A really simple function. The program will take whatever value gets passed into the function. That value is now represented by x. The function now calculates the square of x and returns the value back to wherever the function was called. Here&#39;s an example showing how to call this function&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int square(int);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int main()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;y=2;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;printf(&quot;The square of %d is % d.\n&quot;,y,square(y));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return 0;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int square(int x)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return x*x;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Compile this and you&#39;ll see that the output of the program is:&lt;br /&gt;
The square of 2 is 4.&lt;br /&gt;
&lt;br /&gt;
Notice how to call the function, you simply write the function name and then the values you want to pass into the function (These are called the arguments).&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/885240111311504058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/simple-functions.html#comment-form' title='13 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/885240111311504058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/885240111311504058'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/simple-functions.html' title='Simple Functions'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>13</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-3200965438878292564</id><published>2011-03-16T13:29:00.000-04:00</published><updated>2011-03-16T13:29:36.701-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="beginning"/><title type='text'>Declaring and initialising variables</title><content type='html'>Today, I&#39;ll show you how to declare and initialize variables and talk about the possible types.&lt;br /&gt;
&lt;br /&gt;
C has a few &quot;core&quot; data types called &lt;i&gt;primitives&lt;/i&gt; these data types typically hold some sort of numerical value. The following are primitives:&lt;br /&gt;
&lt;br /&gt;
int (integers)&lt;br /&gt;
long (integers)&lt;br /&gt;
float (real numbers)&lt;br /&gt;
double (real numbers)&lt;br /&gt;
char (characters)&lt;br /&gt;
&lt;br /&gt;
The most used primitives are int, float, and char. Long and double are simply ints and floats respectively which allow a wider range of values.&lt;br /&gt;
&lt;br /&gt;
Declaring a variable is easy. You first type the type of variable you want to declare, and then you give it an identifier (a name) which must start with a letter and may contain numbers and underscore characters as well. For example:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;int x;&lt;/div&gt;&lt;br /&gt;
would declare an integer with the name x. You can now assign a value to x using the assignment operator =.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;x=5;&lt;/div&gt;&lt;br /&gt;
This would store a value of 5 in x. It is also possible to combine declaration and assignment in one line.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;int x=5;&lt;/div&gt;&lt;br /&gt;
is also acceptable. floats are declared in the same way.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;float y=2.7;&lt;/div&gt;&lt;br /&gt;
however, attempting something like:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;int z=3.14;&lt;/div&gt;&lt;br /&gt;
would cause an error, because 3.14 is not an integer.&lt;br /&gt;
Declaring characters is done in the same way, however, assignment is slightly different.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;char c=&#39;f&#39;;&lt;/div&gt;&lt;br /&gt;
This would declare a character and hold the character &#39;f&#39; in it.&lt;br /&gt;
&lt;br /&gt;
Every character has its own unique code to identify it. Given the 256 standard characters, these codes are called ASCII codes and each ASCII character has its own. In C, when you store a character in a variable, you are actually storing the value of its ASCII code. When you want to specify that you&#39;re talking about a character, you must put it between apostrophes.&lt;br /&gt;
&lt;br /&gt;
Next time, I&#39;ll talk about modifying the contents of variables and displaying their contents using printf();</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/3200965438878292564/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/declaring-and-initialising-variables.html#comment-form' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/3200965438878292564'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/3200965438878292564'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/declaring-and-initialising-variables.html' title='Declaring and initialising variables'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-9168112305826275284</id><published>2011-03-15T18:52:00.000-04:00</published><updated>2011-03-15T18:52:14.704-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="functions"/><category scheme="http://www.blogger.com/atom/ns#" term="introduction"/><category scheme="http://www.blogger.com/atom/ns#" term="main"/><title type='text'>Back to basics</title><content type='html'>So I&#39;ve been getting some comments and messages about my posts being too advanced, So&amp;nbsp;I&#39;ve&amp;nbsp;decided that it would probably make more sense to start C from the beginning. In this post, I&#39;ll show you how to write a basic &quot;Hello World!&quot; program and explain the ins and outs of it. Some things will just be touched on right now and more fully explained in later posts.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int main()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;printf(&quot;Hello World!&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return 0;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
To fully understand how the program works, I&#39;ll explain its components.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
#include is a macro. This particular macro goes and finds a file on your computer, in this case stdio.h. This file is what we call a header file.&amp;nbsp;Basically, this file contains a bunch of &lt;i&gt;function definitions&lt;/i&gt;&amp;nbsp;(again, more on this later). The #include macro tells the program to go look in the folder on your computer containing your standard C library header files and to find stdio.h. When you hit the &quot;build&quot; button, the compiler will take your source code and compile it into machine code, but even before that, something called the &lt;i&gt;preprocessor&lt;/i&gt;&amp;nbsp;(we&#39;ll mention this again much later) will physically copy all the text from stdio.h into your program. Now when your program gets compiled, the compiler sees all this code in your program, so it actually &lt;i&gt;becomes&lt;/i&gt;&amp;nbsp;a part of your program.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int main()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Functions are very important in any programming language. Every program in C must have a main function. Everything contained within the curly brackets will be code executed during runtime.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;printf(&quot;Hello World&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This is a call the function which prints to the screen. This printf function is defined within the stdio.h file. Having included that file, we are able to call this function. Here, we can see that the text we are printing to the screen is &quot;Hello World&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;return 0;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
To indicate to the operating system that the program has terminated successfully (ie. No runtime errors occurred/The program did not crash/etc) we return 0 at the end of out main. This&amp;nbsp;signifies&amp;nbsp;the end of our program.&lt;br /&gt;
&lt;br /&gt;
I hope this has been useful to those not yet fully comfortable with C.</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/9168112305826275284/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/back-to-basics.html#comment-form' title='20 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/9168112305826275284'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/9168112305826275284'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/back-to-basics.html' title='Back to basics'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>20</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-8382244388665262347</id><published>2011-03-13T13:04:00.000-04:00</published><updated>2011-03-13T13:04:36.906-04:00</updated><title type='text'>Recursion</title><content type='html'>Probably one of the more controversial topics in terms of usefulness. Today, I&#39;ll show you how to write some simple recursive functions and in an upcoming post, I&#39;ll show you guys how it can be useful outside of mathematical applications.&lt;br /&gt;
&lt;div&gt;So first off, what exactly is a recursive function. A recursive function is a function that keeps calling itself, until it reaches a base case. Once the base case is reached, then the function calls will return all the values to the previous function calls until the original call to the function returns its value.&lt;/div&gt;&lt;div&gt;This sounds like a lot, but I&#39;ll explain it using examples. First, let&#39;s look at the factorial function.&lt;/div&gt;&lt;div&gt;For example, we know that:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;4! = 4*3*2*1 = 24&lt;/div&gt;&lt;div&gt;5! = 5*4*3*2*1 = 120&lt;/div&gt;&lt;div&gt;etc.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Written as a recurrence relation, the factorial function looks like:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;a&lt;sub&gt;n&lt;/sub&gt; = n*a&lt;sub&gt;n-1&lt;/sub&gt;&lt;/div&gt;&lt;div&gt;a&lt;sub&gt;1&lt;/sub&gt; = 1&lt;br /&gt;
&lt;br /&gt;
So let&#39;s say we wanted to find the 3rd element in this relation, a3. It will be equal to 3 times a2&lt;br /&gt;
&lt;br /&gt;
a&lt;sub&gt;3&lt;/sub&gt; = 3*a&lt;sub&gt;2&lt;/sub&gt;&lt;br /&gt;
&lt;br /&gt;
and a&lt;sub&gt;2&lt;/sub&gt; is equal to 2 times a&lt;sub&gt;1&lt;/sub&gt;&lt;br /&gt;
&lt;br /&gt;
a&lt;sub&gt;2&lt;/sub&gt; = 2*a&lt;sub&gt;1&lt;/sub&gt;&lt;br /&gt;
&lt;br /&gt;
and a&lt;sub&gt;1&lt;/sub&gt; is 1&lt;br /&gt;
&lt;br /&gt;
a&lt;sub&gt;1&lt;/sub&gt; = 1 &amp;nbsp; &amp;nbsp;&lt;i&gt;(This is the base case)&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
So like this we can write&lt;br /&gt;
&lt;br /&gt;
a&lt;sub&gt;2&lt;/sub&gt; = 2*1&lt;br /&gt;
a&lt;sub&gt;3&lt;/sub&gt; = 3*(2*1) = 6&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;And we have our answer!&lt;br /&gt;
This is how a recursive function works. See how the function would keep &quot;calling&quot; itself until it reached a base case that was not a recursive call?&lt;br /&gt;
Now let&#39;s see how we can apply this as a function in C.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int factorial(int n)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(n==1 || n==0)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return 1;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;else&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return n*factorial(n-1);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Notice how each time a recursive call is made, we first check to see if n is our base case, and if not, we do recursive calls. Of course, this code is buggy in that if we passed a negative number into the function, it would loop forever, but simple modifications can fix that.&lt;br /&gt;
So now that you&#39;ve seen how it&#39;s done, you may be wondering how it &lt;i&gt;works&lt;/i&gt;.&lt;br /&gt;
Every time a recursive call is made, the scope of the previous call is held in memory and &quot;awaits&quot; an answer from the call that it made. With the example earlier where we calculated 3!, the first call, makes a another call which then makes another call. The 3rd call will return the base case which then gets multiplied by 2 and returned to the first call. The original call then multiplies 2 by 3 and then returns the value to wherever the original call was made.&lt;br /&gt;
&lt;br /&gt;
Later, I&#39;ll show you how to apply recursive functions to practical situations where math is not directly involved.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/8382244388665262347/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/recursion.html#comment-form' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/8382244388665262347'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/8382244388665262347'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/recursion.html' title='Recursion'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-1587050077171759788</id><published>2011-03-11T18:34:00.000-05:00</published><updated>2011-03-11T18:34:50.557-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Math"/><category scheme="http://www.blogger.com/atom/ns#" term="Opinions"/><title type='text'>Calculus</title><content type='html'>Being a computer science major, I need to take lots of different kinds of math courses. One of these classes is calculus. Now I&#39;d like to say that I like calculus as much as I like discrete mathematics or linear algebra, but that&#39;s not the case. Gone are the days when we would take derivatives of polynomials and that was it. Now it&#39;s like &quot;Oh what&#39;s that, you&#39;ve just finally understood u-substitution? Great because now we&#39;re going to start integration by parts. Also, remember the Cartesian coordinate system? Yeah so we&#39;re going to plot things based on r and theta now, not x and y.&quot; FML. I love math, I just don&#39;t like this particular area of it. Saying this, I do have to ensure everyone that I do understand its importance and usefulness. Calculus is a very useful tool for optimization problems, especially for civil and mechanical engineers. I&#39;m just not all that into it.&lt;br /&gt;
More discrete math please!</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/1587050077171759788/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/calculus.html#comment-form' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/1587050077171759788'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/1587050077171759788'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/calculus.html' title='Calculus'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-3784092639603785768</id><published>2011-03-10T16:41:00.000-05:00</published><updated>2011-03-10T16:41:34.921-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="arguments programming functions"/><title type='text'>Variable length argument lists</title><content type='html'>I wrote my midterm for computer programming today and a good portion of it focused on variable length argument lists. What is that you may ask? Well take a look at a random function:&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int square(int x)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return x*x;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;This function takes one argument - an integer which is multiplied by itself to give its square.&lt;/div&gt;&lt;div&gt;Now let&#39;s look at C&#39;s function printf() which is used to print text to the command prompt. We could simply tell it to print a string:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;printf(&quot;Hello&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;or we could use to print a value stored in a variable:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int x=6;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;printf(&quot;The value of x is %d&quot;,x);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;we can do as many variables as we want!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int x=3;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float y=6.3;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;printf(&quot;%d %f&quot;,x,y);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Now if you&#39;re like me when I started out with C, you&#39;re probably thinking &quot;How does the function know when to stop printing, and what types of variables to expect?&quot; Well we&#39;re not going to write out the implementation of printf() as that takes numerous cross-referencing libraries, but we are going to do a function with a variable length argument list that finds the average of a unspecified number of numbers.&lt;/div&gt;&lt;div&gt;The required functions are stored in stdarg.h so we first need to include that:&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;#include &amp;lt;stdarg.h&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Now that we have the proper tools, let&#39;s look at how a variable argument list is created. There are 4 main &quot;tools&quot; we will be using:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;1) va_list &lt;i&gt;identifier&lt;/i&gt;&lt;/div&gt;&lt;div&gt;This declares a variable of type va_list. This is sort of like a pointer to your arguments.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;2) va_start(&lt;i&gt;identifier,&amp;nbsp;first argument&lt;/i&gt;)&lt;/div&gt;&lt;div&gt;This tells the list where we&#39;re starting. The obvious location is the first argument. Note that you must have at least one defined parameter when dealing with variable length argument lists (more on this later)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;3) va_arg(&lt;i&gt;indentifier&lt;/i&gt;,&amp;nbsp;&lt;i&gt;type&lt;/i&gt;)&lt;/div&gt;&lt;div&gt;This is what we will be using to acquire the values form our arguments. Note that the identifier used here is the same one used to declare our va_list&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;4) va_end(&lt;i&gt;identifier&lt;/i&gt;)&lt;/div&gt;&lt;div&gt;This is just to clean up nicely. It tells our program &quot;Ok, we&#39;re done with this list of arguments, let&#39;s clean up now&quot;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;So now that we&#39;ve defined the necessary tools, let&#39;s get to the implementation of the function:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float average(int n,...)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;float sum=0;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;va_list arg;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;va_start(arg,n);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;for(int i=0;i&amp;lt;n;i++)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sum+=va_arg(arg,float);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;va_end(arg);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return sum/n;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;So let&#39;s go through it bit by bit:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;When declaring a function with a variable length argument list, you &lt;b&gt;MUST&lt;/b&gt;&amp;nbsp;have at least one definitive argument. In this case, we are taking that argument to be the number of numbers we would like to average. As we all know, to average numbers, you take the sum of the numbers (float sum), and then divide it by the amount of numbers you have (int n).&lt;/div&gt;&lt;div&gt;So we start off by declaring our va_list and initializing the va_start(). Note that after suing va_start, the pointer now points at the &lt;i&gt;2nd&lt;/i&gt;&amp;nbsp;argument (if available).&lt;/div&gt;&lt;div&gt;Next is our for loop which will loop n times to sum up all the integers. After doing that, we call va_end() to clean up. And then return sum/n, which will be our average!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;A sample call of this function could be:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float x = average(3,6,4,5);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;In which case, the value of x would be 5 since (4+5+6)/3 = (15/3) = 5&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;I hope this has been useful! I just thought I would share this piece of information with everyone!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/3784092639603785768/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/variable-length-argument-lists.html#comment-form' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/3784092639603785768'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/3784092639603785768'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/variable-length-argument-lists.html' title='Variable length argument lists'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8742182865769537021.post-8577061367150466619</id><published>2011-03-09T19:41:00.000-05:00</published><updated>2011-03-09T19:41:21.055-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="malloc c c++ dynamic memory tips tricks sizeof()"/><title type='text'>Using using malloc() to dynamically declare variables</title><content type='html'>If you&#39;re like me and used to using arrays to store primitive data types (or other data types for that matter), then you&#39;ll realize that there are some situations in which you do not initially know how big of an array you will need to store the data your user may enter. To get around this, we will dynamically declare data which will allow your program to effectively store an infinite number of variables (or until your computer runs out of memory).&lt;br /&gt;
To do this, we will be using a function called malloc() &amp;nbsp;(&lt;i&gt;memory allocation&lt;/i&gt;)&lt;br /&gt;
The syntax for malloc is as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;malloc((type*)sizeof(type));&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This may seem like a lot at first, but I&#39;ll break it down a bit starting from the right:&lt;br /&gt;
sizeof(type) will return the number of bytes which malloc will allocate to your program. For example, sizeof(char) will return 1 byte. Instead of using sizeof(), you could always just enter a number, but that&#39;s really bad practice, so I don&#39;t&amp;nbsp;recommend&amp;nbsp;it.&lt;br /&gt;
When you run malloc, it goes and asks the operating system &quot;Can I get this much memory for my program?&quot; and in general, it will return &lt;b&gt;&lt;i&gt;unspecified&lt;/i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;memory. This means that we have to cast it using (type*) because we know what this memory is being used for, but &lt;i&gt;malloc() does not&lt;/i&gt;!&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;So now that I&#39;ve&amp;nbsp;explained&amp;nbsp;the basics of malloc(), I&#39;ll give some examples:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int *p;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;p = malloc((int*)sizeof(int));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;See, we are starting off with a pointer to an integer and we are setting it equal to the memory allocated by malloc(). Useful isn&#39;t it?&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;This is great, but there are even more applications. Take a look at this code:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int *p;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;p = malloc(int*)10*sizeof(int));&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;Have you caught on? Basically, malloc() went and asked the operating system &quot;Can I get 10*sizeof(int) bytes to use?&quot;. We have gotten to enough memory for 10 integers which are all right beside each other in memory. What does this mean? We have dynamically created an array of integers. The multiplier can also be a variable. For example:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int x=42;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int *p;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;p = malloc(int*)x*sizeof(int));&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;There we go! An array of 42 integers. This can also be applied so that the user is asked to enter the size of the array and then an array of that size will be created.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;I hope this first lesson has been informative! Keep on coding and be creative!&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://flyingtoaster0.blogspot.com/feeds/8577061367150466619/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/using-using-malloc-to-dynamically.html#comment-form' title='17 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/8577061367150466619'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8742182865769537021/posts/default/8577061367150466619'/><link rel='alternate' type='text/html' href='http://flyingtoaster0.blogspot.com/2011/03/using-using-malloc-to-dynamically.html' title='Using using malloc() to dynamically declare variables'/><author><name>flyingtoaster0</name><uri>http://www.blogger.com/profile/15847518914387177510</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='23' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjDqaDYsgu8m-9vYB_I5qL4IOc6lYVYVFlqjOANoMBfjpxzxxLPGpuZz9rOaGmMlrJ9ZaFKlSV6Dji9xxGJGfP1Me_edXaLe5NbpRkInz_pst0nJz2IuTgBg7iTAdyMA/s220/FlyingToasters.jpg'/></author><thr:total>17</thr:total></entry></feed>