<?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: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-3800941631712763981</id><updated>2011-04-21T11:25:45.148-07:00</updated><title type='text'>E-books</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ab-ebooks.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3800941631712763981/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ab-ebooks.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Niranjan</name><uri>http://www.blogger.com/profile/13413521883177554840</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3800941631712763981.post-2431315504488084288</id><published>2007-09-24T00:41:00.002-07:00</published><updated>2007-09-24T00:47:33.509-07:00</updated><title type='text'>Web page disignign</title><content type='html'>&lt;p align="left"&gt;&lt;a name="about"&gt;&lt;/a&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;What is a Web  Page?&lt;/strong&gt;&lt;br /&gt;A web is a page with hypertext links that cross-reference text  in the Internet .A web page is also know as HTML pages because it is coded in  HTML language.&lt;br /&gt;Today web pages(HTML pages ) are the standard interface of the  internet.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Power of HTML&lt;/strong&gt;&lt;br /&gt;Earlier HTML pages could only  hold text.However, since the boom of Internet people have added more and more  capabilities to this langauge.&lt;br /&gt;It can now have images,animations,multimedia  contents and even interactive application.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;What is HTML ?&lt;/strong&gt;&lt;br /&gt;Most HTML tags have two parts the  strarting tag that indicates the start of text or formatting and the closing tag  that indicates the end of text of formatting .&lt;br /&gt;The closing tag is the same as  the starting tag,the only differneces is that it begins with a / just after the  &lt;&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Creating and editing web pages&lt;/strong&gt;&lt;br /&gt;Since a web page is a  text file it can be created or edited in any text editor. However, there is  application specially made for designing web pages. These applications are known  as HTML editors.&lt;br /&gt;Use any editor of your choice to create web  pages.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;&lt;a name="blank"&gt;&lt;/a&gt;A blank HTML page&lt;/strong&gt;&lt;br /&gt;A blank HTML page  has the following code:&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;&lt;title&gt;It  appears in the title bar&lt;/title&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;It  appears in the page&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Creating your first web page&lt;/strong&gt;&lt;br /&gt;The above written code  is a blank web page.Copy it to Notepad.Write the title of the page between the  &lt;title&gt; and &lt;/title&gt; tags.And write some one or two paragraphs of  the between the &lt;body&gt; and &lt;/body&gt; tags.&lt;br /&gt;Give the save command  and in the file name box type the filename inside double quotation("")with an  extension of '.htm'.Now you can open the document in any browser and view  it.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="tags"&gt;&lt;/a&gt;Tags and their Properties&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Most  of the HTML tags have their properties. The properties of every tag goes inside  the opening tag .A tag can have any number of properties separated by space  .Most of the properties have a value.For example if you are specifying the color  property then its value will be the name of the color. A tag with properties  will be written like.&lt;br /&gt;&lt;tag property1="value" property2="value"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Body tags and their meaning &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;table align="left" border="1" cellpadding="3" cellspacing="0" width="73%"&gt; &lt;tbody&gt; &lt;tr bg valign="top" style="color:#66ffff;"&gt; &lt;td width="27%"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Opening Tag&lt;/span&gt;&lt;/strong&gt;&lt;/td&gt; &lt;td width="26%"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Closing Tag&lt;/span&gt;&lt;/strong&gt;&lt;/td&gt; &lt;td bg width="47%" style="color:#66ffff;"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Use&lt;/span&gt;&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;body&gt; &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;/body&gt; &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Visible area of the HTML Page&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Formatting start and end.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;p&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;/p&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Paragraph start and end&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;hr /&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;[None] &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Horizontal line&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;[None] &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Line  Break&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;b&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;/b&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Start and end bold text.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;i&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;/i&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Start and end Italic text.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td height="22"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;u&gt; &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;/u&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Start and end Underline text.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt; &lt;/p&gt; &lt;p align="justify"&gt; &lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;&lt;title&gt;First  page&lt;/title&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;&lt;p align="center"&gt;&lt;br /&gt;&lt;span style="font-family:verdana;font-size:180%;color:green;"&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;Welcome to my  site&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;hr size="3" width="100%" color="red"&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;strong&gt;More tag propeties.&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Propeties                            Value&lt;/strong&gt;&lt;br /&gt;&lt;p&gt;  tag                         align Paragraph alignment[left,center,right and  justify]&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;h1&gt;to&lt;h6&gt;Tag        Heading one(It is the greatest font  size)                                      &lt;h2&gt;....&lt;h6&gt;It is  smallest font then the previous font size&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;hr /&gt; tag                        width Width of line in pixel or  percent&lt;br /&gt;                                    align alignment[left,center and  right]&lt;br /&gt;                                    Color Color or line(IE  only)&lt;br /&gt;                                    size size of the Horizontal  line&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;span&gt; Tag                     Font  face&lt;br /&gt;                                     Font  size&lt;br /&gt;                                     Font color&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;&lt;a name="list"&gt;&lt;/a&gt;List tags and their use&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt; &lt;/p&gt; &lt;table border="1" cellpadding="3" cellspacing="0" width="73%"&gt; &lt;tbody&gt; &lt;tr bg valign="top" style="color:#66ffff;"&gt; &lt;td width="27%"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Opening Tag&lt;/span&gt;&lt;/strong&gt;&lt;/td&gt; &lt;td width="26%"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Closing Tag&lt;/span&gt;&lt;/strong&gt;&lt;/td&gt; &lt;td bg width="47%" style="color:#66ffff;"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Use&lt;/span&gt;&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;ul&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;/ul&gt; &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Start and end of the bullet list&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;ol&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;/ol&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Start and end of the number list&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;dir&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;/dir&gt; &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Start and end of directory list&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;li&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;/li&gt; &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Start and end of the list item&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;div&gt; &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;/div&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Start and end of division or paragraph&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;img&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;none&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Insert image.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg valign="top" style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;a&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Hyperlink or anchor.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Tag Proepeties&lt;br /&gt;&lt;ul&gt;tag&lt;br /&gt;Type                          Type of  bullet(circle,sqaure or disc)&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;ol&gt; tag&lt;br /&gt;Type                          Type of numbering(1,A,a,I  or i)&lt;br /&gt;Start                          Beginning count of numbering  (e.g.1,2,3,4 etc)&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;div&gt;tag&lt;br /&gt;Align                           Alignment of  paragraph(left,center,right ro justify)&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;&lt;title&gt;List  &lt;/title&gt;&lt;br /&gt;&lt;/head&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;body&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Computer Course&lt;/strong&gt;  &lt;/p&gt;&lt;br /&gt;&lt;ol start="5" type="i"&gt;&lt;br /&gt;&lt;li&gt;Java&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Oracle&lt;/li&gt;&lt;br /&gt;&lt;li&gt;C++&lt;/li&gt;&lt;br /&gt;&lt;li&gt;  HTML&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Javascript&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;&lt;br /&gt;&lt;a name="img"&gt;&lt;/a&gt;img tag properties&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;table border="1" cellpadding="2" cellspacing="0" width="70%"&gt; &lt;tbody&gt; &lt;tr bg style="color:#66ffff;"&gt; &lt;td width="31%"&gt; &lt;div align="left"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Property&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt; &lt;td width="69%"&gt; &lt;div align="left"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Value&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;SRC&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Location of the image(e.g."c:\windows\circle.gif")&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;WIDTH&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Width of the image in pixel&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;HEIGHT&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Height of the image in pixel&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;ALT&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Alternate or tool-tip text&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;VSPACE &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Space to the right and left of image in pixels&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;HSPACE&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Space to the right and left of image in pixels&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;NAME&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Name  of the image.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;LOWSRC&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Location of a lower resolution image&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;ALIGN&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Alignment of text with imag.(top,middle,bottom  etc)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;&lt;title&gt;Image&lt;/title&gt;&lt;br /&gt;&lt;/head&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;body&gt;&lt;br /&gt;&lt;p align="center"&gt;&lt;strong&gt;Welcome to My  site&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="center"&gt;&lt;strong&gt;&lt;img src="C:/scene.jpg" alt="Click here" name="Image1" width="200" height="200" hspace="10" vspace="10" id="Image1" /&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;&lt;a name="a"&gt;&lt;/a&gt;Anchor tag properties&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Property                                    Value&lt;/strong&gt;&lt;br /&gt;&lt;a&gt;Tag&lt;br /&gt;Name                                   Name of the anchor&lt;br /&gt;HREF                                    Location of the file that is  referenced.&lt;br /&gt;TARGET                               Name of the window or frame  to open the target file.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;NOTE:  &lt;strong&gt;&lt;span style="font-size:78%;"&gt;Hyperlink is the part of the references another document.  When you click on a hyperlink the referenced document is opened. Anchor is a  reference point inside a document that can be referenced by a hyperlink.  When&lt;a&gt;tag is used as anchor it doesn't have a closing  tag.&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;&lt;a name="table"&gt;&lt;/a&gt;Table in an HTML document&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In  HTML a table begins with a &lt;table&gt; tag and ends with a  &lt;/table&gt;tag.&lt;br /&gt;Between the &lt;table&gt; tag there are the rows that are  enclosed between &lt;tr&gt;and &lt;/tr&gt;tags. So there is one pair of  &lt;tr&gt;and &lt;/tr&gt;tags for each row.&lt;br /&gt;Inside these rows are the cells,  which are enclosed between the &lt;td&gt; tag pairs inside every row should be  the same. The contents of the cell goes between the &lt;td&gt;and &lt;/td&gt;  tags.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;head&gt;&lt;title&gt;Table  &lt;/title&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;&lt;table&gt;&lt;br /&gt;         &lt;tr&gt;&lt;br /&gt;                 &lt;td&gt;&lt;br /&gt;                         Row 1, Col  1&lt;br /&gt;                 &lt;/td&gt;&lt;br /&gt;                 &lt;td&gt;&lt;br /&gt;                         Row  1, Col  2&lt;br /&gt;                 &lt;/td&gt;&lt;br /&gt;        &lt;/tr&gt;&lt;br /&gt;        &lt;tr&gt;&lt;br /&gt;                 &lt;td&gt;&lt;br /&gt;                         Row  2, Col  1&lt;br /&gt;                 &lt;/td&gt;&lt;br /&gt;                 &lt;td&gt;&lt;br /&gt;                        Row  2, Col  2&lt;br /&gt;                 &lt;/td&gt;&lt;br /&gt;       &lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Contents of a cell&lt;/strong&gt;&lt;br /&gt;The context of a cell is written  between the &lt;td&gt;and &lt;/td&gt;tags.A cell of table can contain any  text,HTML,image or even another table(i.e.you can have a table inside another  table).&lt;br /&gt;Tables are used in web pages to arrange the layout and /or to display  tabular data.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Table/cell Properties&lt;br /&gt;&lt;/strong&gt;&lt;table&gt;and  &lt;td&gt;tag&lt;strong&gt; &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;table border="1" cellpadding="2" cellspacing="0" width="61%"&gt; &lt;tbody&gt; &lt;tr bg style="color:#66ffff;"&gt; &lt;td width="31%"&gt; &lt;div align="left"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Property&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt; &lt;td width="69%"&gt; &lt;div align="left"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Value&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;WIDTH&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Width of table /cell in pixel or percent&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;HEIGHT&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Height of table/cell in pixel or percent&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;BGCOLOR&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Background color of table/cell&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;BACKGROUND&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Background image of table/cell&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;&lt;table&gt; Tag only&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; &lt;/span&gt;&lt;/p&gt; &lt;table border="1" cellpadding="2" cellspacing="0" width="61%"&gt; &lt;tbody&gt; &lt;tr bg style="color:#66ffff;"&gt; &lt;td width="31%"&gt; &lt;div align="left"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Property&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt; &lt;td width="69%"&gt; &lt;div align="left"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Value&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;BORDER&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Thickness of table border in pixel&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;BORDERCOLOR &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Color of table border&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;CELLSPACNING&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Space between cells in pixel&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#999999;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;CELLPADDING&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Space between cell border and content in  pixel&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;More tag properties&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;Property                         Value&lt;br /&gt;&lt;td&gt;tag  only&lt;br /&gt;ROWSPAN                      Number of rows the cell spans&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;html&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;&lt;title&gt;&lt;/title&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;&lt;table border="1" align="center" cellpadding="3" cellspacing="2" width="60%" height="80%"&gt;&lt;br /&gt;&lt;caption&gt;Simple Table With  Formatting&lt;/caption&gt;&lt;br /&gt;       &lt;tr&gt;&lt;br /&gt;              &lt;td&gt;&lt;br /&gt;                     Row  1, Col  1&lt;br /&gt;              &lt;/td&gt;&lt;br /&gt;              &lt;td&gt;&lt;br /&gt;                    Row  1, Col  2&lt;br /&gt;              &lt;/td&gt;&lt;br /&gt;      &lt;/tr&gt;&lt;br /&gt;      &lt;tr&gt;&lt;br /&gt;             &lt;td&gt;&lt;br /&gt;                    Row  2, Col  1&lt;br /&gt;             &lt;/td&gt;&lt;br /&gt;             &lt;td&gt;&lt;br /&gt;                    Row  2, Col  2&lt;br /&gt;             &lt;/td&gt;&lt;br /&gt;       &lt;/tr&gt;&lt;br /&gt;       &lt;tr&gt;&lt;br /&gt;              &lt;td colspan="2" rowspan="2" align="center" valign="center"&gt;&lt;br /&gt;              This  is a double-width, double-height cell with centered  contents.&lt;br /&gt;              &lt;/td&gt;&lt;br /&gt;       &lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Images in HTML document&lt;/strong&gt;&lt;br /&gt;As we learnt earlier, a web  page can only store text. So any images that appear inside the page is not  inside the HTML document.Actually the image is a different file and there is a  tag in the HTML page specifying the location of the image.The browser displays  the image in the page as if it were a part of that document.&lt;/span&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Image Formats in a HTML page&lt;/strong&gt;&lt;br /&gt;There are two types of  image formats used in web pages.GIF(Graphics Interchangeable Format ".gif")and  JPEG(Joint Photographics Expert Group ".jpg").The PNG(Portable Network Graphic  ".png") format is still consideration and most probably will be used as web  graphic format in the future.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Inserting image into the HTML page&lt;/strong&gt;&lt;br /&gt;IF you have a JPEG  or GIF image you can insert it into HTML page by inserting  the&lt;img&gt;tag.Refer to lecture 3 for the properties of the &lt;img&gt; tag  looks like:&lt;br /&gt;&lt;img src="image surce" width="image width" height="image  height" /&gt;&lt;br /&gt;Example &lt;img src="images/picture.gif" width="150" height="" /&gt;&lt;br /&gt;The SRC property of the &lt;img&gt; tag is must.All other tags  are optional.If you dono't specify the width and height property the image  dimesion is calculated automatically.If you don't specify the width and height  property the image resized in the browser while displaying. If the width and  height property is not specified then the browser will take a little longer time  to display the image as it has to calculated the values, so it is better to  specify them at design time.&lt;br /&gt;Other properties the&lt;img&gt; tag are ALT and  LOSRC.The ALT property is used to specify the text that will appear if the image  cannot be shown in the page or when the mouse moves will be loaded before the  actual high-resolution image is loaded .This property is used when low source  image instead of a blank page before the large image appears.&lt;br /&gt;The format will  be something like this:&lt;br /&gt;Example:&lt;br /&gt;&lt;img src="image/picture.gif  width=" height="30" alt="Home Buttom" lowsrc="images/smalliamge.gif" /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt; &lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;&lt;a name="forms"&gt;&lt;/a&gt;Forms in a HTML document&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;Forms are used in a web page to collect information form the user  .Generally user cannot write or edit a web page in the browser but in a form he  can type and enter data,which can be collect by the web site owner.&lt;br /&gt;For  example a from can be used to accept the username and password of a user to log  him onto the system or to take his details for any other purpose.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Tags for inserting a form&lt;/strong&gt;&lt;br /&gt;A form is inserted into a  web page using the &lt;form&gt; and&lt;/form&gt;tag.All the elements of a form  tag are put between these tags inside the &lt;input&gt;tag.The Type property of  the &lt;input&gt;tag determines the type of form element it is.For example  &lt;input type="text"&gt; will be a text box and &lt;input type="password"&gt;will be a password box.The &lt;input&gt;Tag doesnot have a  closing tag.&lt;br /&gt;All types of form fields are inserted using the &lt;input&gt;Tag  except the Drop Down and list Box.These are enclosed between &lt;select&gt; and  &lt;/select&gt;tags.The list items are placed between these tags.Each list item  is enclosed between a pair of &lt;option&gt; and &lt;/option&gt;tags.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;The type of elements in a from&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;table bg border="1" cellpadding="2" cellspacing="1" width="100%" style="color:#cccccc;"&gt; &lt;tbody&gt; &lt;tr bg style="color:#66ffff;"&gt; &lt;td width="19%"&gt; &lt;div align="left"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;From Element&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;td width="23%"&gt; &lt;div align="left"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;&lt;input&gt;Tag Type&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;td bg width="58%" style="color:#66ffff;"&gt; &lt;div align="left"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Text  Box&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Text&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Field where the user can enter any text&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Password Box&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Password&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Field where the user can enter password&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Text  Area&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Textarea&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Field where the user can enter multiple line of text&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Check box&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Checkbox&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Filed where the user can check one or more of available  option&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Radio Button&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Radio&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Filed where the user can select any one of available  option&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Button&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Button&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Command buttton used to enter a command&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Submit Button&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Submit&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Command button used to submit the form&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Reset Button &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Reset&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Command button used to reset the form&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Drop  Down Box&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt; &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Filed where the user can select an item from the drop down  menu&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;List  Box&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt; &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Field where the user can select one or more items from a  list&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Example&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;here  is a blank web page with only a from&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;html&gt;&lt;br /&gt;&lt;head&gt;&lt;br /&gt;&lt;title&gt;Form  Page&lt;/title&gt;&lt;br /&gt;&lt;/head&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;&lt;form&gt;&lt;br /&gt;Full  Name:&lt;input type="text" name="name"&gt;&lt;br /&gt;&lt;br /&gt;Gender:&lt;input type="radio" name="gender" value="male"&gt;Male&lt;input type="radio" name="Gender" value="female"&gt;Female&lt;br /&gt;&lt;br /&gt;Age Group:&lt;select name  ="age"&gt;&lt;br /&gt;&lt;option value="12"&gt;12&lt;/option&gt;&lt;br /&gt;&lt;option value="13"&gt;13&lt;/option&gt;&lt;br /&gt;&lt;option value="14"&gt;14&lt;/option&gt; &lt;br /&gt;&lt;option value="15"&gt;15&lt;/option&gt;&lt;br /&gt;&lt;option value="16"&gt;16&lt;/option&gt;&lt;br /&gt;&lt;/select&gt;&lt;br /&gt;&lt;input type="submit" value="submit form" type="reset" value="reset  From"&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;strong&gt;From Elements and their properties&lt;/strong&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;form&gt;Tag properties &lt;/span&gt;&lt;/strong&gt;&lt;/p&gt; &lt;table border="1" cellpadding="0" cellspacing="0" width="62%"&gt; &lt;tbody&gt; &lt;tr bg style="color:#66ffff;"&gt; &lt;td width="38%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Property&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td width="62%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;NAME&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Name  of the Form&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;METHOD&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;How  the form data will be sent(Get or Post)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;ACTION&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;The  script or program file that will handle the form  data&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt;&lt;strong&gt;Text Field/Password Field/File Field&lt;/strong&gt;&lt;/p&gt; &lt;table border="1" cellpadding="0" cellspacing="0" width="62%"&gt; &lt;tbody&gt; &lt;tr bg style="color:#66ffff;"&gt; &lt;td width="38%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Property&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td width="62%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;NAME&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Name  of the Field&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;SIZE&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Width of field in number of characters&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="color:#990000;"&gt;MAXLENGTH&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Themaximum number of character allowed (Including  space)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt;&lt;strong&gt;Check BOX/Radio Button&lt;span style="font-size:85%;"&gt;(INPUT  TYPE="CHECKBOX"&gt;&lt;input type="RADIO "&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt; &lt;table border="1" cellpadding="0" cellspacing="0" width="62%"&gt; &lt;tbody&gt; &lt;tr bg style="color:#66ffff;"&gt; &lt;td width="38%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Property&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td width="62%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;NAME&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Name  of the check box/radio button&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td height="19"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;VALUE&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Value to pass when checked&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;CHECKED&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Doesnot have a value,the box will appear checked initially  &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;BUTTON /SUBMIT BUTTON /RESET BUTTON&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;input type="button"&gt;/&lt;input type="submit"&gt;/&lt;input&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt; &lt;table border="1" cellpadding="0" cellspacing="0" width="62%"&gt; &lt;tbody&gt; &lt;tr bg style="color:#66ffff;"&gt; &lt;td width="38%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Property&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td width="62%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;NAME&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Name  of the Button(optional)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td height="19"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;VALUE&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Text  on the button face&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt; &lt;/p&gt; &lt;p align="justify"&gt;&lt;strong&gt;Hidden field &lt;input type ="hidden"&gt;&lt;/strong&gt;&lt;/p&gt; &lt;table border="1" cellpadding="0" cellspacing="0" width="62%"&gt; &lt;tbody&gt; &lt;tr bg style="color:#66ffff;"&gt; &lt;td width="38%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Property&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td width="62%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;NAME&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Name  of the field&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td height="19"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;VALUE&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;value of pass&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Drop Down/List  Box&lt;select&gt;&lt;option&gt;&lt;/select&gt;&lt;/span&gt;&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;select&gt; Tag&lt;/strong&gt;&lt;/p&gt; &lt;table border="1" cellpadding="0" cellspacing="0" width="62%"&gt; &lt;tbody&gt; &lt;tr bg style="color:#66ffff;"&gt; &lt;td width="38%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Property&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td width="62%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;NAME&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Name  of the field&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td height="19"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;SIZE&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Number of lines in the list box .&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;option&gt;Tag &lt;/span&gt;&lt;/strong&gt;&lt;/p&gt; &lt;table border="1" cellpadding="0" cellspacing="0" width="62%"&gt; &lt;tbody&gt; &lt;tr bg style="color:#66ffff;"&gt; &lt;td width="38%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Property&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td width="62%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;VALUE&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Value to be passed when selected&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td height="19"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;SELECTED&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Doesnot have a value,appears selected  initially&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Text  Area&lt;textarea&gt;&lt;/textarea&gt;&lt;/strong&gt;&lt;/span&gt;  &lt;table border="1" cellpadding="0" cellspacing="0" width="62%"&gt; &lt;tbody&gt; &lt;tr bg style="color:#66ffff;"&gt; &lt;td width="38%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Property&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt; &lt;td width="62%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#000000;"&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;NAME&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Name  of the field&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td height="19"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;ROWS&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Height of the field in number of line&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td height="19"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;COLS&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Width of the field in number of characters&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td height="19"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;WRAP&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Type  of text wrapping[off,virtual or physical]&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt; &lt;/p&gt; &lt;p align="justify"&gt;&lt;strong&gt;&lt;a name="frame"&gt;&lt;/a&gt;Frame&lt;/strong&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Until  now wach web page when opend takes over the entire browser screen.The browser  screen could not be split into separate(unique) sections,showing different but  related information.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The  HTML tags that divide a browser screen into two or more HTML recognizable unique  region is the &lt;frameset&gt;&lt;/frameset&gt; tags.Each unique region is  called a frame.Each frame can be loaded with a different document and  hence,allow multiple HTML documents to be seen concurrently.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The  HTML frame is a powerful feature that enables a web page to be broken into  different unique section that,although realated ,operate independently of each  other.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;The &lt;frameset&gt; Tag&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The  spliting of a browser screen into frames is accomplished with the  &lt;frameset&gt; and &lt;/frameset&gt; tags embedded into the HTML document .The  &lt;frameset&gt;&lt;/frameset&gt;tags require one of the following two  attributes depending on whethher the screen has to be divided into rows and  columns.&lt;/span&gt;&lt;/p&gt; &lt;table border="1" cellpadding="2" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr valign="top"&gt; &lt;td width="25%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;ROWS&lt;/span&gt;&lt;/td&gt; &lt;td width="75%"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This  attribute is used to divide the screen into multiple rows.It can be set equal to  a list of values.Depending on the require size of each row.The values can number  of pixel,percentage of screen resolution and the symbol of * which indicates the  remaining space of the screen&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;COLS&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This attribute is  used to divide the screen into multiple columns.It can be set equal to a list of  values.Depending on the require size of each Columns..The values can number of  pixel,percentage of screen resolution and the symbol of * which indicates the  remaining space of the screen&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;frameset rows=""&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;            &lt;frameset cols="50 %,50%"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;             &lt;/frameset&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;             &lt;frameset cols="50%,50%"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;             &lt;/frameset&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;/frameset&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The &lt;frame&gt; Tag&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Once  the browser screen is divided into rows(Horizontal sections)and columns  (Vertical Sections),Each unique section defined can be loaded with different  HTML documents.This is achieved by using the &lt;frame&gt;tag,which takes in the  following attributes :&lt;/span&gt;&lt;/p&gt; &lt;table border="1" cellpadding="2" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr bg style="color:#66ffff;"&gt; &lt;td width="24%"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Propery&lt;/span&gt;&lt;/strong&gt;&lt;/td&gt; &lt;td width="76%"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Value&lt;/span&gt;&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;SRC&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Indicates the URL of the document to be loaded into the  frame.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;MARGINHEIGHT&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Specifies the amount the amount of white space to be left at top and  bottom of the frame&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;MARGINWIDTH&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Specified the amount of white space to be along the sides of the  frame&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;NAME&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Gives the frame a unique name so it can be targeted by other  documents.The name given must begin with an Alphanumeric  character.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;NORSIZE&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Disables the frames resizing capability&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr bg style="color:#cccccc;"&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;SCROLLING&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#990000;"&gt;Controls the appearance of horizontall and vertical scrollbars in a  frame.This takes the values YES/NO/AUTO&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p align="justify"&gt;&lt;strong&gt;Example&lt;br /&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;FRAMESET  ROWS="30%,*"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;               &lt;frameset cols="50%,50%"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;                         &lt;frame src="file1.htm"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;                         &lt;frame src="file2.htm"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;                &lt;/frameset&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;               &lt;frameset cols="50%,50%"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;                         &lt;frame src="file3,htm"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;                         &lt;frame src="file4.htm"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;                 &lt;/frameset&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;/frameset&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3800941631712763981-2431315504488084288?l=ab-ebooks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ab-ebooks.blogspot.com/feeds/2431315504488084288/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3800941631712763981&amp;postID=2431315504488084288' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3800941631712763981/posts/default/2431315504488084288'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3800941631712763981/posts/default/2431315504488084288'/><link rel='alternate' type='text/html' href='http://ab-ebooks.blogspot.com/2007/09/web-page-disignign.html' title='Web page disignign'/><author><name>Niranjan</name><uri>http://www.blogger.com/profile/13413521883177554840</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3800941631712763981.post-1208249543677042211</id><published>2007-09-24T00:27:00.000-07:00</published><updated>2007-09-24T00:30:24.919-07:00</updated><title type='text'>About Java</title><content type='html'>&lt;h1 align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Introduction&lt;/span&gt;&lt;/h1&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Like any human language, Java provides a way to express concepts. If successful, this medium of expression will be significantly easier and more flexible than the alternatives as problems grow larger and more complex.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;You can’t look at Java as just a collection of features—some of the features make no sense in isolation. You can use the sum of the parts only if you are thinking about &lt;i&gt;design&lt;/i&gt;, not simply coding. And to understand Java in this way, you must understand the problems with it and with programming in general. This book discusses programming problems, why they are problems, and the approach Java has taken to solve them. Thus, the set of features I explain in each chapter are based on the way I see a particular type of problem being solved with the language. In this way I hope to move you, a little at a time, to the point where the Java mindset becomes your native tongue.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Throughout, I’ll be taking the attitude that you want to build a model in your head that allows you to develop a deep understanding of the language; if you encounter a puzzle you’ll be able to feed it to your model and deduce the answer.&lt;a name="_Toc312373769"&gt;&lt;/a&gt;&lt;a name="_Toc375545177"&gt;&lt;/a&gt;&lt;a name="_Toc479507356"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;div align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading6"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt; &lt;h2 align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Prerequisites&lt;/span&gt;&lt;/h2&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This book assumes that you have some programming familiarity: you understand that a program is a collection of statements, the idea of a subroutine/function/macro, control statements such as “if” and looping constructs such as “while,” etc. However, you might have learned this in many places, such as programming with a macro language or working with a tool like Perl. As long as you’ve programmed to the point where you feel comfortable with the basic ideas of programming, you’ll be able to work through this book. Of course, the book will be &lt;i&gt;easier&lt;/i&gt; for the C programmers and more so for the C++ programmers, but don’t count yourself out if you’re not experienced with those languages (but come willing to work hard; also, the multimedia CD that accompanies this book will bring you up to speed on the basic C syntax necessary to learn Java). I’ll be introducing the concepts of object-oriented programming (OOP) and Java’s basic control mechanisms, so you’ll be exposed to those, and the first exercises will involve the basic control-flow statements.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Although references will often be made to C and C++ language features, these are not intended to be insider comments, but instead to help all programmers put Java in perspective with those languages, from which, after all, Java is descended. I will attempt to make these references simple and to explain anything that I think a non- C/C++ programmer would not be familiar with.&lt;a name="_Toc312373770"&gt;&lt;/a&gt;&lt;a name="_Toc375545178"&gt;&lt;/a&gt;&lt;a name="_Toc479507357"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Although it is  based on C++, Java is more of a “pure” object-oriented  language.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Both C++ and Java are hybrid languages, but in Java the designers felt that the hybridization was not as important as it was in C++. A hybrid language allows multiple programming styles; the reason C++ is hybrid is to support backward compatibility with the C language. Because C++ is a superset of the C language, it includes many of that language’s undesirable features, which can make some aspects of C++ overly complicated.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The Java language assumes that you want to do only object-oriented programming. This means that before you can begin you must shift your mindset into an object-oriented world (unless it’s already there)&lt;i&gt;.&lt;/i&gt; The benefit of this initial effort is the ability to program in a language that is simpler to learn and to use than many other OOP languages. In this chapter we’ll see the basic components of a Java program and we’ll learn that everything in Java is an object, even a Java program.&lt;a name="_Toc375545217"&gt;&lt;/a&gt;&lt;a name="_Toc479507415"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading86"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h2 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;You  manipulate objects with references &lt;/span&gt;&lt;/h2&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Each programming language has its own means of manipulating data. Sometimes the programmer must be constantly aware of what type of manipulation is going on. Are you manipulating the object directly, or are you dealing with some kind of indirect representation (a pointer in C or C++) that must be treated with a special syntax?&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;All this is simplified in Java. You treat everything as an object, so there is a single consistent syntax that you use everywhere. Although you &lt;i&gt;treat &lt;/i&gt;everything as an object, the identifier you manipulate is actually a “reference” to an object. You might imagine this scene as a television (the object) with your remote control (the reference). As long as you’re holding this reference, you have a connection to the television, but when someone says “change the channel” or “lower the volume,” what you’re manipulating is the reference, which in turn modifies the object. If you want to move around the room and still control the television, you take the remote/reference with you, not the television.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Also, the remote control can stand on its own, with no television. That is, just because you have a reference doesn’t mean there’s necessarily an object connected to it. So if you want to hold a word or sentence, you create a &lt;b&gt;String&lt;/b&gt;  reference:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;String s;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;But here you’ve  created &lt;i&gt;only&lt;/i&gt; the reference, not an object. If you decided to send a  message to &lt;b&gt;s&lt;/b&gt; at this point, you’ll get an error (at run-time) because  &lt;b&gt;s&lt;/b&gt; isn’t actually attached to anything (there’s no television). A safer practice, then, is always to initialize a reference when you create it:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;String s = &lt;span style="color: rgb(0, 68, 136);"&gt;"asdf"&lt;/span&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;However, this uses a special Java feature: strings can be initialized with quoted text. Normally, you must use a more general type of initialization for objects.&lt;a name="_Toc375545218"&gt;&lt;/a&gt;&lt;a name="_Toc479507416"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading87"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h2 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;You  must create&lt;br /&gt;all the objects&lt;/span&gt;&lt;/h2&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;When you create a  reference, you want to connect it with a new object. You do so, in general, with  the &lt;b&gt;new&lt;/b&gt; keyword. &lt;b&gt;new&lt;/b&gt; says, “Make me a new one of these objects.”  So in the above example, you can say:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;String s = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; String(&lt;span style="color: rgb(0, 68, 136);"&gt;"asdf"&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Not only does this  mean “Make me a new &lt;b&gt;String&lt;/b&gt;,” but it also gives information about  &lt;i&gt;how&lt;/i&gt; to make the &lt;b&gt;String&lt;/b&gt; by supplying an initial character  string.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Of course,  &lt;b&gt;String&lt;/b&gt; is not the only type that exists. Java comes with a plethora of ready-made types. What’s more important is that you can create your own types. In fact, that’s the fundamental activity in Java programming, and it’s what you’ll be learning about in the rest of this book.&lt;a name="_Toc375545219"&gt;&lt;/a&gt;&lt;a name="_Toc479507417"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading88"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Where  storage lives&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;It’s useful to visualize some aspects of how things are laid out while the program is running, in particular how memory is arranged. There are six different places to store data:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;ol&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Registers&lt;/b&gt;. This is the fastest storage because it exists in a place different from that of other storage: inside the processor. However, the number of registers is severely limited, so registers are allocated by the compiler according to its needs. You don’t have direct control, nor do you see any evidence in your programs that registers even exist.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;The stack&lt;/b&gt;.  This lives in the general RAM (random-access memory) area, but has direct  support from the processor via its &lt;i&gt;stack pointer&lt;/i&gt;. The stack pointer is moved down to create new memory and moved up to release that memory. This is an extremely fast and efficient way to allocate storage, second only to registers. The Java compiler must know, while it is creating the program, the exact size and lifetime of all the data that is stored on the stack, because it must generate the code to move the stack pointer up and down. This constraint places limits on the flexibility of your programs, so while some Java storage exists on the stack—in particular, object references—Java objects themselves are not placed on the stack.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;The heap&lt;/b&gt;. This is a general-purpose pool of memory (also in the RAM area) where all Java objects live. The nice thing about the heap is that, unlike the stack, the compiler doesn’t need to know how much storage it needs to allocate from the heap or how long that storage must stay on the heap. Thus, there’s a great deal of flexibility in using storage on the heap. Whenever you need to create an object, you simply write the code to create it using &lt;b&gt;new&lt;/b&gt;,&lt;b&gt; &lt;/b&gt;and the storage is allocated on the heap when that code is executed. Of course there’s a price you pay for this flexibility: it takes more time to allocate heap storage than it does to allocate stack storage (that is, if you even &lt;i&gt;could&lt;/i&gt; create  objects on the stack in Java, as you can in C++).&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Static  storage&lt;/b&gt;. “Static” is used here in the sense of “in a fixed location” (although it’s also in RAM). Static storage contains data that is available for the entire time a program is running. You can use the &lt;b&gt;static&lt;/b&gt; keyword to specify that a particular element of an object is static, but Java objects themselves are never placed in static storage.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Constant  storage&lt;/b&gt;. Constant values are often placed directly in the program code, which is safe since they can never change. Sometimes constants are cordoned off by themselves so that they can be optionally placed in read-only memory (ROM).&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Non-RAM  storage&lt;/b&gt;. If data lives completely outside a program it can exist while the program is not running, outside the control of the program. The two primary examples of this are &lt;i&gt;streamed objects,&lt;/i&gt; in which objects are turned into  streams of bytes, generally to be sent to another machine, and &lt;i&gt;persistent  objects, &lt;/i&gt;in which the objects are placed on disk so they will hold their state even when the program is terminated. The trick with these types of storage is turning the objects into something that can exist on the other medium, and yet can be resurrected into a regular RAM-based object when necessary. Java provides support for &lt;i&gt;lightweight persistence&lt;/i&gt;, and future versions of Java  might provide more complete solutions for persistence.&lt;a name="_Toc375545220"&gt;&lt;/a&gt;&lt;a name="_Toc479507418"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading89"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Special  case: primitive types&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;There is a group of types that gets special treatment; you can think of these as “primitive” types that you use quite often in your programming. The reason for the special treatment is that to create an object with &lt;b&gt;new&lt;/b&gt;—especially a small, simple  variable—isn’t very efficient because &lt;b&gt;new&lt;/b&gt; places objects on the heap. For these types Java falls back on the approach taken by C and C++. That is, instead of creating the variable using &lt;b&gt;new&lt;/b&gt;, an “automatic” variable is created  that &lt;i&gt;is not a reference&lt;/i&gt;. The variable holds the value, and it’s placed on  the stack so it’s much more efficient.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Java determines the size of each primitive type. These sizes don’t change from one machine architecture to another as they do in most languages. This size invariance is one reason Java programs are so portable.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="center"&gt; &lt;table border="1"&gt; &lt;tbody&gt; &lt;tr valign="top"&gt; &lt;th valign="top" width="72"&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Primitive  type&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/th&gt; &lt;th valign="top" width="45"&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Size&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/th&gt; &lt;th valign="top" width="72"&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Minimum&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/th&gt; &lt;th valign="top" width="85"&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Maximum&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/th&gt; &lt;th valign="top" width="78"&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Wrapper  type&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/th&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;boolean&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;1-bit&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;—&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;—&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Boolean&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;char&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;16-bit&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Unicode  0&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Unicode  2&lt;sup&gt;16&lt;/sup&gt;- 1&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Character&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;byte  &lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;8-bit&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;-128&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;+127&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Byte&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;short&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;16-bit&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;-2&lt;sup&gt;15&lt;/sup&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;+2&lt;sup&gt;15&lt;/sup&gt;—1&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Short&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;int&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;32-bit&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;-2&lt;sup&gt;31&lt;/sup&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;+2&lt;sup&gt;31&lt;/sup&gt;—1&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Integer&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;long&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;64-bit&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;-2&lt;sup&gt;63&lt;/sup&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;+2&lt;sup&gt;63&lt;/sup&gt;—1&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Long&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;float&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;32-bit&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;IEEE754&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;IEEE754&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Float&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;double&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;64-bit&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;IEEE754&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;IEEE754&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Double&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;void&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;—&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;—&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;—&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Void&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;All numeric types  are signed, so don’t go looking for unsigned types.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The primitive data  types also have “wrapper”&lt;i&gt; &lt;/i&gt;classes for them. That means that if you want to make a nonprimitive object on the heap to represent that primitive type, you use the associated wrapper. For example:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;char&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; c = 'x';&lt;br /&gt;Character C = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Character(c);&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Or you could also  use:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Character C = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Character('x');&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The reasons for  doing this will be shown in a later chapter.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading90"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h4 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;High-precision numbers&lt;/span&gt;&lt;/h4&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Java includes two  classes for performing high-precision arithmetic: &lt;b&gt;BigInteger&lt;/b&gt; and  &lt;b&gt;BigDecimal&lt;/b&gt;. Although these approximately fit into the same category as  the “wrapper” classes, neither one has a primitive  analogue.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Both classes have methods that provide analogues for the operations that you perform on primitive types. That is, you can do anything with a &lt;b&gt;BigInteger&lt;/b&gt; or &lt;b&gt;BigDecimal  &lt;/b&gt;that you can with an &lt;b&gt;int&lt;/b&gt; or &lt;b&gt;float&lt;/b&gt;, it’s just that you must use method calls instead of operators. Also, since there’s more involved, the operations will be slower. You’re exchanging speed for accuracy.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;BigInteger&lt;/b&gt; supports arbitrary-precision integers. This means that you can accurately represent integral values of any size without losing any information during operations.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;BigDecimal&lt;/b&gt;  is for arbitrary-precision fixed-point numbers; you can use these for accurate  monetary calculations, for example.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Consult your online  documentation for details about the constructors and methods you can call for  these two classes.&lt;a name="_Toc375545221"&gt;&lt;/a&gt;&lt;a name="_Toc479507419"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading91"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Arrays  in Java&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Virtually all programming languages support arrays. Using arrays in C and C++ is perilous because those arrays are only blocks of memory. If a program accesses the array outside of its memory block or uses the memory before initialization (common programming errors) there will be unpredictable results.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;One of the primary goals of Java is safety, so many of the problems that plague programmers in C and C++ are not repeated in Java. A Java array is guaranteed to be initialized and cannot be accessed outside of its range. The range checking comes at the price of having a small amount of memory overhead on each array as well as verifying the index at run-time, but the assumption is that the safety and increased productivity is worth the expense.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;When you create an array of objects, you are really creating an array of references, and each of those references is automatically initialized to a special value with its own keyword: &lt;a name="Index184"&gt;&lt;/a&gt;&lt;a name="Index185"&gt;&lt;/a&gt;&lt;b&gt;null&lt;/b&gt;. When Java sees  &lt;b&gt;null&lt;/b&gt;, it recognizes that the reference in question isn’t pointing to an  object.&lt;b&gt; &lt;/b&gt;You must assign an object to each reference before you use it,  and if you try to use a reference that’s still &lt;b&gt;null,&lt;/b&gt; the problem will be  reported at run-time. Thus, typical array errors are prevented in  Java.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;You can also create an array of primitives. Again, the compiler guarantees initialization because it zeroes the memory for that array.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Arrays will be  covered in detail in later chapters.&lt;a name="_Toc375545222"&gt;&lt;/a&gt;&lt;a name="_Toc479507420"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading92"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h2 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;You  never need to destroy an object&lt;/span&gt;&lt;/h2&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;In most programming languages, the concept of the lifetime of a variable occupies a significant portion of the programming effort. How long does the variable last? If you are supposed to destroy it, when should you? Confusion over variable lifetimes can lead to a lot of bugs, and this section shows how Java greatly simplifies the issue by doing all the cleanup work for you.&lt;a name="_Toc375545223"&gt;&lt;/a&gt;&lt;a name="_Toc479507421"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading93"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Scoping&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Most procedural  languages have the concept of &lt;i&gt;scope&lt;/i&gt;. This determines both the visibility and lifetime of the names defined within that scope. In C, C++, and Java, scope is determined by the placement of curly braces &lt;b&gt;{}&lt;/b&gt;. So for  example:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;{&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; x = 12;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/* only x available */&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; q = 96;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/* both x &amp;amp; q available */&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/* only x available */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;/* q “out of scope” */&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;A variable defined  within a scope is available only to the end of that scope.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Indentation makes Java code easier to read. Since Java is a free-form language, the extra spaces, tabs, and carriage returns do not affect the resulting program.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Note that you  &lt;i&gt;cannot&lt;/i&gt; do the following, even though it is legal in C and  C++:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;{&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; x = 12;&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; x = 96; &lt;span style="color: rgb(0, 153, 0);"&gt;/* illegal */&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The compiler will  announce that the variable &lt;b&gt;x &lt;/b&gt;has already been defined. Thus the C and C++ ability to “hide” a variable in a larger scope is not allowed because the Java designers thought that it led to confusing programs.&lt;a name="_Toc375545224"&gt;&lt;/a&gt;&lt;a name="_Toc479507422"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading94"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Scope  of objects&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Java objects do not  have the same lifetimes as primitives. When you create a Java object using  &lt;b&gt;new&lt;/b&gt;, it hangs around past the end of the scope. Thus if you  use:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;{&lt;br /&gt;String s = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; String(&lt;span style="color: rgb(0, 68, 136);"&gt;"a string"&lt;/span&gt;);&lt;br /&gt;} &lt;span style="color: rgb(0, 153, 0);"&gt;/* end of scope */&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;the reference  &lt;b&gt;s&lt;/b&gt; vanishes at the end of the scope. However, the &lt;b&gt;String&lt;/b&gt; object  that &lt;b&gt;s&lt;/b&gt; was pointing to is still occupying memory. In this bit of code, there is no way to access the object because the only reference to it is out of scope. In later chapters you’ll see how the reference to the object can be passed around and duplicated during the course of a program.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;It turns out that  because objects created with &lt;b&gt;new&lt;/b&gt; stay around for as long as you want them, a whole slew of C++ programming problems simply vanish in Java. The hardest problems seem to occur in C++ because you don’t get any help from the language in making sure that the objects are available when they’re needed. And more important, in C++ you must make sure that you destroy the objects when you’re done with them.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;That brings up an interesting question. If Java leaves the objects lying around, what keeps them from filling up memory and halting your program? This is exactly the kind of problem that would occur in C++. This is where a bit of magic happens. Java has a &lt;i&gt;garbage collector&lt;/i&gt;, which looks at all the objects that were created  with &lt;b&gt;new&lt;/b&gt; and figures out which ones are not being referenced anymore. Then it releases the memory for those objects, so the memory can be used for new objects. This means that you never need to worry about reclaiming memory yourself. You simply create objects, and when you no longer need them they will go away by themselves. This eliminates a certain class of programming problem: the so-called “memory leak,” in which a programmer forgets to release memory.&lt;a name="_Toc375545225"&gt;&lt;/a&gt;&lt;a name="_Toc479507423"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading95"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h2 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Creating new data types: class&lt;/span&gt;&lt;/h2&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;If everything is an object, what determines how a particular class of object looks and behaves? Put another way, what establishes the &lt;i&gt;type&lt;/i&gt; of an object? You might expect there to be a keyword called “type,” and that certainly would have made sense. Historically, however, most object-oriented languages have used the keyword &lt;b&gt;class&lt;/b&gt; to mean “I’m about to tell you what a new type of object looks  like.” The &lt;b&gt;class&lt;/b&gt; keyword (which is so common that it will not be emboldened throughout this book) is followed by the name of the new type. For example:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;class&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; ATypeName { &lt;span style="color: rgb(0, 153, 0);"&gt;/* class body goes here */&lt;/span&gt; }&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This introduces a  new type, so you can now create an object of this type using  &lt;b&gt;new&lt;/b&gt;:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;ATypeName a = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ATypeName();&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;In  &lt;b&gt;ATypeName&lt;/b&gt;, the class body consists only of a comment (the stars and slashes and what is inside, which will be discussed later in this chapter), so there is not too much that you can do with it. In fact, you cannot tell it to do much of anything (that is, you cannot send it any interesting messages) until you define some methods for it.&lt;a name="_Toc375545226"&gt;&lt;/a&gt;&lt;a name="_Toc479507424"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading96"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Fields  and methods&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;When you define a class (and all you do in Java is define classes, make objects of those classes, and send messages to those objects), you can put two types of elements in your class: data members (sometimes called &lt;i&gt;fields&lt;/i&gt;), and member functions  (typically called &lt;i&gt;methods&lt;/i&gt;). A data member is an object of any type that you can communicate with via its reference. It can also be one of the primitive types (which isn’t a reference). If it is a reference to an object, you must initialize that reference to connect it to an actual object (using &lt;b&gt;new&lt;/b&gt;,  as seen earlier) in a special function called a &lt;i&gt;constructor&lt;/i&gt; (described fully in Chapter 4). If it is a primitive type you can initialize it directly at the point of definition in the class. (As you’ll see later, references can also be initialized at the point of definition.)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Each object keeps its own storage &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; its data members; the data members are not shared among objects. Here is an example of a &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; with some data members:&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; DataOnly {&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; i;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;float&lt;/span&gt; f;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;boolean&lt;/span&gt; b;&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This class doesn’t  &lt;i&gt;do&lt;/i&gt; anything, but you can create an object:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;DataOnly d = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; DataOnly();&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;You can assign values to the data members, but you must first know how to refer to a member of an object. This is accomplished by stating the name of the object reference, followed by a period (dot), followed by the name of the member inside the object:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;objectReference.member&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;For  example:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;d.i = 47;&lt;br /&gt;d.f = 1.1f;&lt;br /&gt;d.b = &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;It is also possible that your object might contain other objects that contain data you’d like to modify. For this, you just keep “connecting the dots.” For example:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;myPlane.leftTank.capacity = 100;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The &lt;b&gt;DataOnly  &lt;/b&gt;class cannot do much of anything except hold data, because it has no member functions (methods). To understand how those work, you must first understand &lt;i&gt;arguments&lt;/i&gt; and &lt;i&gt;return values&lt;/i&gt;, which will be described  shortly.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading97"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h4 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Default  values for primitive members&lt;/span&gt;&lt;/h4&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;When a primitive  data type is a member of a class, it is guaranteed to get a default value if you  do not initialize it:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="center"&gt; &lt;table border="1"&gt; &lt;tbody&gt; &lt;tr valign="top"&gt; &lt;th valign="top" width="100"&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Primitive  type&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/th&gt; &lt;th valign="top" width="106"&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;Default&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/th&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;boolean&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;false&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;char&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;‘\u0000’  (null)&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;byte&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;(byte)0&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;short&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;(short)0&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;int&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;0&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;long&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;0L&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;float&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;0.0f&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;double&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;0.0d&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Note carefully that  the default values are what Java guarantees when the variable is used &lt;i&gt;as a  member of a class&lt;/i&gt;. This ensures that member variables of primitive types will always be initialized (something C++ doesn’t do), reducing a source of bugs. However, this initial value may not be correct or even legal for the program you are writing. It’s best to always explicitly initialize your variables.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This guarantee doesn’t apply to “local” variables—those that are not fields of a class. Thus, if within a function definition you have:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;int&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; x;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Then &lt;b&gt;x&lt;/b&gt; will get some arbitrary value (as in C and C++); it will not automatically be initialized to zero. You are responsible for assigning an appropriate value before you use &lt;b&gt;x&lt;/b&gt;. If you forget, Java definitely improves on C++: you get a compile-time error telling you the variable might not have been initialized. (Many C++ compilers will warn you about uninitialized variables, but in Java these are errors.)&lt;a name="_Toc375545227"&gt;&lt;/a&gt;&lt;a name="_Toc479507425"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading98"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h2 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Methods, arguments, and return values&lt;/span&gt;&lt;/h2&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Up until now, the  term &lt;i&gt;function&lt;/i&gt; has been used to describe a named subroutine. The term that  is more commonly used in Java is &lt;i&gt;method,&lt;/i&gt; as in “a way to do something.” If you want, you can continue thinking in terms of functions. It’s really only a syntactic difference, but from now on “method” will be used in this book rather than “function.”&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Methods in Java determine the messages an object can receive. In this section you will learn how simple it is to define a method.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The fundamental  parts of a method are the name, the arguments, the return type, and the body.  Here is the basic form:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;returnType methodName( &lt;span style="color: rgb(0, 153, 0);"&gt;/* argument list */&lt;/span&gt; ) {&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/* Method body */&lt;/span&gt;&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The return type is the type of the value that pops out of the method after you call it. The argument list gives the types and names for the information you want to pass into the method. The method name and argument list together uniquely identify the method.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Methods in Java can  be created only as part of a class. A method can be called only for an object,&lt;a href="post-create.g?blogID=3800941631712763981#fn22" name="fnB22"&gt;[22]&lt;/a&gt; and that object must be able to perform that method call. If you try to call the wrong method for an object, you’ll get an error message at compile-time. You call a method for an object by naming the object followed by a period (dot), followed by the name of the method and its argument list, like this: &lt;b&gt;objectName.methodName(arg1, arg2, arg3)&lt;/b&gt;. For  example, suppose you have a method &lt;b&gt;f( )&lt;/b&gt; that takes no arguments and  returns a value of type &lt;b&gt;int&lt;/b&gt;. Then, if you have an object called &lt;b&gt;a&lt;/b&gt;  for which &lt;b&gt;f( )&lt;/b&gt; can be called, you can say this:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;int&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; x = a.f();&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The type of the  return value must be compatible with the type of &lt;b&gt;x&lt;/b&gt;.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This act of calling  a method is commonly referred to as &lt;i&gt;sending a message to an object&lt;/i&gt;. In  the above example, the message is &lt;b&gt;f( )&lt;/b&gt; and the object is &lt;b&gt;a&lt;/b&gt;.  Object-oriented programming is often summarized as simply “sending messages to  objects.”&lt;a name="_Toc375545228"&gt;&lt;/a&gt;&lt;a name="_Toc479507426"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading99"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The  argument list&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The method argument list specifies what information you pass into the method. As you might guess, this information—like everything else in Java—takes the form of objects. So, what you must specify in the argument list are the types of the objects to pass in and the name to use for each one. As in any situation in Java where you seem to be handing objects around, you are actually passing references&lt;a href="post-create.g?blogID=3800941631712763981#fn23" name="fnB23"&gt;[23]&lt;/a&gt;. The type of the reference must be correct, however. If the  argument is supposed to be a &lt;b&gt;String&lt;/b&gt;, what you pass in must be a  string.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Consider a method  that takes a &lt;b&gt;String&lt;/b&gt; as its argument. Here is the definition, which must  be placed within a class definition for it to be compiled:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;int&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; storage(String s) {&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; s.length() * 2;&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This method tells  you how many bytes are required to hold the information in a particular  &lt;b&gt;String. &lt;/b&gt;(Each &lt;b&gt;char &lt;/b&gt;in a &lt;b&gt;String &lt;/b&gt;is 16 bits, or two bytes,  long, to support Unicode characters.) The argument is of type &lt;b&gt;String&lt;/b&gt; and  is called &lt;b&gt;s&lt;/b&gt;. Once &lt;b&gt;s&lt;/b&gt; is passed into the method, you can treat it  just like any other object. (You can send messages to it.) Here, the  &lt;b&gt;length( )&lt;/b&gt; method is called, which is one of the methods for  &lt;b&gt;String&lt;/b&gt;s; it returns the number of characters in a  string.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;You can also see  the use of the &lt;b&gt;return&lt;/b&gt; keyword, which does two things. First, it means “leave the method, I’m done.” Second, if the method produces a value, that value is placed right after the &lt;b&gt;return&lt;/b&gt; statement. In this case, the return  value is produced by evaluating the expression &lt;b&gt;s.length( ) *  2&lt;/b&gt;.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;You can return any type you want, but if you don’t want to return anything at all, you do so by indicating that the method returns &lt;b&gt;void&lt;/b&gt;. Here are some  examples:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;boolean&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; flag() { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;true&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;; }&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;float&lt;/span&gt; naturalLogBase() { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; 2.718f; }&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; nothing() { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;; }&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; nothing2() {}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;When the return  type is &lt;b&gt;void&lt;/b&gt;, then the &lt;b&gt;return&lt;/b&gt; keyword is used only to exit the method, and is therefore unnecessary when you reach the end of the method. You can return from a method at any point, but if you’ve given a non-&lt;b&gt;void  &lt;/b&gt;return type then the compiler will force you (with error messages) to return the appropriate type of value regardless of where you return.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;At this point, it can look like a program is just a bunch of objects with methods that take other objects as arguments and send messages to those other objects. That is indeed much of what goes on, but in the following chapter you’ll learn how to do the detailed low-level work by making decisions within a method. For this chapter, sending messages will suffice.&lt;a name="_Toc375545229"&gt;&lt;/a&gt;&lt;a name="_Toc479507427"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading100"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h2 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Building a Java program&lt;/span&gt;&lt;/h2&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;There are several  other issues you must understand before seeing your first Java program.&lt;a name="_Toc375545230"&gt;&lt;/a&gt;&lt;a name="_Toc479507428"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading101"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Name  visibility&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;A problem in any programming language is the control of names. If you use a name in one module of the program, and another programmer uses the same name in another module, how do you distinguish one name from another and prevent the two names from “clashing?” In C this is a particular problem because a program is often an unmanageable sea of names. C++ classes (on which Java classes are based) nest functions within classes so they cannot clash with function names nested within other classes. However, C++ still allowed global data and global functions, so clashing was still possible. To solve this problem, C++ introduced &lt;i&gt;namespaces&lt;/i&gt; using  additional keywords.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Java was able to avoid all of this by taking a fresh approach. To produce an unambiguous name for a library, the specifier used is not unlike an Internet domain name. In fact, the Java creators want you to use your Internet domain name in reverse since those are guaranteed to be unique. Since my domain name is &lt;b&gt;BruceEckel.com&lt;/b&gt;, my utility library of foibles would be named  &lt;b&gt;com.bruceeckel.utility.foibles&lt;/b&gt;. After your reversed domain name, the dots  are intended to represent subdirectories.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;In Java 1.0 and  Java 1.1 the domain extensions &lt;b&gt;com&lt;/b&gt;, &lt;b&gt;edu&lt;/b&gt;, &lt;b&gt;org&lt;/b&gt;, &lt;b&gt;net&lt;/b&gt;,  etc., were &lt;a name="Index186"&gt;&lt;/a&gt;&lt;a name="Index187"&gt;&lt;/a&gt;capitalized by convention,  so the library would appear: &lt;b&gt;COM.bruceeckel.utility.foibles&lt;/b&gt;. Partway through the development of Java 2, however, it was discovered that this caused problems, and so now the entire package name is lowercase.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This mechanism means that all of your files automatically live in their own namespaces, and each class within a file must have a unique identifier. So you do not need to learn special language features to solve this problem—the language takes care of it for you.&lt;a name="_Toc375545231"&gt;&lt;/a&gt;&lt;a name="_Toc479507429"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading102"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Using  other components&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Whenever you want to use a predefined class in your program, the compiler must know how to locate it. Of course, the class might already exist in the same source code file that it’s being called from. In that case, you simply use the class—even if the class doesn’t get defined until later in the file. Java eliminates the “forward referencing” problem so you don’t need to think about it.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;What about a class that exists in some other file? You might think that the compiler should be smart enough to simply go and find it, but there is a problem. Imagine that you want to use a class of a particular name, but more than one definition for that class exists (presumably these are different definitions). Or worse, imagine that you’re writing a program, and as you’re building it you add a new class to your library that conflicts with the name of an existing class.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;To solve this problem, you must eliminate all potential ambiguities. This is accomplished by telling the Java compiler exactly what classes you want using the &lt;b&gt;import&lt;/b&gt;  keyword. &lt;b&gt;import &lt;/b&gt;tells the compiler to bring in a &lt;i&gt;package&lt;/i&gt;, which is a library of classes. (In other languages, a library could consist of functions and data as well as classes, but remember that all code in Java must be written inside a class.)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Most of the time you’ll be using components from the standard Java libraries that come with your compiler. With these, you don’t need to worry about long, reversed domain names; you just say, for example:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;import&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; java.util.ArrayList;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;to tell the  compiler that you want to use Java’s &lt;b&gt;ArrayList&lt;/b&gt; class. However,  &lt;b&gt;util&lt;/b&gt; contains a number of classes and you might want to use several of them without declaring them all explicitly. This is easily accomplished by using ‘&lt;b&gt;*&lt;/b&gt;’ to indicate a wild card:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;import&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; java.util.*;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;It is more common  to import a collection of classes in this manner than to import classes  individually.&lt;a name="_Toc375545232"&gt;&lt;/a&gt;&lt;a name="_Toc479507430"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading103"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The  static keyword&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Ordinarily, when you create a class you are describing how objects of that class look and how they will behave. You don’t actually get anything until you create an object of that class with &lt;b&gt;new&lt;/b&gt;, and at that point data storage is created and  methods become available.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;But there are two situations in which this approach is not sufficient. One is if you want to have only one piece of storage for a particular piece of data, regardless of how many objects are created, or even if no objects are created. The other is if you need a method that isn’t associated with any particular object of this class. That is, you need a method that you can call even if no objects are created. You can achieve both of these effects with the &lt;b&gt;static&lt;/b&gt; keyword. When you say  something is &lt;b&gt;static&lt;/b&gt;, it means that data or method is not tied to any particular object instance of that class. So even if you’ve never created an object of that class you can call a &lt;b&gt;static&lt;/b&gt; method or access a piece of  &lt;b&gt;static&lt;/b&gt; data. With ordinary, non-&lt;b&gt;static&lt;/b&gt; data and methods you must  create an object and use that object to access the data or method, since  non-&lt;b&gt;static&lt;/b&gt; data and methods must know the particular object they are  working with. Of course, since &lt;b&gt;static&lt;/b&gt; methods don’t need any objects to  be created before they are used, they cannot &lt;i&gt;directly &lt;/i&gt;access  non-&lt;b&gt;static&lt;/b&gt; members or methods by simply calling those other members  without referring to a named object (since non-&lt;b&gt;static&lt;/b&gt; members and methods  must be tied to a particular object).&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Some  object-oriented languages use the terms &lt;i&gt;class data&lt;/i&gt; and &lt;i&gt;class  methods&lt;/i&gt;, meaning that the data and methods exist only for the class as a whole, and not for any particular objects of the class. Sometimes the Java literature uses these terms too.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;To make a data  member or method &lt;b&gt;static&lt;/b&gt;, you simply place the keyword before the  definition. For example, the following produces a &lt;b&gt;static&lt;/b&gt; data member and  initializes it:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;class&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; StaticTest {&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;int&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; i = 47;&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Now even if you  make two &lt;b&gt;StaticTest&lt;/b&gt; objects, there will still be only one piece of  storage for &lt;b&gt;StaticTest.i.&lt;/b&gt; Both objects will share the same &lt;b&gt;i&lt;/b&gt;.&lt;b&gt;  &lt;/b&gt;Consider:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;StaticTest st1 = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; StaticTest();&lt;br /&gt;StaticTest st2 = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; StaticTest();&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;At this point, both  &lt;b&gt;st1.i&lt;/b&gt; and &lt;b&gt;st2.i&lt;/b&gt; have the same value of 47 since they refer to the  same piece of memory.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;There are two ways  to refer to a &lt;b&gt;static&lt;/b&gt; variable. As indicated above, you can name it via an  object, by saying, for example, &lt;b&gt;st2.i&lt;/b&gt;. You can also refer to it directly through its class name, something you cannot do with a non-static member. (This is the preferred way to refer to a &lt;b&gt;static&lt;/b&gt; variable since it emphasizes  that variable’s &lt;b&gt;static&lt;/b&gt; nature.)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;StaticTest.i++;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The &lt;b&gt;++&lt;/b&gt;  operator increments the variable. At this point, both &lt;b&gt;st1.i&lt;/b&gt; and  &lt;b&gt;st2.i&lt;/b&gt; will have the value 48.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Similar logic applies to static methods. You can refer to a static method either through an object as you can with any method, or with the special additional syntax &lt;b&gt;ClassName.method( )&lt;/b&gt;. You define a static method in a similar  way:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;class&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; StaticFun {&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;void&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; incr() { StaticTest.i++; }&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;You can see that  the &lt;b&gt;StaticFun&lt;/b&gt; method &lt;b&gt;incr( )&lt;/b&gt; increments the &lt;b&gt;static&lt;/b&gt; data  &lt;b&gt;i&lt;/b&gt;. You can call &lt;b&gt;incr( )&lt;/b&gt; in the typical way, through an  object:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;StaticFun sf = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; StaticFun();&lt;br /&gt;sf.incr();&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Or, because  &lt;b&gt;incr( ) &lt;/b&gt;is a static method, you can call it directly through its  class:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;StaticFun.incr();&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;While  &lt;b&gt;static&lt;/b&gt;, when applied to a data member, definitely changes the way the  data is created (one for each class vs. the non-&lt;b&gt;static &lt;/b&gt;one for each  object), when applied to a method it’s not so dramatic. An important use of  &lt;b&gt;static&lt;/b&gt; for methods is to allow you to call that method without creating an object. This is essential, as we will see, in defining the &lt;b&gt;main( )&lt;/b&gt;  method that is the entry point for running an application.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Like any method, a  &lt;b&gt;static&lt;/b&gt; method can create or use named objects of its type, so a  &lt;b&gt;static&lt;/b&gt; method is often used as a “shepherd” for a flock of instances of  its own type.&lt;a name="_Toc375545233"&gt;&lt;/a&gt;&lt;a name="_Toc479507431"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading104"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h2 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Your  first Java program&lt;/span&gt;&lt;/h2&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Finally, here’s the  program.It starts by printing a string, and then the date, using the &lt;b&gt;Date  &lt;/b&gt;class from the Java standard library. Note that an additional style of  comment is introduced here: the ‘&lt;b&gt;//&lt;/b&gt;’, which is a comment until the end of  the line:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 153, 0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;// HelloDate.java&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;import&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; java.util.*;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;class&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; HelloDate {&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;void&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; main(String[] args) {&lt;br /&gt;System.out.println(&lt;span style="color: rgb(0, 68, 136);"&gt;"Hello, it's: "&lt;/span&gt;);&lt;br /&gt;System.out.println(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Date());&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;At the beginning of  each program file, you must place the &lt;b&gt;import&lt;/b&gt; statement to bring in any extra classes you’ll need for the code in that file. Note that I say “extra;” that’s because there’s a certain library of classes that are automatically brought into every Java file: &lt;b&gt;java.lang&lt;/b&gt;. Start up your Web browser and  look at the documentation from Sun. (If you haven’t downloaded it from  &lt;i&gt;java.sun.com&lt;/i&gt; or otherwise installed the Java documentation, do so now). If you look at the list of the packages, you’ll see all the different class libraries that come with Java. Select &lt;b&gt;java.lang&lt;/b&gt;. This will bring up a  list of all the classes that are part of that library. Since &lt;b&gt;java.lang&lt;/b&gt; is  implicitly included in every Java code file, these classes are automatically  available. There’s no &lt;b&gt;Date&lt;/b&gt; class listed in &lt;b&gt;java.lang&lt;/b&gt;, which means you must import another library to use that. If you don’t know the library where a particular class is, or if you want to see all of the classes, you can select “Tree” in the Java documentation. Now you can find every single class that comes with Java. Then you can use the browser’s “find” function to find &lt;b&gt;Date&lt;/b&gt;.&lt;b&gt; &lt;/b&gt;When you do you’ll see it listed as &lt;b&gt;java.util.Date&lt;/b&gt;,  which lets you know that it’s in the &lt;b&gt;util&lt;/b&gt; library and that you must  &lt;b&gt;import java.util.*&lt;/b&gt; in order to use &lt;b&gt;Date&lt;/b&gt;.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;If you go back to  the beginning, select &lt;b&gt;java.lang&lt;/b&gt; and then &lt;b&gt;System&lt;/b&gt;, you’ll see that  the &lt;b&gt;System&lt;/b&gt; class has several fields, and if you select &lt;b&gt;out&lt;/b&gt; you’ll  discover that it’s a &lt;b&gt;static&lt;/b&gt; &lt;b&gt;PrintStream &lt;/b&gt;object. Since it’s  &lt;b&gt;static&lt;/b&gt; you don’t need to create anything. The &lt;b&gt;out&lt;/b&gt; object is always  there and you can just use it. What you can do with this &lt;b&gt;out&lt;/b&gt; object is  determined by the type it is: a &lt;b&gt;PrintStream&lt;/b&gt;. Conveniently, &lt;b&gt;PrintStream  &lt;/b&gt;is shown in the description as a hyperlink, so if you click on that you’ll  see a list of all the methods you can call for &lt;b&gt;PrintStream&lt;/b&gt;. There are  quite a few and these will be covered later in this book. For now all we’re  interested in is &lt;b&gt;println( )&lt;/b&gt;, which in effect means “print what I’m giving you out to the console and end with a new line.” Thus, in any Java program you write you can say &lt;b&gt;System.out.println(“things”)&lt;/b&gt; whenever you want to print  something to the console.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The name of the class is the same as the name of the file. When you’re creating a stand-alone program such as this one, one of the classes in the file must have the same name as the file. (The compiler complains if you don’t do this.) That class must contain a method called &lt;b&gt;main( )&lt;/b&gt; with the signature  shown:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;void&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; main(String[] args) {&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The &lt;b&gt;public&lt;/b&gt;  keyword means that the method is available to the outside world (described in  detail in Chapter 5). The argument to &lt;b&gt;main( )&lt;/b&gt; is an array of  &lt;b&gt;String&lt;/b&gt; objects. The &lt;b&gt;args&lt;/b&gt; won’t be used in this program, but the Java compiler insists that they be there because they hold the arguments invoked on the command line.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The line that  prints the date is quite interesting:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;System.out.println(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Date());&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Consider the  argument: a &lt;b&gt;Date&lt;/b&gt; object is being created just to send its value to  &lt;b&gt;println( )&lt;/b&gt;. As soon as this statement is finished, that &lt;b&gt;Date&lt;/b&gt; is  unnecessary, and the garbage collector can come along and get it anytime. We  don’t need to worry about cleaning it up.&lt;a name="_Toc375545234"&gt;&lt;/a&gt;&lt;a name="_Toc479507432"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading105"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Compiling and running&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;To compile&lt;a name="Index188"&gt;&lt;/a&gt;&lt;a name="Index189"&gt;&lt;/a&gt;&lt;a name="Index190"&gt;&lt;/a&gt;&lt;a name="Index191"&gt;&lt;/a&gt; and run this program, and all the other programs in this book, you must first have a Java programming environment. There are a number of third-party development environments, but in this book we will assume that you are using the JDK from Sun, which is free. If you are using another development system, you will need to look in the documentation for that system to determine how to compile and run programs.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Get on the Internet  and go to &lt;i&gt;java.sun.com&lt;/i&gt;. There you will find information and links that will lead you through the process of downloading and installing the JDK for your particular platform.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Once the JDK is  installed, and you’ve set up your computer’s path information so that it will  find &lt;b&gt;javac&lt;a name="Index192"&gt;&lt;/a&gt;&lt;/b&gt; and &lt;b&gt;java&lt;/b&gt;, download and unpack the  source code for this book (you can find it on the CD ROM that’s bound in with  this book, or at &lt;i&gt;www.BruceEckel.com&lt;/i&gt;). This will create a subdirectory for  each chapter in this book. Move to subdirectory &lt;b&gt;c02&lt;/b&gt; and  type:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;javac HelloDate.java&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This command should produce no response. If you get any kind of an error message it means you haven’t installed the JDK properly and you need to investigate those problems.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;On the other hand,  if you just get your command prompt back, you can type:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;java HelloDate&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;and you’ll get the  message and the date as output.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This is the process you can use to compile and run each of the programs in this book. However, you will see that the source code for this book also has a file called &lt;b&gt;makefile&lt;/b&gt; in each chapter, and this contains “make” commands for automatically building the files for that chapter. See this book’s Web page at &lt;i&gt;www.BruceEckel.com&lt;/i&gt; for details on how to use the makefiles.&lt;a name="_Toc479507433"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading106"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h2 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Comments and embedded documentation&lt;br /&gt;&lt;a name="Index193"&gt;&lt;/a&gt;&lt;a name="Index194"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;There are two types of comments in Java. The first is the traditional C-style comment that was inherited by C++. These comments begin with a &lt;b&gt;/*&lt;/b&gt; and continue, possibly  across many lines, until a &lt;b&gt;*/&lt;/b&gt;. Note that many programmers will begin each  line of a continued comment with a &lt;b&gt;*&lt;/b&gt;, so you’ll often  see:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 153, 0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;/* This is a comment&lt;br /&gt;*  that continues&lt;br /&gt;*  across lines&lt;br /&gt;*/&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Remember, however,  that everything inside the &lt;b&gt;/*&lt;/b&gt; and &lt;b&gt;*/&lt;/b&gt; is ignored, so there’s no  difference in saying:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 153, 0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;/* This is a comment that&lt;br /&gt;continues across lines */&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The second form of  comment comes from C++. It is the single-line comment, which starts at a  &lt;b&gt;//&lt;/b&gt; and continues until the end of the line. This type of comment is convenient and commonly used because it’s easy. You don’t need to hunt on the keyboard to find &lt;b&gt;/&lt;/b&gt; and then &lt;b&gt;*&lt;/b&gt; (instead, you just press the same  key twice), and you don’t need to close the comment. So you will often  see:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 153, 0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;// this is a one-line comment&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="_Toc375545235"&gt;&lt;/a&gt;&lt;a name="_Toc479507434"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading107"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Comment  documentation&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;One of the thoughtful parts of the Java language is that the designers didn’t consider writing code to be the only important activity—they also thought about documenting it. Possibly the biggest problem with documenting code has been maintaining that documentation. If the documentation and the code are separate, it becomes a hassle to change the documentation every time you change the code. The solution seems simple: link the code to the documentation. The easiest way to do this is to put everything in the same file. To complete the picture, however, you need a special comment syntax to mark special documentation, and a tool to extract those comments and put them in a useful form. This is what Java has done.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The tool to extract  the comments is called &lt;i&gt;javadoc.&lt;/i&gt; It uses some of the technology from the Java compiler to look for special comment tags you put in your programs. It not only extracts the information marked by these tags, but it also pulls out the class name or method name that adjoins the comment. This way you can get away with the minimal amount of work to generate decent program documentation.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The output of javadoc is an HTML file that you can view with your Web browser. This tool allows you to create and maintain a single source file and automatically generate useful documentation. Because of javadoc we have a standard for creating documentation, and it’s easy enough that we can expect or even demand documentation with all Java libraries.&lt;a name="_Ref348399283"&gt;&lt;/a&gt;&lt;a name="_Toc375545236"&gt;&lt;/a&gt;&lt;a name="_Toc479507435"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading108"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Syntax&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;All of the javadoc  commands occur only within &lt;b&gt;/**&lt;/b&gt; comments. The comments end with &lt;b&gt;*/  &lt;/b&gt;as usual. There are two primary ways to use javadoc: embed HTML, or use “doc  tags.” Doc tags are commands that start with a ‘&lt;b&gt;@&lt;/b&gt;’ and are placed at the  beginning of a comment line. (A leading ‘&lt;b&gt;*&lt;/b&gt;’, however, is  ignored.)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;There are three “types” of comment documentation, which correspond to the element the comment precedes: class, variable, or method. That is, a class comment appears right before the definition of a class; a variable comment appears right in front of the definition of a variable, and a method comment appears right in front of the definition of a method. As a simple example:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 153, 0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;/** A class comment */&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;class&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; docTest {&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/** A variable comment */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;int&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; i;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/** A method comment */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;void&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; f() {}&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Note that javadoc  will process comment documentation for only &lt;b&gt;public &lt;/b&gt;and &lt;b&gt;protected  &lt;/b&gt;members. Comments for &lt;b&gt;private &lt;/b&gt;and “friendly” members (see Chapter 5)  are ignored and you’ll see no output. (However, you can use the &lt;b&gt;-private  &lt;/b&gt;flag to include &lt;b&gt;private&lt;/b&gt; members as well.) This makes sense, since  only &lt;b&gt;public&lt;/b&gt; and &lt;b&gt;protected&lt;/b&gt; members are available outside the file,  which is the client programmer’s perspective. However, all &lt;b&gt;class&lt;/b&gt; comments  are included in the output.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The output for the above code is an HTML file that has the same standard format as all the rest of the Java documentation, so users will be comfortable with the format and can easily navigate your classes. It’s worth entering the above code, sending it through javadoc and viewing the resulting HTML file to see the results.&lt;a name="_Toc375545237"&gt;&lt;/a&gt;&lt;a name="_Toc479507436"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading109"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Embedded HTML&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Javadoc passes HTML commands through to the generated HTML document. This allows you full use of HTML; however, the primary motive is to let you format code, such as:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 153, 0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;/**&lt;br /&gt;* &lt;pre&gt;&lt;br /&gt;* System.out.println(new Date());&lt;br /&gt;* &lt;/pre&gt;&lt;br /&gt;*/&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;You can also use  HTML just as you would in any other Web document to format the regular text in  your descriptions:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 153, 0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;/**&lt;br /&gt;* You can &lt;em&gt;even&lt;/em&gt; insert a list:&lt;br /&gt;* &lt;ol&gt;&lt;br /&gt;* &lt;li&gt; Item one&lt;br /&gt;* &lt;/li&gt;&lt;li&gt; Item two&lt;br /&gt;* &lt;/li&gt;&lt;li&gt; Item three&lt;br /&gt;* &lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;*/&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Note that within the documentation comment, asterisks at the beginning of a line are thrown away by javadoc, along with leading spaces. Javadoc reformats everything so that it conforms to the standard documentation appearance. Don’t use headings such as &lt;h1&gt; or &lt;b&gt;&lt;hr /&gt;&lt;/b&gt; as embedded HTML because javadoc inserts  its own headings and yours will interfere with them.&lt;br /&gt;&lt;/h1&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;All types of  comment documentation—class, variable, and method—can support embedded HTML.&lt;a name="_Toc375545238"&gt;&lt;/a&gt;&lt;a name="_Toc479507437"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading110"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@see:  referring to other classes&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;All three types of  comment documentation (class, variable, and method) can contain &lt;b&gt;@see&lt;/b&gt;  tags, which allow you to refer to the documentation in other classes. Javadoc  will generate HTML with the &lt;b&gt;@see&lt;/b&gt; tags hyperlinked to the other  documentation. The forms are:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@see classname&lt;br /&gt;@see fully-qualified-classname&lt;br /&gt;@see fully-qualified-classname#method-name&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Each one adds a hyperlinked “See Also” entry to the generated documentation. Javadoc will not check the hyperlinks you give it to make sure they are valid.&lt;a name="_Toc375545239"&gt;&lt;/a&gt;&lt;a name="_Toc479507438"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading111"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Class  documentation tags&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Along with embedded  HTML and &lt;b&gt;@see &lt;/b&gt;references, class documentation can include tags for version information and the author’s name. Class documentation can also be used for &lt;i&gt;interfaces&lt;/i&gt; (see Chapter 8).&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading112"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h4 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@version&lt;/span&gt;&lt;/h4&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This is of the  form:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@version version-information&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;in which  &lt;b&gt;version-information&lt;/b&gt; is any significant information you see fit to  include. When the &lt;b&gt;-version&lt;/b&gt; flag is placed on the javadoc command line, the version information will be called out specially in the generated HTML documentation.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading113"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h4 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@author&lt;/span&gt;&lt;/h4&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This is of the  form:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@author author-information&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;in which  &lt;b&gt;author-information&lt;/b&gt; is, presumably, your name, but it could also include  your email address or any other appropriate information. When the &lt;b&gt;-author  &lt;/b&gt;flag is placed on the javadoc command line, the author information will be called out specially in the generated HTML documentation.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;You can have multiple author tags for a list of authors, but they must be placed consecutively. All the author information will be lumped together into a single paragraph in the generated HTML.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading114"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h4 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@since&lt;/span&gt;&lt;/h4&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This tag allows you to indicate the version of this code that began using a particular feature. You’ll see it appearing in the HTML Java documentation to indicate what version of the JDK is used.&lt;a name="_Toc375545240"&gt;&lt;/a&gt;&lt;a name="_Toc479507439"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading115"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Variable documentation tags&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Variable  documentation can include only embedded HTML and &lt;b&gt;@see&lt;/b&gt; references.&lt;a name="_Toc375545241"&gt;&lt;/a&gt;&lt;a name="_Toc479507440"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading116"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Method  documentation tags&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;As well as embedded  documentation and &lt;b&gt;@see&lt;/b&gt; references, methods allow documentation tags for  parameters, return values, and exceptions.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading117"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h4 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@param&lt;/span&gt;&lt;/h4&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This is of the  form:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@param parameter-name description&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;in which  &lt;b&gt;parameter-name &lt;/b&gt;is the identifier in the parameter list, and  &lt;b&gt;description &lt;/b&gt;is text that can continue on subsequent lines. The description is considered finished when a new documentation tag is encountered. You can have any number of these, presumably one for each parameter.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading118"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h4 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@return&lt;/span&gt;&lt;/h4&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This is of the  form:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@&lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; description&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;in which  &lt;b&gt;description&lt;/b&gt; gives you the meaning of the return value. It can continue on  subsequent lines.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading119"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h4 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@throws&lt;/span&gt;&lt;/h4&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Exceptions will be demonstrated in Chapter 10, but briefly they are objects that can be “thrown” out of a method if that method fails. Although only one exception object can emerge when you call a method, a particular method might produce any number of different types of exceptions, all of which need descriptions. So the form for the exception tag is:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@&lt;span style="color: rgb(0, 0, 255);"&gt;throws&lt;/span&gt; fully-qualified-&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;-name description&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;in which  &lt;b&gt;fully-qualified-class-name&lt;/b&gt; gives an unambiguous name of an exception  class that’s defined somewhere, and &lt;b&gt;description&lt;/b&gt; (which can continue on  subsequent lines) tells you why this particular type of exception can emerge  from the method call.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading120"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h4 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;@deprecated&lt;br /&gt;&lt;a name="Index195"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/h4&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This is used to tag features that were superseded by an improved feature. The deprecated tag is a suggestion that you no longer use this particular feature, since sometime in the future it is likely to be removed. A method that is marked &lt;b&gt;@deprecated&lt;/b&gt;  causes the compiler to issue a warning if it is used.&lt;a name="_Toc375545242"&gt;&lt;/a&gt;&lt;a name="_Toc479507441"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading121"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h3 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Documentation example&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Here is the first  Java program again, this time with documentation comments  added:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 153, 0);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;//: c02:HelloDate.java&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;import&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; java.util.*;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/** The first Thinking in Java example program.&lt;br /&gt;* Displays a string and today's date.&lt;br /&gt;* @author Bruce Eckel&lt;br /&gt;* @author http://www.BruceEckel.com&lt;br /&gt;* @version 2.0&lt;br /&gt;*/&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;class&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; HelloDate {&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/** Sole entry point to class &amp;amp; application&lt;br /&gt;* @param args array of string arguments&lt;br /&gt;* @return No return value&lt;br /&gt;* @exception exceptions No exceptions thrown&lt;br /&gt;*/&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;void&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; main(String[] args) {&lt;br /&gt;System.out.println(&lt;span style="color: rgb(0, 68, 136);"&gt;"Hello, it's: "&lt;/span&gt;);&lt;br /&gt;System.out.println(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Date());&lt;br /&gt;}&lt;br /&gt;} &lt;span style="color: rgb(0, 153, 0);"&gt;///:~&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The first line of  the file uses my own technique of putting a ‘&lt;b&gt;:&lt;/b&gt;’ as a special marker for the comment line containing the source file name. That line contains the path information to the file (in this case, &lt;b&gt;c02 &lt;/b&gt;indicates Chapter 2) followed by the file name. The last line also finishes with a comment, and this one indicates the end of the source code listing, which allows it to be automatically extracted from the text of this book and checked with a compiler.&lt;a name="_Toc312373851"&gt;&lt;/a&gt;&lt;a name="_Toc375545243"&gt;&lt;/a&gt;&lt;a name="_Toc479507442"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading122"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h2 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Coding  style&lt;/span&gt;&lt;/h2&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The unofficial standard in Java is to capitalize the first letter of a class name. If the class name consists of several words, they are run together (that is, you don’t use underscores to separate the names), and the first letter of each embedded word is capitalized, such as:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;class&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; AllTheColorsOfTheRainbow { &lt;span style="color: rgb(0, 153, 0);"&gt;// ...&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;For almost everything else: methods, fields (member variables), and object reference names, the accepted style is just as it is for classes &lt;i&gt;except&lt;/i&gt; that the first  letter of the identifier is lowercase. For example:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;class&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; AllTheColorsOfTheRainbow {&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; anIntegerRepresentingColors;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; changeTheHueOfTheColor(&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; newHue) {&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;// ...&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;// ...&lt;/span&gt;&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Of course, you  should remember that the user must also type all these long names, and so be  merciful.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The Java code you will see in the Sun libraries also follows the placement of open-and-close curly braces that you see used in this book.&lt;a name="_Toc375545244"&gt;&lt;/a&gt;&lt;a name="_Toc479507443"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading123"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h2 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Summary&lt;/span&gt;&lt;/h2&gt;&lt;/span&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;In this chapter you have seen enough of Java programming to understand how to write a simple program, and you have gotten an overview of the language and some of its basic ideas. However, the examples so far have all been of the form “do this, then do that, then do something else.” What if you want the program to make choices, such as “if the result of doing this is red, do that; if not, then do something else”? The support in Java for this fundamental programming activity will be covered in the next chapter.&lt;a name="_Toc375545245"&gt;&lt;/a&gt;&lt;a name="_Toc479507444"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="Heading124"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt; &lt;h2 align="left"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Exercises&lt;/span&gt;&lt;/h2&gt;&lt;/span&gt; &lt;ol&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Following the  &lt;b&gt;HelloDate.java&lt;/b&gt; example in this chapter, create a “hello, world” program that simply prints out that statement. You need only a single method in your class (the “main” one that gets executed when the program starts). Remember to make it &lt;b&gt;static&lt;/b&gt; and to include the argument list, even though you don’t  use the argument list. Compile the program with &lt;b&gt;javac&lt;/b&gt; and run it using  &lt;b&gt;java&lt;/b&gt;. If you are using a different development environment than the JDK,  learn how to compile and run programs in that environment.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Find the code  fragments involving &lt;b&gt;ATypeName&lt;/b&gt; and turn them into a program that compiles  and runs.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Turn the  &lt;b&gt;DataOnly&lt;/b&gt; code fragments into a program that compiles and runs.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Modify Exercise 3  so that the values of the data in &lt;b&gt;DataOnly&lt;/b&gt; are assigned to and printed in  &lt;b&gt;main( )&lt;/b&gt;.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Write a program  that includes and calls the &lt;b&gt;storage( )&lt;/b&gt; method defined as a code fragment  in this chapter.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Turn the  &lt;b&gt;StaticFun&lt;/b&gt; code fragments into a working program.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Write a program that prints three arguments taken from the command line. To do this, you’ll need to index into the command-line array of &lt;b&gt;String&lt;/b&gt;s.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Turn the  &lt;b&gt;AllTheColorsOfTheRainbow&lt;/b&gt; example into a program that compiles and  runs.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Find the code for  the second version of &lt;b&gt;HelloDate.java&lt;/b&gt;, which is the simple comment  documentation example. Execute &lt;b&gt;javadoc&lt;/b&gt; on the file and view the results  with your Web browser.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Turn  &lt;b&gt;docTest&lt;/b&gt; into a file that compiles and then run it through &lt;b&gt;javadoc&lt;/b&gt;.  Verify the resulting documentation with your Web browser.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Add an HTML list  of items to the documentation in Exercise 10.&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Take the program in Exercise 1 and add comment documentation to it. Extract this comment documentation into an HTML file using &lt;b&gt;javadoc&lt;/b&gt; and view it with your Web  &lt;/span&gt;&lt;span style="font-family:Georgia;"&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This can be a flashpoint. There are those who say “clearly, it’s a pointer,” but this presumes an underlying implementation. Also, Java references are much more akin to C++ references than pointers in their syntax. In the first edition of this book, I choose to invent a new term, “handle,” because C++ references and Java references have some important differences. I was coming out of C++ and did not want to confuse the C++ programmers whom I assumed would be the largest audience for Java. In the 2&lt;sup&gt;nd&lt;/sup&gt; edition, I decided that “reference” was the more commonly used term, and that anyone changing from C++ would have a lot more to cope with than the terminology of references, so they might as well jump in with both feet. However, there are people who disagree even with the term “reference.” I read in one book where it was “completely wrong to say that Java supports pass by reference,” because Java object identifiers (according to that author) are &lt;i&gt;actually&lt;/i&gt; “object references.” And (he goes on) everything is  &lt;i&gt;actually&lt;/i&gt; pass by value. So you’re not passing by reference, you’re “passing an object reference by value.” One could argue for the precision of such convoluted explanations, but I think my approach simplifies the understanding of the concept without hurting anything (well, the language lawyers may claim that I’m lying to you, but I’ll say that I’m providing an appropriate abstraction.)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;b&gt;static&lt;/b&gt;  methods, which you’ll learn about soon, can be called &lt;i&gt;for the class&lt;/i&gt;,  without an object.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;With the usual  exception of the aforementioned “special” data types &lt;b&gt;boolean, char&lt;/b&gt;,  &lt;b&gt;byte&lt;/b&gt;, &lt;b&gt;short&lt;/b&gt;, &lt;b&gt;int&lt;/b&gt;, &lt;b&gt;long&lt;/b&gt;,&lt;b&gt; float,&lt;/b&gt; and  &lt;b&gt;double&lt;/b&gt;. In general, though, you pass objects, which really means you pass  references to objects.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Some programming environments will flash programs up on the screen and close them before you've had a chance to see the results. You can put in the following bit of code at the end of &lt;b&gt;main( )&lt;/b&gt; to pause the output:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;blockquote&gt;&lt;span style="font-size:78%;"&gt;&lt;pre&gt;    &lt;span style="color: rgb(0, 0, 255);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;try&lt;/span&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; {&lt;br /&gt; System.in.read();&lt;br /&gt;} &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt;(Exception e) {}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/blockquote&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This will pause the output until you press “Enter” (or any other key). This code involves concepts that will not be introduced until much later in the book, so you won’t understand it until then, but it will do the trick.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;div align="left"&gt; &lt;p&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;A tool that I created using Python (see www.Python.org) uses this information to extract the code files, put them in appropriate subdirectories, and create makefiles.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3800941631712763981-1208249543677042211?l=ab-ebooks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ab-ebooks.blogspot.com/feeds/1208249543677042211/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3800941631712763981&amp;postID=1208249543677042211' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3800941631712763981/posts/default/1208249543677042211'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3800941631712763981/posts/default/1208249543677042211'/><link rel='alternate' type='text/html' href='http://ab-ebooks.blogspot.com/2007/09/about-java.html' title='About Java'/><author><name>Niranjan</name><uri>http://www.blogger.com/profile/13413521883177554840</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3800941631712763981.post-2020628114984832582</id><published>2007-09-24T00:04:00.000-07:00</published><updated>2007-09-24T00:05:20.555-07:00</updated><title type='text'>Histroy of C++</title><content type='html'>&lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;&lt;/strong&gt;Computer languages have undergone  dramatic evolution since the first electronic computers were built to assist in  telemetry calculations during World war II.Early on,programmers worked with the  most primitive computer instructions:machine langauge.These instructions were  represented by long strings of ones and zeros.soon,assembles were invented to  map machine instructions to human-readable and-manageable mnemonics,such as ADD  and MOV.&lt;br /&gt;In time,higher-level languages evloved,sush as BASIC and COBOL.These  langauges let people work with something approximating words and sentences,such  as let I=100.These instructions were translated back into machine language by  interpreters and compilers.An intermediary then invokes a linker,which turns the  object file into an executable program.&lt;br /&gt;&lt;br /&gt;Because interpreters read the  code as it is written and execute the code on the spot,interpreters are easy for  the programmer to work with.Compilers,however,introduce the extra steps of  compiling and linking the code,which is inconvenient.Compilers produce a program  that is very fast each time it is run.However,the time-consuming task of  translating the soource code into machine language has already been  accomplished.&lt;br /&gt;Another advantage of many compiled lanagues like C++ is that  you can distribute the executable program to people who donot have the  compilers.With an interpretive language,you must have the languages to run the  program.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;For  many years,the principle goal of computer programmers was to write short pieves  of code that would execute quickly.The program needed to be small,because memory  was expensive,and it needed to be fast,because processing power was also  expensive.As computers have become smaller,cheaper,and faster,and as the cost of  memory has fallen,these priorities have changed.Today the cost of programmer's  time far outweighs the cost of most of the computers in use by  businesses.Well-written,easy to-maintian code is at a premium.Easy-to-maintain  means that as business requirements change,the program can be extended and  enhanced without great expense.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Programs&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The  word program is used in two ways:to describe individual instructions,or source  code,created by the programmer,and to describe an entire piece of executable  software.This distinction can cause enormous confusion,so we will try to  distinguish between the source code on one hand,and the executable on the  other.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Procedural,Structured and Object Oriented  Programming&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;Until recently,programs were thought of as series of  procedures that acted upon data.A procedure,or function,is a set specific  instructions executed one after the other.The data was quite separate from  procedures,and the trick in programming was to keep track of which functions  called which other functions,and what data was changed.To make sense of this  potentially confusing situation,structured programming was created.&lt;br /&gt;The  principle idea behind structured programming is as simple as the idea of divide  and conquer.A computer program can be thought of as consisting of a set of  tasks.Any task that is too complex to be described simply would be broken down  into a set of smaller component tasks,until the tasks were sufficiently small  and self-contained enough that they were easily understood.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;C++  and Object_oriented Programming&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;C++ fully supports  object-oriented programming,including the four pillars of object-oriented  development:encapsulation,data hiding,inheritance,and polymorphism.Encapsulation  and Data Hiding when an engineer needs to add a resistor to the device she is  creating,she doesn't typically build a new one from scratch.She walks over to a  bin of resistors,examines the coloured bands that indicate the properties,and  picks the one she needs.The resistor is a "balck box" as far as the engineer is  concerned --she doesnot much care how it does its work as long as conforms to  her specifications:she doesnot need to look inside the box to use it in he  design.&lt;br /&gt;The property of being a self-contained unit is called  encapsulation.With encapsulation,we can accomplish data hiding.Data hiding is  the highly valued characteristic that an object can be used without the user  knowing how the compressor works,you can use a wall-designed object without  knowing about its internal data members.&lt;br /&gt;Similarly,when the engineer uses the  resistor,she need not know anything about the internal state of the resistor.All  the propeties of the resistor are encapsulated in the resistor object;they are  not spread out through the circuitry.It is not necessary to understand how the  resistor works in order to use it effectively.Its data is hidden inside the  resistor's casing.&lt;br /&gt;&lt;br /&gt;C++ supports the properties of encapsulation and data  hiding through the creation of user-defined types,called classes.Once created,a  well-defined class acts as a fully encapsulated entity--it is used as a whole  unit.The actual inner wrokings of the class should be hidden.Users of a  well-defined class do not need to know how the class works;they just need to  know how to use it.Inheritance and Reuse when the engineers at Acme Motors want  to build a new car,they have two choices:They can start from scratch,or they can  modify an existing model.Perhaps their Star model is nearly perfect,but they'd  like to add a turbocharger and a six-speed transmission.The chief engineer would  prefer not to start from the ground up,but rather to say,"Let's build another  Star,but let's add these additional capabilities.We'll call the new model a  Quasar ."A Quasar is a kind of Star,but one with new features.&lt;br /&gt;&lt;br /&gt;C++  supports the idea of reuse through inheritance.A new type,which is an extension  of an exiting type,can be decalred.This new subclass is said it derive from the  existing type and is sometimes called a derived type.The Quasar is derived from  the Star and thus inherits all its qualities,but can add to them as needed.The  new Quasar might respond differently than a Star does when you press down on the  accelerator.The Quasar might engage fuel injection and a turbocharger,while the  star would simply let gasoline into its carburetor.A user,however,does not have  to know about these differences.He can just"floot it,"and the right thing will  happen,depending on which can he's driving.&lt;br /&gt;&lt;br /&gt;C++ supports the idea that  different objects do "the right thing" through what is called function  polymorphism and class ploymorphism.Poly means many,and morph means  form.Ploymorphism refers to the same name taking many forms.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;a name="Howcevolved"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;How C++ Evolved&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;As object-oriented  analysis,design and programming began to catch on,Bjarne Stroustrup took the  most popular langauge for commercial software development,C and extended it to  provide the features needed to facilities object-oriented programming .He  created C++ and in less than a decade it has gone from being used by only a  handful of developers at AT &amp;amp; T to being the programming langauge of choice  for an estimated one million developers worldwide.It is expected that by the end  of the decade,c++ will be the predomminant langauge for commercial software  development.&lt;br /&gt;While it is true that C++ is a superset of C,and that virtutally  any legal C program is a legal C++ program,the leap from C to C++ is very  significant.C++ benefited from its relationship to C for many years,as C  programmers could ease into their use of C++.To really get the full benefit of  C++,however,many programmers found they had to unlearn much of what they knew  and learn a whole new way of conceptutalizing and solving programming  problems.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;b&gt;A  first impression of C++&lt;/b&gt;&lt;br /&gt;We're always interested in getting feedback.  E-mail us if you like this guide, if you think that important material is  omitted, if you encounter errors in the code examples or in the documentation,  if you find any typos, or generally just if you feel like e-mailing. Send your  email to Frank Brokken. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Please state the  document version you're referring to, as found in the title (in this document:  4.4.2). &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;In this chapter the  usage of C++ is further explored. The possibility to declare functions in  structs is further illustrated using examples. The concept of a class is  introduced. &lt;/span&gt;&lt;/p&gt;  &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Variable and Contraints&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;Programs need a way to  store the data they use.variable and constraints offer various ways to represent  and manipulate that data.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt; &lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="whatisvariable"&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;What is a variable?&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;In C++ a  variable is a place to store information.A variable is a location in your  computer's memory in which you can store value and from which you can later  retrieve that value.&lt;br /&gt;Your computer's memory can be viewed as a series of  cobbyholes.Each cobbyhole is one of many,many such holes all lined up.Each  cubbyhole--or memory location--is numbered sequentillly.These numbers are known  as memory addresses.A variable reserves one or more cubbyholes in which you may  store a value.&lt;br /&gt;Your variable name(for example,myVariable)is a label on one of  these cubbyholes,so that you can find it easily without knowing its actual  memory address.&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="FirstImpression"&gt;&lt;/a&gt;&lt;a name="l29"&gt;&lt;/a&gt;&lt;a name="afirst"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;h1&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;A first impression  of C++&lt;/span&gt;&lt;/h1&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="first"&gt;&lt;/a&gt;&lt;/span&gt; &lt;blockquote&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="first/first"&gt;&lt;/a&gt;In this chapter the usage of &lt;strong&gt;C++&lt;/strong&gt; is  further explored. The possibility to declare functions in &lt;code&gt;struct&lt;/code&gt;s  is further illustrated using examples. The concept of a &lt;code&gt;class&lt;/code&gt; is  introduced. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="l30"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h2&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.1: More  extensions of C in C++&lt;/span&gt;&lt;/h2&gt;&lt;a name="first/more"&gt;&lt;/a&gt;Before we continue with  the `real' object-oriented approach to programming, we first introduce some  extensions to the &lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;C&lt;/span&gt;&lt;/strong&gt; programming language, encountered in &lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;C++&lt;/span&gt;&lt;/strong&gt;: not  mere differences between &lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;C&lt;/span&gt;&lt;/strong&gt; and  &lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;C++&lt;/span&gt;&lt;/strong&gt;, but syntactical constructs and keywords that are not  found in &lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;C&lt;/span&gt;&lt;/strong&gt;.    &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="l31"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.1.1: The scope  resolution operator ::&lt;/span&gt;&lt;/h3&gt;&lt;a name="first/scope"&gt;&lt;/a&gt;The syntax of  &lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;C++&lt;/span&gt;&lt;/strong&gt; introduces a number of new operators, of which the  scope resolution operator &lt;code&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;::&lt;/span&gt;&lt;/code&gt; is  described first. This operator can be used in situations where a global variable  exists with the same name as a local variable:   &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt;   int&lt;br /&gt;       counter = 50;                   // global variable&lt;br /&gt;&lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       for (register int counter = 1;  // this refers to the&lt;br /&gt;            counter &lt; 10;              // local variable&lt;br /&gt;            counter++)&lt;br /&gt;       {&lt;br /&gt;           printf("%d\n",&lt;br /&gt;                   ::counter           // global variable&lt;br /&gt;                   /                   // divided by&lt;br /&gt;                   counter);           // local variable&lt;br /&gt;       }&lt;br /&gt;       return (0);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;In this code  fragment the scope operator is used to address a global variable instead of the  local variable with the same name. The usage of the scope operator is more  extensive than just this, but the other purposes will be described later.  &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="CoutCinCerr"&gt;&lt;/a&gt;&lt;a name="l32"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.1.2: cout, cin  and cerr&lt;/span&gt;&lt;/h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="first/cout"&gt;&lt;/a&gt;In analogy to &lt;strong&gt;C&lt;/strong&gt;, &lt;strong&gt;C++&lt;/strong&gt;  defines standard input- and output streams which are opened when a program is  executed. The streams are: &lt;/span&gt; &lt;p&gt; &lt;/p&gt;&lt;ul&gt;&lt;p&gt; &lt;/p&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;code&gt;cout&lt;/code&gt;,  analogous to &lt;code&gt;stdout&lt;/code&gt;, &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;code&gt;cin&lt;/code&gt;,  analogous to &lt;code&gt;stdin&lt;/code&gt;, &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;code&gt;cerr&lt;/code&gt;,  analogous to &lt;code&gt;stderr&lt;/code&gt;. &lt;/span&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Syntactically these  streams are not used with functions: instead, data are read from the streams or  written to them using the operators &lt;code&gt;&lt;&lt;&lt;/code&gt;, called the  &lt;em&gt;insertion operator&lt;/em&gt; and &lt;code&gt;&gt;&gt;&lt;/code&gt;, called the &lt;em&gt;extraction  operator&lt;/em&gt;. This is illustrated in the example below: &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   #include &lt;iostream&gt;&lt;br /&gt;&lt;br /&gt;   void main()&lt;br /&gt;   {&lt;br /&gt;       int&lt;br /&gt;           ival;&lt;br /&gt;       char&lt;br /&gt;           sval[30];&lt;br /&gt;&lt;br /&gt;       cout &lt;&lt; "Enter a number:" &lt;&lt; endl;&lt;br /&gt;       cin &gt;&gt; ival;&lt;br /&gt;       cout &lt;&lt; "And now a string:" &lt;&lt; endl;&lt;br /&gt;       cin &gt;&gt; sval;&lt;br /&gt;&lt;br /&gt;       cout &lt;&lt; "The number is: " &lt;&lt; ival &lt;&lt; endl&lt;br /&gt;            &lt;&lt; "And the string is: " &lt;&lt; sval &lt;&lt; endl;&lt;br /&gt;   }           &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This program reads  a number and a string from the &lt;code&gt;cin&lt;/code&gt; stream (usually the keyboard)  and prints these data to &lt;code&gt;cout&lt;/code&gt;. Concerning the streams and their  usage we remark the following: &lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;ul&gt;&lt;p&gt; &lt;/p&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The streams are  declared in the header file &lt;code&gt;iostream&lt;/code&gt;. &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The streams  &lt;code&gt;cout&lt;/code&gt;, &lt;code&gt;cin&lt;/code&gt; and &lt;code&gt;cerr&lt;/code&gt; are in fact `objects'  of a given class (more on classes later), processing the input and output of a  program. Note that the term `object', as used here, means the set of data and  functions which defines the item in question. &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The stream  &lt;code&gt;cin&lt;/code&gt; reads data and copies the information to variables (e.g.,  &lt;code&gt;ival&lt;/code&gt; in the above example) using the extraction operator  &lt;code&gt;&gt;&gt;&lt;/code&gt;. We will describe later how operators in  &lt;strong&gt;C++&lt;/strong&gt; can perform quite different actions than what they are  defined to do by the language grammar, such as is the case here. We've seen  function overloading. In &lt;strong&gt;C++&lt;/strong&gt; &lt;em&gt;operators&lt;/em&gt; can also have  multiple definitions, which is called &lt;em&gt;operator overloading&lt;/em&gt;. &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The operators  which manipulate &lt;code&gt;cin&lt;/code&gt;, &lt;code&gt;cout&lt;/code&gt; and &lt;code&gt;cerr&lt;/code&gt;  (i.e., &lt;code&gt;&gt;&gt;&lt;/code&gt; and &lt;code&gt;&lt;&lt;&lt;/code&gt;) also manipulate  variables of different types. In the above example &lt;code&gt;cout &lt;&lt;&gt; results in the printing of an integer value, whereas &lt;code&gt;cout  &lt;&lt; "Enter a number"&lt;/code&gt; results in the printing of a string. The  actions of the operators therefore depend on the type of supplied variables.  &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Special symbolic  constants are used for special situations. The termination of a line written by  &lt;code&gt;cout&lt;/code&gt; is realized by inserting the &lt;code&gt;endl&lt;/code&gt; symbol, rather  than using the string &lt;code&gt;"\n"&lt;/code&gt;. &lt;/span&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The streams  &lt;code&gt;cin&lt;/code&gt;, &lt;code&gt;cout&lt;/code&gt; and &lt;code&gt;cerr&lt;/code&gt; are in fact not part  of the &lt;strong&gt;C++&lt;/strong&gt; grammar, as defined in the compiler which parses  source files. The streams are part of the definitions in the header file  &lt;code&gt;iostream&lt;/code&gt;. This is comparable to the fact that functions as  &lt;code&gt;printf()&lt;/code&gt; are not part of the &lt;strong&gt;C&lt;/strong&gt; grammar, but were  originally written by people who considered such functions handy and collected  them in a run-time library. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Whether a program  uses the old-style functions like &lt;code&gt;printf()&lt;/code&gt; and &lt;code&gt;scanf()&lt;/code&gt;  or whether it employs the new-style streams is a matter of taste. Both styles  can even be mixed. A number of advantages and disadvantages is given below:  &lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;ul&gt;&lt;p&gt; &lt;/p&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Compared to the  standard &lt;code&gt;C&lt;/code&gt; functions &lt;code&gt;printf()&lt;/code&gt; and  &lt;code&gt;scanf()&lt;/code&gt;, the usage of the insertion and extraction operators is  more &lt;code&gt;type-safe&lt;/code&gt;. The format strings which are used with  &lt;code&gt;printf()&lt;/code&gt; and &lt;code&gt;scanf()&lt;/code&gt; can define wrong format  specifiers for their arguments, for which the compiler sometimes can't warn. In  contrast, argument checking with &lt;code&gt;cin&lt;/code&gt;, &lt;code&gt;cout&lt;/code&gt; and  &lt;code&gt;cerr&lt;/code&gt; is performed by the compiler. Consequently it isn't possible  to err by providing an &lt;code&gt;int&lt;/code&gt; argument in places where, according to  the format string, a string argument should appear. &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The functions  &lt;code&gt;printf()&lt;/code&gt; and &lt;code&gt;scanf()&lt;/code&gt;, and other functions which use  format strings, in fact implement a mini-language which is interpreted at  run-time. In contrast, the &lt;code&gt;C++&lt;/code&gt; compiler knows exactly  &lt;code&gt;which&lt;/code&gt; in- or output action to perform given which argument. &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The usage of the  left-shift and right-shift operators in the context of the streams does  illustrate the possibilities of &lt;code&gt;C++&lt;/code&gt;. Again, it requires a little  getting used to, coming from &lt;strong&gt;C&lt;/strong&gt;, but after that these overloaded  operators feel rather comfortably. &lt;/span&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The &lt;em&gt;iostream  library&lt;/em&gt; has a lot more to offer than just &lt;code&gt;cin, cout&lt;/code&gt; and  &lt;code&gt;cerr&lt;/code&gt;. In chapter &lt;a href="cplusplus12.html#IOStreams" tppabs="http://www.icce.rug.nl/docs/cplusplus/cplusplus12.html#IOStreams"&gt;12&lt;/a&gt;  &lt;em&gt;iostreams&lt;/em&gt; will be covered in greater detail. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="ConstRule"&gt;&lt;/a&gt;&lt;a name="l33"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.1.3: The keyword  const&lt;/span&gt;&lt;/h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="first/const"&gt;&lt;/a&gt;The keyword &lt;code&gt;const&lt;/code&gt; very often occurs in  &lt;strong&gt;C++&lt;/strong&gt; programs, even though it is also part of the  &lt;strong&gt;C&lt;/strong&gt; grammar, where it's much less used. &lt;/span&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This keyword is a  modifier which states that the value of a variable or of an argument may not be  modified. In the below example an attempt is made to change the value of a  variable &lt;code&gt;ival&lt;/code&gt;, which is not legal: &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       int const               // a constant int..&lt;br /&gt;           ival = 3;           // initialized to 3&lt;br /&gt;&lt;br /&gt;       ival = 4;               // assignment leads&lt;br /&gt;                               // to an error message&lt;br /&gt;&lt;br /&gt;       return (0);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This example shows  how &lt;code&gt;ival&lt;/code&gt; may be initialized to a given value in its definition;  attempts to change the value later (in an assignment) are not permitted.  &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Variables which are  declared &lt;code&gt;const&lt;/code&gt; can, in contrast to &lt;strong&gt;C&lt;/strong&gt;, be used as  the specification of the size of an array, as in the following example:  &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   int const&lt;br /&gt;       size = 20;&lt;br /&gt;   char&lt;br /&gt;       buf[size];          // 20 chars big&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;A further usage of  the keyword &lt;code&gt;const&lt;/code&gt; is seen in the declaration of pointers, e.g., in  pointer-arguments. In the declaration &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   char const *buf;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;code&gt;buf&lt;/code&gt; is  a pointer variable, which points to &lt;code&gt;char&lt;/code&gt;s. Whatever is pointed to  by &lt;code&gt;buf&lt;/code&gt; may not be changed: the &lt;code&gt;char&lt;/code&gt;s are declared as  &lt;code&gt;const&lt;/code&gt;. The pointer &lt;code&gt;buf&lt;/code&gt; itself however may be changed.  A statement as &lt;code&gt;*buf = 'a';&lt;/code&gt; is therefore not allowed, while  &lt;code&gt;buf++&lt;/code&gt; is. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;In the declaration  &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   char *const buf;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;code&gt;buf&lt;/code&gt;  itself is a &lt;code&gt;const&lt;/code&gt; pointer which may not be changed. Whatever  &lt;code&gt;char&lt;/code&gt;s are pointed to by &lt;code&gt;buf&lt;/code&gt; may be changed at will.  &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Finally, the  declaration &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   char const *const buf;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;is also possible;  here, neither the pointer nor what it points to may be changed. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The rule of thumb  for the placement of the keyword &lt;code&gt;const&lt;/code&gt; is the following: whatever  occurs just prior to the keyword may not be changed. The definition or  declaration in which &lt;code&gt;const&lt;/code&gt; is used should be read from the variable  or function identifier back to the type indentifier: &lt;/span&gt; &lt;/p&gt;&lt;blockquote&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;``Buf is a  const pointer to const characters'' &lt;/span&gt;&lt;/blockquote&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This rule of thumb is  especially handy in cases where confusion may occur. In examples of  &lt;strong&gt;C++&lt;/strong&gt; code, one often encounters the reverse: &lt;code&gt;const&lt;/code&gt;  &lt;em&gt;preceding&lt;/em&gt; what should not be altered. That this may result in sloppy  code is indicated by our second example above: &lt;/span&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   char const *buf;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;What must remain  constant here? According to the sloppy interpretation, the pointer cannot be  altered (since &lt;code&gt;const&lt;/code&gt; precedes the pointer-*). In fact, the  charvalues are the constant entities here, as will be clear when it is tried to  compile the following program: &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       char const *buf = "hello";&lt;br /&gt;  &lt;br /&gt;       buf++;                  // accepted by the compiler&lt;br /&gt;       *buf = 'u';             // rejected by the compiler&lt;br /&gt;&lt;br /&gt;       return (0);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Compilation fails  on the statement &lt;code&gt;*buf = 'u';&lt;/code&gt;, &lt;em&gt;not&lt;/em&gt; on the statement  &lt;code&gt;buf++&lt;/code&gt;. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="l34"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.1.4:  References&lt;/span&gt;&lt;/h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="first/references"&gt;&lt;/a&gt;Besides the normal declaration of variables,  &lt;strong&gt;C++&lt;/strong&gt; allows `references' to be declared as synonyms for  variables. A reference to a variable is like an alias; the variable name and the  reference name can both be used in statements which affect the variable: &lt;/span&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   int&lt;br /&gt;       int_value;&lt;br /&gt;   int&lt;br /&gt;       &amp;amp;ref = int_value;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;In the above  example a variable &lt;code&gt;int_value&lt;/code&gt; is defined. Subsequently a reference  &lt;code&gt;ref&lt;/code&gt; is defined, which due to its initialization addresses the same  memory location which &lt;code&gt;int_value&lt;/code&gt; occupies. In the definition of  &lt;code&gt;ref&lt;/code&gt;, the reference operator &lt;code&gt;&amp;amp;&lt;/code&gt; indicates that  &lt;code&gt;ref&lt;/code&gt; is not itself an integer but a reference to one. The two  statements &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   int_value++;            // alternative 1&lt;br /&gt;   ref++;                  // alternative 2&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;have the same  effect, as expected. At some memory location an &lt;code&gt;int&lt;/code&gt; value is  increased by one --- whether that location is called &lt;code&gt;int_value&lt;/code&gt; or  &lt;code&gt;ref&lt;/code&gt; does not matter. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;References serve an  important function in &lt;strong&gt;C++&lt;/strong&gt; as a means to pass arguments which  can be modified (`variable arguments' in Pascal-terms). E.g., in standard  &lt;strong&gt;C&lt;/strong&gt;, a function which increases the value of its argument by five  but which returns nothing (&lt;code&gt;void&lt;/code&gt;), needs a pointer argument:  &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   void increase(int *valp)        // expects a pointer&lt;br /&gt;   {                               // to an int&lt;br /&gt;       *valp += 5;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       int&lt;br /&gt;           x;&lt;br /&gt;&lt;br /&gt;       increase(&amp;amp;x)                // the address of x is&lt;br /&gt;       return (0);                 // passed as argument&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This construction  can &lt;em&gt;also&lt;/em&gt; be used in &lt;strong&gt;C++&lt;/strong&gt; but the same effect can be  achieved using a reference: &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   void increase(int &amp;amp;valr)            // expects a reference&lt;br /&gt;   {                                   // to an int&lt;br /&gt;       valr += 5;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       int&lt;br /&gt;           x;&lt;br /&gt;&lt;br /&gt;       increase(x);                    // a reference to x is&lt;br /&gt;       return (0);                     // passed as argument&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The way in which  &lt;strong&gt;C++&lt;/strong&gt; compilers implement references is actually by using  pointers: in other words, references in &lt;strong&gt;C++&lt;/strong&gt; are just ordinary  pointers, as far as the compiler is concerned. However, the programmer does not  need to know or to bother about levels of indirection. (Compare this to the  Pascal way: an argument which is declared as &lt;code&gt;var&lt;/code&gt; is in fact also a  pointer, but the programmer needn't know.) &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;It can be argued  whether code such as the above is clear: the statement &lt;code&gt;increase&lt;/code&gt;  &lt;code&gt;(x)&lt;/code&gt; in the &lt;code&gt;main()&lt;/code&gt; function suggests that not  &lt;code&gt;x&lt;/code&gt; itself but a &lt;em&gt;copy&lt;/em&gt; is passed. Yet the value of  &lt;code&gt;x&lt;/code&gt; changes because of the way &lt;code&gt;increase()&lt;/code&gt; is defined.  &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Our suggestions for  the usage of references as arguments to functions are therefore the following:  &lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;ul&gt;&lt;p&gt; &lt;/p&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;In those  situations where a called function does not alter its arguments, a copy of the  variable can be passed: &lt;/span&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;       void some_func(int val)&lt;br /&gt;       {&lt;br /&gt;           printf("%d\n", val);&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       int main()&lt;br /&gt;       {&lt;br /&gt;           int&lt;br /&gt;               x;&lt;br /&gt;&lt;br /&gt;           some_func(x);           // a copy is passed, so&lt;br /&gt;           return (0);             // x won't be changed&lt;br /&gt;       }&lt;br /&gt;  &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;When a function  changes the value of its argument, the address or a reference can be passed,  whichever you prefer: &lt;/span&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;       void by_pointer(int *valp)&lt;br /&gt;       {&lt;br /&gt;           *valp += 5;&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       void by_reference(int &amp;amp;valr)&lt;br /&gt;       {&lt;br /&gt;           valr += 5;&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       int main ()&lt;br /&gt;       {&lt;br /&gt;           int&lt;br /&gt;               x;&lt;br /&gt;&lt;br /&gt;           by_pointer(&amp;amp;x);             // a pointer is passed&lt;br /&gt;           by_reference(x);            // x is altered by reference&lt;br /&gt;           return (0);                 // x might be changed&lt;br /&gt;       }&lt;br /&gt;  &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;References have an  important role in those cases where the argument will not be changed by the  function, but where it is desirable to pass a reference to the variable instead  of a copy of the whole variable. Such a situation occurs when a large variable,  e.g., a &lt;code&gt;struct&lt;/code&gt;, is passed as argument, or is returned from the  function. In these cases the copying operations tend to become significant  factors when the entire structure must be copied, and it is preferred to use  references. If the argument isn't changed by the function, or if the caller  shouldn't change the returned information, the use of the &lt;code&gt;const&lt;/code&gt;  keyword is appropriate and should be used. &lt;/span&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Consider the  following example: &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;  &lt;br /&gt;   struct Person                       // some large structure&lt;br /&gt;   {&lt;br /&gt;       char&lt;br /&gt;           name [80],&lt;br /&gt;           address [90];&lt;br /&gt;       double&lt;br /&gt;           salary;&lt;br /&gt;   };&lt;br /&gt;          &lt;br /&gt;   Person   &lt;br /&gt;      person[50];                      // database of persons   &lt;br /&gt;&lt;br /&gt;   void printperson (Person const &amp;amp;p)  // printperson expects a&lt;br /&gt;   {                                   // reference to a structure&lt;br /&gt;       printf ("Name: %s\n"            // but won't change it&lt;br /&gt;               "Address: %s\n",&lt;br /&gt;       p.name, p.address);&lt;br /&gt;   }&lt;br /&gt;              &lt;br /&gt;   Person const &amp;amp;getperson(int index)  // get a person by indexvalue   &lt;br /&gt;   {   &lt;br /&gt;       ...&lt;br /&gt;       return (person[index]);         // a reference is returned,   &lt;br /&gt;   }                                   // not a copy of person[index]   &lt;br /&gt;&lt;br /&gt;   int main ()&lt;br /&gt;   {&lt;br /&gt;       Person&lt;br /&gt;           boss;&lt;br /&gt;&lt;br /&gt;       printperson (boss);             // no pointer is passed,&lt;br /&gt;                                       // so variable won't be   &lt;br /&gt;                                       // altered by function&lt;br /&gt;       printperson(getperson(5));      // references, not copies&lt;br /&gt;                                       // are passed here&lt;br /&gt;       return (0);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;It should  furthermore be noted here that there is another reason for using references when  passing objects as function arguments: when passing a reference to an object,  the activation of a copy constructor is avoided. &lt;/span&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;References also can  lead to extremely `ugly' code. A function can also return a reference to a  variable, as in the following example: &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   int &amp;amp;func()&lt;br /&gt;   {&lt;br /&gt;       static int&lt;br /&gt;           value;&lt;br /&gt;&lt;br /&gt;       return (value);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This allows the  following constructions: &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   func() = 20;&lt;br /&gt;   func() += func ();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;It is probably  superfluous to note that such constructions should not normally be used.  Nonetheless, there are situations where it is useful to return a reference. Even  though this is discussed later, we have seen an example of this phenomenon at  our previous discussion of the &lt;em&gt;iostreams&lt;/em&gt;. In a statement like  &lt;code&gt;cout &lt;&lt; "Hello" &lt;&lt;&gt;, the insertion operator  returns a reference to &lt;code&gt;cout&lt;/code&gt;. So, in this statement first the  &lt;code&gt;"Hello"&lt;/code&gt; is inserted into &lt;code&gt;cout&lt;/code&gt;, producing a reference  to &lt;code&gt;cout&lt;/code&gt;. Via this reference the &lt;code&gt;endl&lt;/code&gt; is then inserted  in the &lt;code&gt;cout&lt;/code&gt; object, again producing a reference to  &lt;code&gt;cout&lt;/code&gt;. This latter reference is not further used. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;A number of  differences between pointers and references is pointed out in the list below:  &lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;ul&gt;&lt;p&gt; &lt;/p&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;A reference cannot  exist by itself, i.e., without something to refer to. A declaration of a  reference like &lt;/span&gt; &lt;p&gt; &lt;/p&gt;&lt;center&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;code&gt;int  &amp;ref;&lt;/code&gt; &lt;/span&gt;&lt;/center&gt;  &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;is not allowed;  what would &lt;code&gt;ref&lt;/code&gt; refer to? &lt;/span&gt;&lt;/p&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;References can,  however, be declared as &lt;code&gt;external&lt;/code&gt;. These references were initialized  elsewhere. &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Reference may  exist as parameters of functions: they are initialized when the function is  called. &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;References may be  used in the return types of functions. In those cases the function determines to  what the return value will refer. &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Reference may be  used as data members of classes. We will return to this usage later. &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;In contrast,  pointers are variables by themselves. They point at something concrete or just  ``at nothing''. &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;References are  aliases for other variables and cannot be re-aliased to another variable. Once a  reference is defined, it refers to its particular variable. &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;In contrast,  pointers can be reassigned to point to different variables. &lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;When an address-of  operator &lt;code&gt;&amp;amp;&lt;/code&gt; is used with a reference, the expression yields the  address of the variable to which the reference applies. In contrast, ordinary  pointers are variables themselves, so the address of a pointer variable has  nothing to do with the address of the variable pointed to. &lt;/span&gt; &lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="FunctionsInStructs"&gt;&lt;/a&gt;&lt;a name="l35"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h2&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.2: Functions as  part of structs&lt;/span&gt;&lt;/h2&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="first/structs"&gt;&lt;/a&gt;The first chapter described that functions can  be part of &lt;code&gt;struct&lt;/code&gt;s . Such functions are called &lt;em&gt;member  functions&lt;/em&gt; or &lt;em&gt;methods&lt;/em&gt;. This section discusses the actual definition  of such functions. &lt;/span&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The code fragment  below illustrates a &lt;code&gt;struct&lt;/code&gt; in which data fields for a name and  address are present. A function &lt;code&gt;print()&lt;/code&gt; is included in the  &lt;code&gt;struct&lt;/code&gt; definition: &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   struct person&lt;br /&gt;   {&lt;br /&gt;       char&lt;br /&gt;           name [80],&lt;br /&gt;           address [80];&lt;br /&gt;       void&lt;br /&gt;           print (void);&lt;br /&gt;   };&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The member function  &lt;code&gt;print()&lt;/code&gt; is defined using the structure name (&lt;code&gt;person&lt;/code&gt;)  and the scope resolution operator (&lt;code&gt;::&lt;/code&gt;): &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   void person::print()&lt;br /&gt;   {&lt;br /&gt;       printf("Name:      %s\n"&lt;br /&gt;              "Address:   %s\n", name, address);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;In the definition  of this member function, the function name is preceded by the  &lt;code&gt;struct&lt;/code&gt; name followed by &lt;code&gt;::&lt;/code&gt;. The code of the function  shows how the fields of the &lt;code&gt;struct&lt;/code&gt; can be addressed without using  the type name: in this example the function &lt;code&gt;print()&lt;/code&gt; prints a  variable &lt;code&gt;name&lt;/code&gt;. Since &lt;code&gt;print()&lt;/code&gt; is a part of the  &lt;code&gt;struct&lt;/code&gt; &lt;code&gt;person&lt;/code&gt;, the variable &lt;code&gt;name&lt;/code&gt;  implicitly refers to the same type. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The usage of this  &lt;code&gt;struct&lt;/code&gt; could be, e.g.: &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   person&lt;br /&gt;       p;&lt;br /&gt;&lt;br /&gt;   strcpy(p.name, "Karel");&lt;br /&gt;   strcpy(p.address, "Rietveldlaan 37");&lt;br /&gt;   p.print();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The advantage of  member functions lies in the fact that the called function can automatically  address the data fields of the structure for which it was invoked. As such, in  the statement &lt;code&gt;p.print()&lt;/code&gt; the structure &lt;code&gt;p&lt;/code&gt; is the  `substrate': the variables &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;address&lt;/code&gt; which are  used in the code of &lt;code&gt;print()&lt;/code&gt; refer to the same &lt;code&gt;struct  p&lt;/code&gt;. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="l36"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h2&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.3: Several new  data types&lt;/span&gt;&lt;/h2&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="first/datatypes"&gt;&lt;/a&gt;In &lt;strong&gt;C&lt;/strong&gt; the following basic  data types are available: &lt;code&gt;void, char, short, int, long, float&lt;/code&gt; and  &lt;code&gt;double&lt;/code&gt;. &lt;strong&gt;C++&lt;/strong&gt; extends these five basic types with  several extra types: the types &lt;code&gt;bool, wchar_t&lt;/code&gt; and &lt;code&gt;long  double&lt;/code&gt;. The type &lt;code&gt;long double&lt;/code&gt; is merely a double-long  &lt;code&gt;double&lt;/code&gt; datatype. Apart from these basic types a standard type  &lt;code&gt;string&lt;/code&gt; is available. &lt;/span&gt;  &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="BOOL"&gt;&lt;/a&gt;&lt;a name="l37"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.3.1: The `bool'  data type&lt;/span&gt;&lt;/h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="first/bool"&gt;&lt;/a&gt;In &lt;strong&gt;C&lt;/strong&gt; the following basic data  types are available: &lt;code&gt;void, char, int, float&lt;/code&gt; and  &lt;code&gt;double&lt;/code&gt;. &lt;strong&gt;C++&lt;/strong&gt; extends these five basic types with  several extra types. In this section the type &lt;code&gt;bool&lt;/code&gt; is introduced.  &lt;/span&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The type  &lt;code&gt;bool&lt;/code&gt; represents boolean (logical) values, for which the (now  reserved) values &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt; may be used. Apart  from these reserved values, integral values may also be assigned to variables of  type &lt;code&gt;bool&lt;/code&gt;, which are implicitly converted to &lt;code&gt;true&lt;/code&gt; and  &lt;code&gt;false&lt;/code&gt; according to the following conversion rules (assume  &lt;code&gt;intValue&lt;/code&gt; is an &lt;code&gt;int&lt;/code&gt;-variable, and  &lt;code&gt;boolValue&lt;/code&gt; is a &lt;code&gt;bool&lt;/code&gt;-variable): &lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;       // from int to bool:&lt;br /&gt;   boolValue = intValue ? true : false;&lt;br /&gt;&lt;br /&gt;       // from bool to int:&lt;br /&gt;&lt;br /&gt;   intValue = boolValue ? 1 : 0;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Furthermore, when &lt;code&gt;bool&lt;/code&gt; values are inserted into, e.g.,  &lt;code&gt;cout&lt;/code&gt;, then &lt;code&gt;1&lt;/code&gt; is written for &lt;code&gt;true&lt;/code&gt; values,  and &lt;code&gt;0&lt;/code&gt; is written for &lt;code&gt;false&lt;/code&gt; values. Consider the  following example: &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   cout &lt;&lt; "A true value: "  &lt;&lt; true &lt;&lt; endl&lt;br /&gt;        &lt;&lt; "A false value: " &lt;&lt; false &lt;&lt; endl;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The  &lt;code&gt;bool&lt;/code&gt; data type is found in other programming languages as well.  &lt;strong&gt;Pascal&lt;/strong&gt; has its type &lt;code&gt;Boolean&lt;/code&gt;, and  &lt;strong&gt;Java&lt;/strong&gt; has a &lt;code&gt;boolean&lt;/code&gt; type. Different from these  languages, &lt;strong&gt;C++&lt;/strong&gt;'s type &lt;code&gt;bool&lt;/code&gt; acts like a kind of  &lt;code&gt;int&lt;/code&gt; type: it's primarily a documentation-improving type, having  just two values &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt;. Actually, these values  can be interpreted as &lt;code&gt;enum&lt;/code&gt; values for &lt;code&gt;1&lt;/code&gt; and  &lt;code&gt;0&lt;/code&gt;. Doing so would neglect the philosophy behind the  &lt;code&gt;bool&lt;/code&gt; data type, but nevertheless: assigning &lt;code&gt;true&lt;/code&gt; to an  &lt;code&gt;int&lt;/code&gt; variable neither produces warnings nor errors. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Using the  &lt;code&gt;bool&lt;/code&gt;-type is generally more intuitively clear than using  &lt;code&gt;int&lt;/code&gt;. Consider the following prototypes: &lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;       bool exists(char const *fileName);  // (1)&lt;br /&gt;       int  exists(char const *fileName);  // (2)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;For the  first prototype &lt;code&gt;(1)&lt;/code&gt;, most people will expect the function to return  &lt;code&gt;true&lt;/code&gt; if the given filename is the name of an existing file.  However, using the second prototype some ambiguity arises: intuitively the  returnvalue 1 is appealing, as it leads to constructions like &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;       if (exists("myfile"))&lt;br /&gt;           cout &lt;&lt; "myfile exists";&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;On the  other hand, many functions (like &lt;code&gt;access(), stat(),&lt;/code&gt; etc.) return  &lt;code&gt;0&lt;/code&gt; to indicate a successful operation, reserving other values to  indicate various types of errors. &lt;/span&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;As a rule of thumb  we suggest the following: If a function should inform its caller about the  success or failure of its task, let the function return a &lt;code&gt;bool&lt;/code&gt;  value. If the function should return success or various types of errors, let the  function return &lt;em&gt;enum&lt;/em&gt; values, documenting the situation when the  function returns. Only when the function returns a meaningful integral value  (like the sum of two &lt;code&gt;int&lt;/code&gt; values), let the function return an  &lt;code&gt;int&lt;/code&gt; value. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="WCHAR"&gt;&lt;/a&gt;&lt;a name="l38"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.3.2: The  `wchar_t' data type&lt;/span&gt;&lt;/h3&gt;&lt;a name="first/wchar"&gt;&lt;/a&gt;The &lt;code&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;wchar_t&lt;/span&gt;&lt;/code&gt; type  is an extension of the &lt;code&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;char&lt;/span&gt;&lt;/code&gt; basic type, to accomodate &lt;em&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;wide&lt;/span&gt;&lt;/em&gt; character  values, such as the &lt;em&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Unicode&lt;/span&gt;&lt;/em&gt; character set. &lt;code&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Sizeof(wchar_t)&lt;/span&gt;&lt;/code&gt; is 2, allowing for 65,536 different  character values.   &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Note that a  programming language like &lt;strong&gt;Java&lt;/strong&gt; has a data type  &lt;code&gt;char&lt;/code&gt; that is comparable to &lt;strong&gt;C++&lt;/strong&gt;'s  &lt;code&gt;wchar_t&lt;/code&gt; type, while &lt;strong&gt;Java&lt;/strong&gt;'s &lt;code&gt;byte&lt;/code&gt; data  type is comparable to &lt;strong&gt;C++&lt;/strong&gt;'s &lt;code&gt;char&lt;/code&gt; type. Very  convenient.... &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="l39"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h2&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.4: Data hiding:  public, private and class&lt;/span&gt;&lt;/h2&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="first/public"&gt;&lt;/a&gt;As  mentioned previously &lt;strong&gt;C++&lt;/strong&gt; contains special syntactical  possibilities to implement data hiding. Data hiding is the ability of one  program part to hide its data from other parts; thus avoiding improper  addressing or name collisions of data. &lt;/span&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;C++&lt;/strong&gt; has two special keywords which are concerned with  data hiding: &lt;code&gt;private&lt;/code&gt; and &lt;code&gt;public&lt;/code&gt;. These keywords can be  inserted in the definition of a &lt;code&gt;struct&lt;/code&gt;. The keyword  &lt;code&gt;public&lt;/code&gt; defines all subsequent fields of a structure as accessible  by all code; the keyword &lt;code&gt;private&lt;/code&gt; defines all subsequent fields as  only accessible by the code which is part of the &lt;code&gt;struct&lt;/code&gt; (i.e., only  accessible for the member functions) (Besides &lt;code&gt;public&lt;/code&gt; and  &lt;code&gt;private&lt;/code&gt;, &lt;strong&gt;C++&lt;/strong&gt; defines the keyword  &lt;code&gt;protected&lt;/code&gt;. This keyword is not often used and it is left for the  reader to explore.). In a &lt;code&gt;struct&lt;/code&gt; all fields are  &lt;code&gt;public&lt;/code&gt;, unless explicitly stated otherwise. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;With this knowledge  we can expand the &lt;code&gt;struct&lt;/code&gt; &lt;code&gt;person&lt;/code&gt;: &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   struct person&lt;br /&gt;   {&lt;br /&gt;       public:&lt;br /&gt;           void&lt;br /&gt;               setname (char const *n),&lt;br /&gt;               setaddress (char const *a),&lt;br /&gt;               print (void);&lt;br /&gt;           char const&lt;br /&gt;               *getname (void),&lt;br /&gt;               *getaddress (void);&lt;br /&gt;       private:&lt;br /&gt;           char&lt;br /&gt;               name [80],&lt;br /&gt;               address [80];&lt;br /&gt;   };&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The data fields  &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;address&lt;/code&gt; are only accessible for the member  functions which are defined in the &lt;code&gt;struct&lt;/code&gt;: these are the functions  &lt;code&gt;setname()&lt;/code&gt;, &lt;code&gt;setaddress()&lt;/code&gt; etc.. This property of the  data type is given by the fact that the fields &lt;code&gt;name&lt;/code&gt; and  &lt;code&gt;address&lt;/code&gt; are preceded by the keyword &lt;code&gt;private&lt;/code&gt;. As an  illustration consider the following code fragment: &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   person&lt;br /&gt;       x;&lt;br /&gt;&lt;br /&gt;   x.setname ("Frank");        // ok, setname() is public&lt;br /&gt;   strcpy (x.name, "Knarf");   // error, name is private&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The concept of data  hiding is realized here in the following manner. The actual data of a  &lt;code&gt;struct&lt;/code&gt; &lt;code&gt;person&lt;/code&gt; are named only in the structure  definition. The data are accessed by the outside world by special functions,  which are also part of the definition. These member functions control all  traffic between the data fields and other parts of the program and are therefore  also called `interface' functions. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="datahiding"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;center&gt; &lt;/center&gt;   &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Also note that the  functions &lt;code&gt;setname()&lt;/code&gt; and &lt;code&gt;setaddress()&lt;/code&gt; are declared as  having a &lt;code&gt;char const *&lt;/code&gt; argument. This means that the functions will  not alter the strings which are supplied as their arguments. In the same vein,  the functions &lt;code&gt;getname()&lt;/code&gt; and &lt;code&gt;getaddress()&lt;/code&gt; return a  &lt;code&gt;char const *&lt;/code&gt;: the caller may not modify the strings which are  pointed to by the return values. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Two examples of  member functions of the &lt;code&gt;struct&lt;/code&gt; &lt;code&gt;person&lt;/code&gt; are shown below:  &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   void person::setname(char const *n)&lt;br /&gt;   {&lt;br /&gt;       strncpy(name, n, 79);&lt;br /&gt;       name[79] = '\0';&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   char const *person::getname()&lt;br /&gt;   {&lt;br /&gt;       return (name);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;In general, the  power of the member functions and of the concept of data hiding lies in the fact  that the interface functions can perform special tasks, e.g., checks for the  validity of data. In the above example &lt;code&gt;setname()&lt;/code&gt; copies only up to  79 characters from its argument to the data member &lt;code&gt;name&lt;/code&gt;, thereby  avoiding array boundary overflow. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Another example of  the concept of data hiding is the following. As an alternative to member  functions which keep their data in memory (as do the above code examples), a  runtime library could be developed with interface functions which store their  data on file. The conversion of a program which stores &lt;code&gt;person&lt;/code&gt;  structures in memory to one that stores the data on disk would mean the  relinking of the program with a different library. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Though data hiding  can be realized with &lt;code&gt;structs&lt;/code&gt;, more often (almost always) classes  are used instead. A &lt;code&gt;class&lt;/code&gt; is in principle equivalent to a  &lt;code&gt;struct&lt;/code&gt; except that unless specified otherwise, all members (data or  functions) are &lt;code&gt;private&lt;/code&gt;. As far as &lt;code&gt;private&lt;/code&gt; and  &lt;code&gt;public&lt;/code&gt; are concerned, a &lt;code&gt;class&lt;/code&gt; is therefore the  opposite of a &lt;code&gt;struct&lt;/code&gt;. The definition of a &lt;code&gt;class&lt;/code&gt;  &lt;code&gt;person&lt;/code&gt; would therefore look exactly as shown above, except for the  fact that instead of the keyword &lt;code&gt;struct&lt;/code&gt;, &lt;code&gt;class&lt;/code&gt; would  be used. Our typographic suggestion for class names is a capital as first  character, followed by the remainder of the name in lower case (e.g.,  &lt;code&gt;Person&lt;/code&gt;). &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="l40"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h2&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.5: Structs in C  vs. structs in C++&lt;/span&gt;&lt;/h2&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="first/cvscpp"&gt;&lt;/a&gt;At the end of this chapter we would like to  illustrate the analogy between &lt;strong&gt;C&lt;/strong&gt; and &lt;strong&gt;C++&lt;/strong&gt; as  far as &lt;code&gt;struct&lt;/code&gt;s are concerned. In &lt;strong&gt;C&lt;/strong&gt; it is common to  define several functions to process a &lt;code&gt;struct&lt;/code&gt;, which then require a  pointer to the &lt;code&gt;struct&lt;/code&gt; as one of their arguments. A fragment of an  imaginary &lt;strong&gt;C&lt;/strong&gt; header file is given below: &lt;/span&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   // definition of a struct PERSON_&lt;br /&gt;   typedef struct&lt;br /&gt;   {&lt;br /&gt;       char&lt;br /&gt;           name[80],&lt;br /&gt;           address[80];&lt;br /&gt;   } PERSON_;&lt;br /&gt;&lt;br /&gt;   // some functions to manipulate PERSON_ structs&lt;br /&gt;&lt;br /&gt;   // initialize fields with a name and address&lt;br /&gt;   extern void initialize(PERSON_ *p, char const *nm,&lt;br /&gt;                          char const *adr);&lt;br /&gt;&lt;br /&gt;   // print information&lt;br /&gt;   extern void print(PERSON_ const *p);&lt;br /&gt;&lt;br /&gt;   // etc..&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;In  &lt;strong&gt;C++&lt;/strong&gt;, the declarations of the involved functions are placed  inside the definition of the &lt;code&gt;struct&lt;/code&gt; or &lt;code&gt;class&lt;/code&gt;. The  argument which denotes which &lt;code&gt;struct&lt;/code&gt; is involved is no longer  needed. &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   class Person&lt;br /&gt;   {&lt;br /&gt;       public:&lt;br /&gt;           void initialize(char const *nm, char const *adr);&lt;br /&gt;           void print(void);&lt;br /&gt;           // etc..&lt;br /&gt;       private:&lt;br /&gt;           char&lt;br /&gt;               name[80],&lt;br /&gt;               address[80];&lt;br /&gt;   };&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The  &lt;code&gt;struct&lt;/code&gt; argument is implicit in &lt;strong&gt;C++&lt;/strong&gt;. A function  call in &lt;strong&gt;C&lt;/strong&gt; like &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   PERSON_&lt;br /&gt;       x;&lt;br /&gt;&lt;br /&gt;   initialize(&amp;amp;x, "some name", "some address");&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;becomes in  &lt;strong&gt;C++&lt;/strong&gt;: &lt;/span&gt;&lt;/p&gt; &lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   Person&lt;br /&gt;       x;&lt;br /&gt;&lt;br /&gt;   x.initialize("some name", "some address");&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="Namespaces"&gt;&lt;/a&gt;&lt;a name="l41"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h2&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.6:  Namespaces&lt;/span&gt;&lt;/h2&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="namespace/intro"&gt;&lt;/a&gt;Imagine a math teacher who wants to develop  an interactive math program. For this program functions like &lt;code&gt;cos(), sin(),  tan()&lt;/code&gt; etc. are to be used accepting arguments in degrees rather than  arguments in radials. Unfortunately, the functionname &lt;code&gt;cos()&lt;/code&gt; is  already in use, and that function accepts radials as its arguments, rather than  degrees. &lt;/span&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Problems like these  are normally solved by looking for another name, e.g., the functionname  &lt;code&gt;cosDegrees()&lt;/code&gt; is defined. &lt;strong&gt;C++&lt;/strong&gt; offers an alternative  solution by allowing &lt;em&gt;namespaces&lt;/em&gt; to be defined: areas or regions in the  code in which identifiers are defined which cannot conflict with existing names  defined elsewhere. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="l42"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.6.1: Defining  namespaces&lt;/span&gt;&lt;/h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="namespace/defining"&gt;&lt;/a&gt;Namespaces are defined according to the  following syntax: &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   namespace identifier&lt;br /&gt;   {&lt;br /&gt;       // declared or defined entities&lt;br /&gt;       // (declarative region)&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The  identifier used in the definition of a namespace is a standard  &lt;strong&gt;C++&lt;/strong&gt; identifier. &lt;/span&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Within the  &lt;em&gt;declarative region&lt;/em&gt;, introduced in the above code example, functions,  variables, structs, classes and even (nested) namespaces can be defined or  declared. Namespaces cannot be defined within a block. So it is not possible to  define a namespace within, e.g., a function. However, it is possible to define a  namespace using multiple &lt;em&gt;namespace&lt;/em&gt; declarations. Namespaces are said to  be &lt;em&gt;open&lt;/em&gt;. This means that a namespace &lt;code&gt;CppAnnotations&lt;/code&gt; could  be defined in a file &lt;code&gt;file1.cc&lt;/code&gt; and also in a file  &lt;code&gt;file2.cc&lt;/code&gt;. The entities defined in the &lt;code&gt;CppAnnotations&lt;/code&gt;  namespace of files &lt;code&gt;file1.cc&lt;/code&gt; and &lt;code&gt;file2.cc&lt;/code&gt; are then  united in one &lt;code&gt;CppAnnotations&lt;/code&gt; namespace region. For example: &lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   // in file1.cc&lt;br /&gt;   namespace CppAnnotations&lt;br /&gt;   {&lt;br /&gt;       double cos(double argInDegrees)&lt;br /&gt;       {&lt;br /&gt;           ...&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   // in file2.cc&lt;br /&gt;   namespace CppAnnotations&lt;br /&gt;   {&lt;br /&gt;       double sin(double argInDegrees)&lt;br /&gt;       {&lt;br /&gt;           ...&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;Both &lt;code&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;sin()&lt;/span&gt;&lt;/code&gt; and &lt;code&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;cos()&lt;/span&gt;&lt;/code&gt; are now  defined in the same &lt;code&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CppAnnotations&lt;/span&gt;&lt;/code&gt; namespace.   &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Namespace entities  can also be defined outside of their namespaces. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="l43"&gt;&lt;/a&gt;&lt;strong&gt;3.6.1.1: Declaring entities in  namespaces&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="namespace/declaring"&gt;&lt;/a&gt;Instead of &lt;em&gt;defiing&lt;/em&gt; entities in a  namespace, entities may also be &lt;em&gt;declared&lt;/em&gt; in a namespace. This allows us  to put all the declarations of a namespace in a header file which can thereupon  be included in sources in which the entities of a namespace are used. Such a  header file could contain, e.g., &lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   namespace CppAnnotations&lt;br /&gt;   {&lt;br /&gt;       double cos(double degrees);&lt;br /&gt;       double sin(double degrees);&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;   &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="l44"&gt;&lt;/a&gt;&lt;strong&gt;3.6.1.2: A closed namespace&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="namespace/closed"&gt;&lt;/a&gt;Namespaces can be defined without a name. Such a  namespace is anonymous and it restricts the usability of the defined entities to  the source file in which the anonymous namespace is defined. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The entities that  are defined in the anonymous namespace are accessible the same way as  &lt;code&gt;static&lt;/code&gt; functions and variables in &lt;strong&gt;C&lt;/strong&gt;. The  &lt;code&gt;static&lt;/code&gt; keyword can still be used in &lt;strong&gt;C++&lt;/strong&gt;, but its  use is more dominant in &lt;code&gt;class&lt;/code&gt; definitions (see chapter &lt;a href="cplusplus05.html#Classes" tppabs="http://www.icce.rug.nl/docs/cplusplus/cplusplus05.html#Classes"&gt;5&lt;/a&gt;).  In situations where static variables or functions are necessary, the use of the  anonymous namespace is preferred. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="l45"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.6.2: Referring  to entities&lt;/span&gt;&lt;/h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="namespace/referring"&gt;&lt;/a&gt;Given a namespace and entities that are  defined or declared in it, the scope resolution operator can be used to refer to  the entities that are defined in the namespace. For example, to use the function  &lt;code&gt;cos()&lt;/code&gt; defined in the &lt;code&gt;CppAnnotations&lt;/code&gt; namespace the  following code could be used: &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   // assume the CppAnnotations namespace is declared in the next header&lt;br /&gt;   // file:&lt;br /&gt;   #include &lt;cppannotations&gt;&lt;br /&gt;  &lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       cout &lt;&lt; "The cosine of 60 degrees is: " &lt;&lt;&lt;br /&gt;               CppAnnotations::cos(60) &lt;&lt; endl;&lt;br /&gt;       return (0);&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This is a  rather cumbersome way to refer to the &lt;code&gt;cos()&lt;/code&gt; function in the  &lt;code&gt;CppAnnotations&lt;/code&gt; namespace, especially so if the function is  frequently used. &lt;/span&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Therefore, an  &lt;em&gt;abbreviated&lt;/em&gt; form (just &lt;code&gt;cos()&lt;/code&gt; can be used by declaring that  &lt;code&gt;cos()&lt;/code&gt; will refer to &lt;code&gt;CppAnnotations::cos()&lt;/code&gt;. For this,  the &lt;code&gt;using&lt;/code&gt;-declaration can be used. Following &lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   using CppAnnotations::cos;      // note: no function prototype, just the&lt;br /&gt;                                   // name of the entity is required.   &lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;the  function &lt;code&gt;cos()&lt;/code&gt; will refer to the &lt;code&gt;cos()&lt;/code&gt; function in the  &lt;code&gt;CppAnnotations&lt;/code&gt; namespace. This implies that the standard  &lt;code&gt;cos()&lt;/code&gt; function, accepting radials, cannot be used automatically  anymore. The plain scope resolution operator can be used to reach the generic  &lt;code&gt;cos()&lt;/code&gt; function: &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       using CppAnnotations::cos;&lt;br /&gt;       ...&lt;br /&gt;       cout &lt;&lt; cos(60)         // this uses CppAnnotations::cos()&lt;br /&gt;           &lt;&lt; ::cos(1.5)       // this uses the standard cos() function&lt;br /&gt;           &lt;&lt; endl;&lt;br /&gt;       return (0);&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Note that  a &lt;code&gt;using&lt;/code&gt;-declaration can be used inside a block. The  &lt;code&gt;using&lt;/code&gt; declaration prevents the definition of entities having the  same name as the one used in the &lt;code&gt;using&lt;/code&gt; declaration: it is not  possible to use a using declaration for a variable &lt;code&gt;value&lt;/code&gt; in the  &lt;code&gt;CppAnnotations&lt;/code&gt; namespace, and to define (or declare) an identically  named object in the block in which the &lt;code&gt;using&lt;/code&gt; declaration was  placed: &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       using CppAnnotations::value;&lt;br /&gt;       ...&lt;br /&gt;       cout &lt;&lt; value &lt;&lt; endl;  // this uses CppAnnotations::value&lt;br /&gt;&lt;br /&gt;       int&lt;br /&gt;           value;              // error: value already defined.&lt;br /&gt;&lt;br /&gt;       return (0);&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="l46"&gt;&lt;/a&gt;&lt;strong&gt;3.6.2.1: The using directive&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="namespace/directive"&gt;&lt;/a&gt;A generalized alternative to the  &lt;code&gt;using&lt;/code&gt;-declaration is the &lt;code&gt;using&lt;/code&gt;-&lt;em&gt;directive&lt;/em&gt;:  &lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   using namespace CppAnnotations;&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Following  this directive, &lt;em&gt;all&lt;/em&gt; entities defined in the &lt;code&gt;CppAnnotations&lt;/code&gt;  namespace are uses as if they where declared by &lt;code&gt;using&lt;/code&gt; declarations.  &lt;/span&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;While the  &lt;code&gt;using&lt;/code&gt;-directive is a quick way to import all the names of the  &lt;code&gt;CppAnnotations&lt;/code&gt; namespace (assuming the entities are declared or  defined separately from the directive), it is at the same time a somewhat dirty  way to do so, as it is less clear which entity will be used in a particular  block of code. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;If, e.g.,  &lt;code&gt;cos()&lt;/code&gt; is defined in the &lt;code&gt;CppAnnotations&lt;/code&gt; namespace, the  function &lt;code&gt;CppAnnotations::cos()&lt;/code&gt; will be used when &lt;code&gt;cos()&lt;/code&gt;  is called in the code. However, if &lt;code&gt;cos()&lt;/code&gt; is &lt;em&gt;not&lt;/em&gt; defined in  the &lt;code&gt;CppAnnotations&lt;/code&gt; namespace, the standard &lt;code&gt;cos()&lt;/code&gt;  function will be used. The &lt;code&gt;using&lt;/code&gt; directive does not document as  clearly which entity will be used as the &lt;code&gt;using&lt;/code&gt; declaration does.  For this reason, the &lt;code&gt;using&lt;/code&gt; directive is somewhat deprecated.  &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="l47"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.6.3: The  standard namespace&lt;/span&gt;&lt;/h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="namespace/std"&gt;&lt;/a&gt;Apart from the anonymous namespace, many  entities of the runtime available software (e.g., &lt;code&gt;cout, cin, cerr&lt;/code&gt;  and the templates defined in the &lt;em&gt;Standard Template Library&lt;/em&gt;) are now  defined in the &lt;code&gt;std&lt;/code&gt; namespace. &lt;/span&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Regarding the  discussion in the previous section, one should use a &lt;code&gt;using&lt;/code&gt;  declaration for these entities. For example, in order to use the  &lt;code&gt;cout&lt;/code&gt; stream, the code should start with something like &lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   #include &lt;iostream&gt;&lt;br /&gt;  &lt;br /&gt;   using std::cout;&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Often,  however, the identifiers that are defined in the &lt;code&gt;std&lt;/code&gt; namespace can  all be accepted without much thought. Because of that, one often encounters a  &lt;code&gt;using&lt;/code&gt; directive, rather than a &lt;code&gt;using&lt;/code&gt; declaration with  the &lt;code&gt;std&lt;/code&gt; namespace. So, instead of the mentioned &lt;code&gt;using  declaration&lt;/code&gt; a construction like &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   #include &lt;iostream&gt;&lt;br /&gt;  &lt;br /&gt;   using namespace std;&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;is often  encountered. Whether this should be encouraged is subject of some dispute. Long  &lt;code&gt;using&lt;/code&gt; declarations are of course inconvenient too. So as a rule of  thumb one might decide to stick to &lt;code&gt;using&lt;/code&gt; declarations, up to the  point where the list becomes impractically long, at which point a  &lt;code&gt;using&lt;/code&gt; directive could be considered. &lt;/span&gt;  &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="l48"&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;&lt;h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;3.6.4: Nesting  namespaces and namespace aliasing&lt;/span&gt;&lt;/h3&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="namespace/nesting"&gt;&lt;/a&gt;Namespaces can be nested. The following code shows  the definition of a nested namespace: &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   namespace CppAnnotations&lt;br /&gt;   {&lt;br /&gt;       namespace Virtual&lt;br /&gt;       {&lt;br /&gt;           void&lt;br /&gt;               *pointer;&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Now the  variable &lt;code&gt;pointer&lt;/code&gt; defined in the &lt;code&gt;Virtual&lt;/code&gt; namespace,  nested under the &lt;code&gt;CppAnnotations&lt;/code&gt; namespace. In order to refer to  this variable, the following options are available: &lt;/span&gt; &lt;ul&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The &lt;em&gt;fully  qualified name&lt;/em&gt; can be used. A fully qualified name of an entity is a list  of all the namespaces that are visited until the definition of the entity is  reached, glued together by the scope resolution operator: &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       CppAnnotations::Virtual::pointer = 0;&lt;br /&gt;       return (0);&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;A  &lt;code&gt;using&lt;/code&gt; declaration for &lt;code&gt;CppAnnotations::Virtual&lt;/code&gt; can be  used. Now &lt;code&gt;Virtual&lt;/code&gt; can be used without any prefix, but  &lt;code&gt;pointer&lt;/code&gt; must be used with the &lt;code&gt;Virtual::&lt;/code&gt; prefix:  &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   ...&lt;br /&gt;   using CppAnnotations::Virtual;&lt;br /&gt;&lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       Virtual::pointer = 0;&lt;br /&gt;       return (0);&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;A  &lt;code&gt;using&lt;/code&gt; declaration for &lt;code&gt;CppAnnotations::Virtual::pointer&lt;/code&gt;  can be used. Now &lt;code&gt;pointer&lt;/code&gt; can be used without any prefix: &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   ...&lt;br /&gt;   using CppAnnotations::Virtual::pointer;&lt;br /&gt;&lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       pointer = 0;&lt;br /&gt;       return (0);&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;A  &lt;code&gt;using&lt;/code&gt; directive or directives can be used: &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   ...&lt;br /&gt;   using namespace CppAnnotations::Virtual;&lt;br /&gt;&lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       pointer = 0;&lt;br /&gt;       return (0);&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Alternatively, two separate &lt;code&gt;using&lt;/code&gt; directives could have been  used: &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   ...&lt;br /&gt;   using namespace CppAnnotations;&lt;br /&gt;   using namespace Virtual;&lt;br /&gt;&lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       pointer = 0;&lt;br /&gt;       return (0);&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;A combination of  &lt;code&gt;using&lt;/code&gt; declarations and &lt;code&gt;using&lt;/code&gt; directives can be used.  E.g., a &lt;code&gt;using&lt;/code&gt; directive can be used for the  &lt;code&gt;CppAnnotations&lt;/code&gt; namespace, and a &lt;code&gt;using&lt;/code&gt; declaration can  be used for the &lt;code&gt;Virtual::pointer&lt;/code&gt; variable: &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   ...&lt;br /&gt;   using namespace CppAnnotations;&lt;br /&gt;   using Virtual::pointer;&lt;br /&gt;&lt;br /&gt;   int main()&lt;br /&gt;   {&lt;br /&gt;       pointer = 0;&lt;br /&gt;       return (0);&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;At every &lt;code&gt;using&lt;/code&gt; directive all entities of that namespace can  be used without any further prefix. If a namespace is nested, then that  namespace can also be used without any further prefix. However, the entities  defined in the nested namespace still need the nested namespace's name. Only by  using a &lt;code&gt;using&lt;/code&gt; declaration or directive the qualified name of the  nested namespace can be omitted. &lt;/span&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;When fully  qualified names are somehow preferred, while the long form (like  &lt;code&gt;CppAnnotations::Virtual::pointer&lt;/code&gt;) is at the same time considered  too long, a namespace &lt;em&gt;alias&lt;/em&gt; can be used: &lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   namespace CV = CppAnnotations::Virtual;&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This  defines &lt;code&gt;CV&lt;/code&gt; as an &lt;em&gt;alias&lt;/em&gt; for the full name. So, to refer to  the &lt;code&gt;pointer&lt;/code&gt; variable the construction &lt;/span&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   CV::pointer = 0;&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Of  course, a namespace alias itself can also be used in a &lt;code&gt;using&lt;/code&gt;  declaration or directive. &lt;/span&gt;  &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="OUTSIDE"&gt;&lt;/a&gt;&lt;a name="l49"&gt;&lt;/a&gt;&lt;strong&gt;3.6.4.1: Defining entities outside of  their namespaces&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;a name="namespace/outside"&gt;&lt;/a&gt;It is not strictly necessary to define members of  namespaces within a &lt;code&gt;namespace&lt;/code&gt; region. By prefixing the member by  its namespace or namespaces a member can be defined outside of a namespace  region. This may be done at the global level, or at intermediate levels in the  case of nested namespaces. So while it is not possible to define a member of  namespace &lt;code&gt;A&lt;/code&gt; within the region of namespace &lt;code&gt;C&lt;/code&gt;, it is  possible to define a member of namespace &lt;code&gt;A::B&lt;/code&gt; within the region of  namespace &lt;code&gt;A&lt;/code&gt;. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Note, however, that  when a member of a namespace is defined outside of a namespace region, it must  &lt;em&gt;still be declared within&lt;/em&gt; the region. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Assume the type  &lt;code&gt;int INT8[8]&lt;/code&gt; is defined in the &lt;code&gt;CppAnnotations::Virtual&lt;/code&gt;  namespace. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Now suppose we want  to define (at the global level) a member function &lt;code&gt;funny&lt;/code&gt; of  namespace &lt;code&gt;CppAnnotations::Virtual&lt;/code&gt;, returning a pointer to  &lt;code&gt;CppAnnotations::Virtual::INT8&lt;/code&gt;. The definition of such a function  could be as follows (first everything is defined inside the  &lt;code&gt;CppAnnotations::Virtual&lt;/code&gt; namespace): &lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   namespace CppAnnotations&lt;br /&gt;   {&lt;br /&gt;       namespace Virtual&lt;br /&gt;       {&lt;br /&gt;           void&lt;br /&gt;               *pointer;&lt;br /&gt;&lt;br /&gt;           typedef int INT8[8];&lt;br /&gt;&lt;br /&gt;           INT8 *funny()&lt;br /&gt;           {&lt;br /&gt;               INT8&lt;br /&gt;                   *ip = new INT8[1];&lt;br /&gt;              &lt;br /&gt;               for (int idx = 0; idx &lt; sizeof(INT8) / sizeof(int); ++idx)&lt;br /&gt;                   (*ip)[idx] = (1 + idx) * (1 + idx);&lt;br /&gt;&lt;br /&gt;               return (ip);&lt;br /&gt;           }&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The  function &lt;code&gt;funny()&lt;/code&gt; defines an array of one &lt;code&gt;INT8&lt;/code&gt; vector,  and returns its address after initializing the vector by the squares of the  first eight natural numbers. &lt;/span&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Now the function  &lt;code&gt;funny()&lt;/code&gt; can be defined outside of the  &lt;code&gt;CppAnnotations::Virtual&lt;/code&gt; as follows: &lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   namespace CppAnnotations&lt;br /&gt;   {&lt;br /&gt;       namespace Virtual&lt;br /&gt;       {&lt;br /&gt;           void&lt;br /&gt;               *pointer;&lt;br /&gt;&lt;br /&gt;           typedef int INT8[8];&lt;br /&gt;&lt;br /&gt;           INT8 *funny();&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   CppAnnotations::Virtual::INT8 *CppAnnotations::Virtual::funny()&lt;br /&gt;   {&lt;br /&gt;       INT8&lt;br /&gt;           *ip = new INT8[1];&lt;br /&gt;      &lt;br /&gt;       for (int idx = 0; idx &lt; sizeof(INT8) / sizeof(int); ++idx)&lt;br /&gt;       {&lt;br /&gt;           cout &lt;&lt; idx &lt;&lt; endl;&lt;br /&gt;           (*ip)[idx] = idx * idx;&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       return (ip);&lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;At the  final code fragment note the following: &lt;/span&gt; &lt;ul&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;code&gt;funny()&lt;/code&gt; is declared inside of the  &lt;code&gt;CppAnnotations::Virtual&lt;/code&gt; namespace. &lt;/span&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The definition  outside of the namespace region requires us to use the fully qualified name of  the function &lt;em&gt;and&lt;/em&gt; of its returntype. &lt;/span&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;em&gt;Inside&lt;/em&gt;  the block of the function &lt;code&gt;funny&lt;/code&gt; we are within the  &lt;code&gt;CppAnnotations::Virtual&lt;/code&gt; namespace, so inside the function fully  qualified names (e.g., for &lt;code&gt;INT8&lt;/code&gt; are not required any more.  &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Finally, note that  the function could also have been defined in the &lt;code&gt;CppAnnotations&lt;/code&gt;  region. It that case the &lt;code&gt;Virtual&lt;/code&gt; namespace would have been required  for the function name and its returntype, while the internals of the function  would remain the same: &lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;   namespace CppAnnotations&lt;br /&gt;   {&lt;br /&gt;       namespace Virtual&lt;br /&gt;       {&lt;br /&gt;           void&lt;br /&gt;               *pointer;&lt;br /&gt;&lt;br /&gt;           typedef int INT8[8];&lt;br /&gt;&lt;br /&gt;           INT8 *funny();&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       Virtual::INT8 *Virtual::funny()&lt;br /&gt;       {&lt;br /&gt;           INT8&lt;br /&gt;               *ip = new INT8[1];&lt;br /&gt;          &lt;br /&gt;           for (int idx = 0; idx &lt; sizeof(INT8) / sizeof(int); ++idx)&lt;br /&gt;           {&lt;br /&gt;               cout &lt;&lt; idx &lt;&lt; endl;&lt;br /&gt;               (*ip)[idx] = idx * idx;&lt;br /&gt;           }&lt;br /&gt;  &lt;br /&gt;           return (ip);&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;       &lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3800941631712763981-2020628114984832582?l=ab-ebooks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ab-ebooks.blogspot.com/feeds/2020628114984832582/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3800941631712763981&amp;postID=2020628114984832582' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3800941631712763981/posts/default/2020628114984832582'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3800941631712763981/posts/default/2020628114984832582'/><link rel='alternate' type='text/html' href='http://ab-ebooks.blogspot.com/2007/09/histroy-of-c.html' title='Histroy of C++'/><author><name>Niranjan</name><uri>http://www.blogger.com/profile/13413521883177554840</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3800941631712763981.post-2878726171022551264</id><published>2007-09-23T23:11:00.000-07:00</published><updated>2007-09-23T23:18:52.056-07:00</updated><title type='text'>About c</title><content type='html'>&lt;div align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Let    us begin with a quick introduction in C. Our aim is to show the essential elements    of the language in real programs, but without getting bogged down in details,    rules, and exceptions. At this point, we are not trying to be complete or even    precise (save that the examples are meant to be correct). We want to get you    as quickly as possible to the point where you can write useful programs, and    to do that we have to concentrate on the basics: variables and constants, arithmetic,    control flow, functions, and the rudiments of input and output. We are intentionally    leaving out of this chapter features of C that are important for writing bigger    programs. These include pointers, structures, most of C's rich set of operators,    several control-flow statements, and the standard library. &lt;/span&gt; &lt;/div&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;This    approach and its drawbacks. Most notable is that the complete story on any particular    feature is not found here, and the tutorial, by being brief, may also be misleading.    And because the examples do not use the full power of C, they are not as concise    and elegant as they might be. We have tried to minimize these effects, but be    warned. Another drawback is that later chapters will necessarily repeat some    of this chapter. We hope that the repetition will help you more than it annoys.    &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;In    any case, experienced programmers should be able to extrapolate from the material    in this chapter to their own programming needs. Beginners should supplement    it by writing small, similar programs of their own. Both groups can use it as    a framework on which to hang the more detailed descriptions that begin in Chapter    2. &lt;/span&gt; &lt;/p&gt;&lt;h2 align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="s1.1"&gt;1.1    Getting Started&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt; &lt;div align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;    The only way to learn a new programming language is by writing programs in it.    The first program to write is the same for all languages:&lt;br /&gt;  &lt;em&gt;Print the words&lt;/em&gt;&lt;br /&gt;  &lt;tt&gt;hello, world&lt;/tt&gt; &lt;/span&gt;&lt;/div&gt; &lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;This is    a big hurdle; to leap over it you have to be able to create the program text    somewhere, compile it successfully, load it, run it, and find out where your    output went. With these mechanical details mastered, everything else is comparatively    easy. &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;In C, the    program to print ``&lt;tt&gt;hello, world&lt;/tt&gt;'' is &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;  &lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;   printf("hello, world\n");&lt;br /&gt; }&lt;br /&gt;&lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;  &lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; Just how to run this program    depends on the system you are using. As a specific example, on the UNIX operating    system you must create the program in a file whose name ends in ``&lt;tt&gt;.c&lt;/tt&gt;'',    such as &lt;tt&gt;hello.c&lt;/tt&gt;, then compile it with the command &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   cc hello.c&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  If you haven't botched anything, such as omitting a character or misspelling    something, the compilation will proceed silently, and make an executable file    called &lt;tt&gt;a.out&lt;/tt&gt;. If you run &lt;tt&gt;a.out&lt;/tt&gt; by typing the command    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   a.out&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  it will print    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   hello, world&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  On other systems, the rules will be different; check with a local expert. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;Now, for some explanations about the program itself. A C program,    whatever its size, consists of &lt;em&gt;functions&lt;/em&gt; and &lt;em&gt;variables&lt;/em&gt;. A    function contains &lt;em&gt;statements&lt;/em&gt; that specify the computing operations    to be done, and variables store values used during the computation. C functions    are like the subroutines and functions in Fortran or the procedures and functions    of Pascal. Our example is a function named &lt;tt&gt;main&lt;/tt&gt;. Normally you are at    liberty to give functions whatever names you like, but ``&lt;tt&gt;main&lt;/tt&gt;'' is    special - your program begins executing at the beginning of main. This means    that every program must have a &lt;tt&gt;main&lt;/tt&gt; somewhere.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;tt&gt;main&lt;/tt&gt; will usually call other functions to help perform    its job, some that you wrote, and others from libraries that are provided for    you. The first line of the program,  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  tells the compiler to include information about the standard input/output library;    the line appears at the beginning of many C source files. The standard library    is described in Chapter 7. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;One method of communicating data between functions is for the    calling function to provide a list of values, called &lt;em&gt;arguments&lt;/em&gt;, to    the function it calls. The parentheses after the function name surround the    argument list. In this example, &lt;tt&gt;main&lt;/tt&gt; is defined to be a function that    expects no arguments, which is indicated by the empty list &lt;tt&gt;( )&lt;/tt&gt;. &lt;/span&gt;&lt;/span&gt;  &lt;/p&gt;&lt;p align="justify"&gt;   &lt;/p&gt;&lt;div align="justify"&gt;   &lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;#include &lt;stdio.h&gt;                 &lt;em&gt;include information about standard library&lt;/em&gt;&lt;br /&gt;main()                                          &lt;em&gt;define a function called main&lt;/em&gt;&lt;br /&gt;                                           &lt;em&gt;that received no argument values&lt;/em&gt;&lt;br /&gt;{                                   &lt;em&gt;statements of main are enclosed in braces&lt;/em&gt;&lt;br /&gt;  printf("hello, world\n");              &lt;em&gt;main calls library function printf&lt;/em&gt;&lt;br /&gt;                                       &lt;em&gt;to print this sequence of characters&lt;/em&gt;&lt;br /&gt;}                                         \n &lt;em&gt;represents the newline character&lt;/em&gt; &lt;/stdio.h&gt;&lt;/span&gt;&lt;/pre&gt; &lt;/div&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;strong&gt;The    first C program&lt;/strong&gt; &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;   &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The    statements of a function are enclosed in braces &lt;tt&gt;{ }&lt;/tt&gt;. The function &lt;tt&gt;main&lt;/tt&gt;    contains only one statement, &lt;/span&gt; &lt;/p&gt;&lt;div align="justify"&gt;   &lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;   printf("hello, world\n");&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;   &lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;A function is called    by naming it, followed by a parenthesized list of arguments, so this calls the    function &lt;tt&gt;printf&lt;/tt&gt; with the argument &lt;tt&gt;"hello, world\n"&lt;/tt&gt;. &lt;tt&gt;printf&lt;/tt&gt;    is a library function that prints output, in this case the string of characters    between the quotes. &lt;/span&gt; &lt;/div&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;A    sequence of characters in double quotes, like &lt;tt&gt;"hello, world\n"&lt;/tt&gt;, is    called a &lt;em&gt;character string&lt;/em&gt; or &lt;em&gt;string constant&lt;/em&gt;. For the moment    our only use of character strings will be as arguments for &lt;tt&gt;printf&lt;/tt&gt; and    other functions. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The    sequence &lt;tt&gt;\n&lt;/tt&gt; in the string is C notation for the &lt;em&gt;newline character&lt;/em&gt;,    which when printed advances the output to the left margin on the next line.    If you leave out the &lt;tt&gt;\n&lt;/tt&gt; (a worthwhile experiment), you will find that    there is no line advance after the output is printed. You must use &lt;tt&gt;\n&lt;/tt&gt;    to include a newline character in the &lt;tt&gt;printf&lt;/tt&gt; argument; if you try something    like &lt;/span&gt; &lt;/p&gt;&lt;div align="justify"&gt;   &lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;   printf("hello, world&lt;br /&gt; ");&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;   &lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; the C compiler    will produce an error message. &lt;/span&gt;&lt;/div&gt; &lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;tt&gt;printf&lt;/tt&gt;    never supplies a newline character automatically, so several calls may be used    to build up an output line in stages. Our first program could just as well have    been written &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;  &lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;   printf("hello, ");&lt;br /&gt;   printf("world");&lt;br /&gt;   printf("\n");&lt;br /&gt; }&lt;br /&gt;&lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;  &lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; to produce identical output.    &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;Notice that &lt;tt&gt;\n&lt;/tt&gt; represents only a single character.    An &lt;em&gt;escape sequence&lt;/em&gt; like &lt;tt&gt;\n&lt;/tt&gt; provides a general and extensible    mechanism for representing hard-to-type or invisible characters. Among the others    that C provides are &lt;tt&gt;\t&lt;/tt&gt; for tab, &lt;tt&gt;\b&lt;/tt&gt; for backspace, &lt;tt&gt;\"&lt;/tt&gt;    for the double quote and &lt;tt&gt;\\&lt;/tt&gt; for the backslash itself. There is a complete    list in Section 2.3.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercise 1-1.&lt;/strong&gt; Run the ``&lt;tt&gt;hello, world&lt;/tt&gt;''    program on your system. Experiment with leaving out parts of the program, to    see what error messages you get.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercise 1-2.&lt;/strong&gt; Experiment to find out what    happens when &lt;tt&gt;prints&lt;/tt&gt;'s argument string contains &lt;em&gt;\c&lt;/em&gt;, where &lt;em&gt;c&lt;/em&gt;    is some character not listed above.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;h2 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/h2&gt; &lt;h2 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Variable and Arithmetic&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt; &lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The next program uses the formula &lt;sup&gt;o&lt;/sup&gt;C=(5/9)(&lt;sup&gt;o&lt;/sup&gt;F-32)    to print the following table of Fahrenheit temperatures and their centigrade    or Celsius equivalents:    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   1    -17&lt;br /&gt; 20   -6&lt;br /&gt; 40   4&lt;br /&gt; 60   15&lt;br /&gt; 80   26&lt;br /&gt; 100  37&lt;br /&gt; 120  48&lt;br /&gt; 140  60&lt;br /&gt; 160  71&lt;br /&gt; 180  82&lt;br /&gt; 200  93&lt;br /&gt; 220  104&lt;br /&gt; 240  115&lt;br /&gt; 260  126&lt;br /&gt; 280  137&lt;br /&gt; 300  148&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The program itself still consists of the definition of a single function named    &lt;tt&gt;main&lt;/tt&gt;. It is longer than the one that printed ``&lt;tt&gt;hello, world&lt;/tt&gt;'',    but not complicated. It introduces several new ideas, including comments, declarations,    variables, arithmetic expressions, loops , and formatted output.    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; /* print Fahrenheit-Celsius table&lt;br /&gt;     for fahr = 0, 20, ..., 300 */&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;   int fahr, celsius;&lt;br /&gt;   int lower, upper, step;&lt;br /&gt;&lt;br /&gt;   lower = 0;      /* lower limit of temperature scale */&lt;br /&gt;   upper = 300;    /* upper limit */&lt;br /&gt;   step = 20;      /* step size */&lt;br /&gt;&lt;br /&gt;   fahr = lower;&lt;br /&gt;   while (fahr &lt;= upper) {         celsius = 5 * (fahr-32) / 9;         printf("%d\t%d\n", fahr, celsius);         fahr = fahr + step;     }   } &lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The two lines    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  /* print Fahrenheit-Celsius table&lt;br /&gt;    for fahr = 0, 20, ..., 300 */&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  are a &lt;em&gt;comment&lt;/em&gt;, which in this case explains briefly what the program    does. Any characters between &lt;tt&gt;/*&lt;/tt&gt; and &lt;tt&gt;*/&lt;/tt&gt; are ignored by the    compiler; they may be used freely to make a program easier to understand. Comments    may appear anywhere where a blank, tab or newline can. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;In C, all variables must be declared before they are used,    usually at the beginning of the function before any executable statements. A    &lt;em&gt;declaration&lt;/em&gt; announces the properties of variables; it consists of a    name and a list of variables, such as  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    int fahr, celsius;&lt;br /&gt;  int lower, upper, step;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The type &lt;tt&gt;int&lt;/tt&gt; means that the variables listed are integers; by contrast    with &lt;tt&gt;float&lt;/tt&gt;, which means floating point, i.e., numbers that may have    a fractional part. The range of both &lt;tt&gt;int&lt;/tt&gt; and &lt;tt&gt;float&lt;/tt&gt; depends    on the machine you are using; 16-bits &lt;tt&gt;int&lt;/tt&gt;s, which lie between -32768    and +32767, are common, as are 32-bit &lt;tt&gt;int&lt;/tt&gt;s. A &lt;tt&gt;float&lt;/tt&gt; number    is typically a 32-bit quantity, with at least six significant digits and magnitude    generally between about 10&lt;sup&gt;-38&lt;/sup&gt; and 10&lt;sup&gt;38&lt;/sup&gt;. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;C provides several other data types besides &lt;tt&gt;int&lt;/tt&gt; and    &lt;tt&gt;float&lt;/tt&gt;, including: &lt;/span&gt;&lt;/span&gt;  &lt;/p&gt;&lt;p align="justify"&gt;  &lt;/p&gt;&lt;div align="justify"&gt;   &lt;table align="center" border="1"&gt;     &lt;tbody&gt;       &lt;tr&gt;          &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; &lt;tt&gt;char&lt;/tt&gt;             &lt;/span&gt;&lt;/td&gt;         &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; character            - a single byte&lt;/span&gt;&lt;/td&gt;       &lt;/tr&gt;&lt;tr&gt;          &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; &lt;tt&gt;short&lt;/tt&gt;             &lt;/span&gt;&lt;/td&gt;         &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; short            integer&lt;/span&gt;&lt;/td&gt;       &lt;/tr&gt;&lt;tr&gt;          &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; &lt;tt&gt;long&lt;/tt&gt;             &lt;/span&gt;&lt;/td&gt;         &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; long            integer&lt;/span&gt;&lt;/td&gt;       &lt;/tr&gt;&lt;tr&gt;          &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; &lt;tt&gt;double&lt;/tt&gt; &lt;/span&gt;&lt;/td&gt;         &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; double-precision            floating point &lt;/span&gt;&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;   &lt;/table&gt; &lt;/div&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The    size of these objects is also machine-dependent. There are also &lt;em&gt;arrays&lt;/em&gt;,    &lt;em&gt;structures&lt;/em&gt; and &lt;em&gt;unions&lt;/em&gt; of these basic types, &lt;em&gt;pointers&lt;/em&gt;    to them, and &lt;em&gt;functions&lt;/em&gt; that return them, all of which we will meet    in due course. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Computation    in the temperature conversion program begins with the &lt;em&gt;assignment statements&lt;/em&gt;    &lt;/span&gt; &lt;/p&gt;&lt;div align="justify"&gt;   &lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;    lower = 0;&lt;br /&gt;  upper = 300;&lt;br /&gt;  step = 20;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;   &lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;which set the variables    to their initial values. Individual statements are terminated by semicolons.    &lt;/span&gt; &lt;/div&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Each    line of the table is computed the same way, so we use a loop that repeats once    per output line; this is the purpose of the &lt;tt&gt;while&lt;/tt&gt; loop &lt;/span&gt; &lt;/p&gt;&lt;div align="justify"&gt;   &lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;    while (fahr &lt;= upper) {       ...    } &lt;/span&gt;&lt;/pre&gt;   &lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; The &lt;tt&gt;while&lt;/tt&gt;    loop operates as follows: The condition in parentheses is tested. If it is true    (&lt;tt&gt;fahr&lt;/tt&gt; is less than or equal to &lt;tt&gt;upper&lt;/tt&gt;), the body of the loop    (the three statements enclosed in braces) is executed. Then the condition is    re-tested, and if true, the body is executed again. When the test becomes false    (&lt;tt&gt;fahr&lt;/tt&gt; exceeds &lt;tt&gt;upper&lt;/tt&gt;) the loop ends, and execution continues    at the statement that follows the loop. There are no further statements in this    program, so it terminates. &lt;/span&gt;&lt;/div&gt; &lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The body    of a &lt;tt&gt;while&lt;/tt&gt; can be one or more statements enclosed in braces, as in    the temperature converter, or a single statement without braces, as in &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;  &lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   while (i &lt; i =" 2"&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;  &lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; In either case, we will    always indent the statements controlled by the &lt;tt&gt;while&lt;/tt&gt; by one tab stop    (which we have shown as four spaces) so you can see at a glance which statements    are inside the loop. The indentation emphasizes the logical structure of the    program. Although C compilers do not care about how a program looks, proper    indentation and spacing are critical in making programs easy for people to read.    We recommend writing only one statement per line, and using blanks around operators    to clarify grouping. The position of braces is less important, although people    hold passionate beliefs. We have chosen one of several popular styles. Pick    a style that suits you, then use it consistently. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;Most of the work gets done in the body of the loop. The Celsius    temperature is computed and assigned to the variable &lt;tt&gt;celsius&lt;/tt&gt; by the    statement  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;        celsius = 5 * (fahr-32) / 9;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The reason for multiplying by 5 and dividing by 9 instead of just multiplying    by &lt;tt&gt;5/9&lt;/tt&gt; is that in C, as in many other languages, integer division &lt;em&gt;truncates&lt;/em&gt;:    any fractional part is discarded. Since &lt;tt&gt;5&lt;/tt&gt; and &lt;tt&gt;9&lt;/tt&gt; are integers.    &lt;tt&gt;5/9&lt;/tt&gt; would be truncated to zero and so all the Celsius temperatures    would be reported as zero. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;This example also shows a bit more of how &lt;tt&gt;printf&lt;/tt&gt; works.    &lt;tt&gt;printf&lt;/tt&gt; is a general-purpose output formatting function, which we will    describe in detail in Chapter 7. Its first argument is a string of characters    to be printed, with each &lt;tt&gt;%&lt;/tt&gt; indicating where one of the other (second,    third, ...) arguments is to be substituted, and in what form it is to be printed.    For instance, &lt;tt&gt;%d&lt;/tt&gt; specifies an integer argument, so the statement  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;        printf("%d\t%d\n", fahr, celsius);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  causes the values of the two integers &lt;tt&gt;fahr&lt;/tt&gt; and &lt;tt&gt;celsius&lt;/tt&gt; to    be printed, with a tab (&lt;tt&gt;\t&lt;/tt&gt;) between them. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;Each &lt;tt&gt;%&lt;/tt&gt; construction in the first argument of &lt;tt&gt;printf&lt;/tt&gt;    is paired with the corresponding second argument, third argument, etc.; they    must match up properly by number and type, or you will get wrong answers.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;By the way, &lt;tt&gt;printf&lt;/tt&gt; is not part of the C language;    there is no input or output defined in C itself. &lt;tt&gt;printf&lt;/tt&gt; is just a useful    function from the standard library of functions that are normally accessible    to C programs. The behaviour of &lt;tt&gt;printf&lt;/tt&gt; is defined in the ANSI standard,    however, so its properties should be the same with any compiler and library    that conforms to the standard.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;In order to concentrate on C itself, we don't talk much about    input and output until chapter 7. In particular, we will defer formatted input    until then. If you have to input numbers, read the discussion of the function    &lt;tt&gt;scanf&lt;/tt&gt; in Section 7.4. &lt;tt&gt;scanf&lt;/tt&gt; is like &lt;tt&gt;printf&lt;/tt&gt;, except    that it reads input instead of writing output.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;There are a couple of problems with the temperature conversion    program. The simpler one is that the output isn't very pretty because the numbers    are not right-justified. That's easy to fix; if we augment each &lt;tt&gt;%d&lt;/tt&gt;    in the &lt;tt&gt;printf&lt;/tt&gt; statement with a width, the numbers printed will be right-justified    in their fields. For instance, we might say  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   printf("%3d %6d\n", fahr, celsius);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  to print the first number of each line in a field three digits wide, and the    second in a field six digits wide, like this:    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;     0     -17&lt;br /&gt;  20      -6&lt;br /&gt;  40       4&lt;br /&gt;  60      15&lt;br /&gt;  80      26&lt;br /&gt; 100      37&lt;br /&gt; ...&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The more serious problem is that because we have used integer arithmetic, the    Celsius temperatures are not very accurate; for instance, 0&lt;sup&gt;o&lt;/sup&gt;F is    actually about -17.8&lt;sup&gt;o&lt;/sup&gt;C, not -17. To get more accurate answers, we    should use floating-point arithmetic instead of integer. This requires some    changes in the program. Here is the second version:    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; /* print Fahrenheit-Celsius table&lt;br /&gt;     for fahr = 0, 20, ..., 300; floating-point version */&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;   float fahr, celsius;&lt;br /&gt;   float lower, upper, step;&lt;br /&gt;&lt;br /&gt;   lower = 0;      /* lower limit of temperatuire scale */&lt;br /&gt;   upper = 300;    /* upper limit */&lt;br /&gt;   step = 20;      /* step size */&lt;br /&gt;&lt;br /&gt;   fahr = lower;&lt;br /&gt;   while (fahr &lt;= upper) {         celsius = (5.0/9.0) * (fahr-32.0);         printf("%3.0f %6.1f\n", fahr, celsius);         fahr = fahr + step;     }   } &lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  This is much the same as before, except that &lt;tt&gt;fahr&lt;/tt&gt; and &lt;tt&gt;celsius&lt;/tt&gt;    are declared to be &lt;tt&gt;float&lt;/tt&gt; and the formula for conversion is written    in a more natural way. We were unable to use &lt;tt&gt;5/9&lt;/tt&gt; in the previous version    because integer division would truncate it to zero. A decimal point in a constant    indicates that it is floating point, however, so &lt;tt&gt;5.0/9.0&lt;/tt&gt; is not truncated    because it is the ratio of two floating-point values. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;If an arithmetic operator has integer operands, an integer    operation is performed. If an arithmetic operator has one floating-point operand    and one integer operand, however, the integer will be converted to floating    point before the operation is done. If we had written &lt;tt&gt;(fahr-32)&lt;/tt&gt;, the    &lt;tt&gt;32&lt;/tt&gt; would be automatically converted to floating point. Nevertheless,    writing floating-point constants with explicit decimal points even when they    have integral values emphasizes their floating-point nature for human readers.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The detailed rules for when integers are converted to floating    point are in Chapter 2. For now, notice that the assignment  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   fahr = lower;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  and the test    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   while (fahr &lt;= upper) &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  also work in the natural way - the &lt;tt&gt;int&lt;/tt&gt; is converted to &lt;tt&gt;float&lt;/tt&gt;    before the operation is done. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The &lt;tt&gt;printf&lt;/tt&gt; conversion specification &lt;tt&gt;%3.0f&lt;/tt&gt;    says that a floating-point number (here &lt;tt&gt;fahr&lt;/tt&gt;) is to be printed at least    three characters wide, with no decimal point and no fraction digits. &lt;tt&gt;%6.1f&lt;/tt&gt;    describes another number (&lt;tt&gt;celsius&lt;/tt&gt;) that is to be printed at least six    characters wide, with 1 digit after the decimal point. The output looks like    this:  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;     0   -17.8&lt;br /&gt;  20    -6.7&lt;br /&gt;  40     4.4&lt;br /&gt; ...&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  Width and precision may be omitted from a specification: &lt;tt&gt;%6f&lt;/tt&gt; says that    the number is to be at least six characters wide; &lt;tt&gt;%.2f&lt;/tt&gt; specifies two    characters after the decimal point, but the width is not constrained; and &lt;tt&gt;%f&lt;/tt&gt;    merely says to print the number as floating point. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;   &lt;p align="justify"&gt;  &lt;/p&gt;&lt;div align="justify"&gt;   &lt;table align="center" border="1"&gt;     &lt;tbody&gt;       &lt;tr&gt;          &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; &lt;tt&gt;%d&lt;/tt&gt;            &lt;/span&gt;&lt;/td&gt;         &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; print            as decimal integer&lt;/span&gt;&lt;/td&gt;       &lt;/tr&gt;&lt;tr&gt;          &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; &lt;tt&gt;%6d&lt;/tt&gt;            &lt;/span&gt;&lt;/td&gt;         &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; print            as decimal integer, at least 6 characters wide&lt;/span&gt;&lt;/td&gt;       &lt;/tr&gt;&lt;tr&gt;          &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; &lt;tt&gt;%f&lt;/tt&gt;            &lt;/span&gt;&lt;/td&gt;         &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; print            as floating point&lt;/span&gt;&lt;/td&gt;       &lt;/tr&gt;&lt;tr&gt;          &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; &lt;tt&gt;%6f&lt;/tt&gt;            &lt;/span&gt;&lt;/td&gt;         &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; print            as floating point, at least 6 characters wide&lt;/span&gt;&lt;/td&gt;       &lt;/tr&gt;&lt;tr&gt;          &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; &lt;tt&gt;%.2f&lt;/tt&gt;            &lt;/span&gt;&lt;/td&gt;         &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; print            as floating point, 2 characters after decimal point&lt;/span&gt;&lt;/td&gt;       &lt;/tr&gt;&lt;tr&gt;          &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; &lt;tt&gt;%6.2f&lt;/tt&gt;  &lt;/span&gt;&lt;/td&gt;         &lt;td&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; print            as floating point, at least 6 wide and 2 after decimal point &lt;/span&gt;&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;   &lt;/table&gt; &lt;/div&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Among    others, &lt;tt&gt;printf&lt;/tt&gt; also recognizes &lt;tt&gt;%o&lt;/tt&gt; for octal, &lt;tt&gt;%x&lt;/tt&gt; for    hexadecimal, &lt;tt&gt;%c&lt;/tt&gt; for character, &lt;tt&gt;%s&lt;/tt&gt; for character string and    &lt;tt&gt;%%&lt;/tt&gt; for itself. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;strong&gt;Exercise    1-3.&lt;/strong&gt; Modify the temperature conversion program to print a heading above    the table. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;strong&gt;Exercise    1-4.&lt;/strong&gt; Write a program to print the corresponding Celsius to Fahrenheit    table. &lt;/span&gt; &lt;/p&gt;&lt;h2 align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="s1.3"&gt;1.3    The for statement&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt; &lt;div align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;There    are plenty of different ways to write a program for a particular task. Let's    try a variation on the temperature converter. &lt;/span&gt;    &lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; /* print Fahrenheit-Celsius table */&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;     int fahr;&lt;br /&gt;&lt;br /&gt;     for (fahr = 0; fahr &lt;= 300; fahr = fahr + 20)           printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));   } &lt;/stdio.h&gt;&lt;/span&gt;&lt;/pre&gt;   &lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; This produces the    same answers, but it certainly looks different. One major change is the elimination    of most of the variables; only &lt;tt&gt;fahr&lt;/tt&gt; remains, and we have made it an    &lt;tt&gt;int&lt;/tt&gt;. The lower and upper limits and the step size appear only as constants    in the &lt;tt&gt;for&lt;/tt&gt; statement, itself a new construction, and the expression    that computes the Celsius temperature now appears as the third argument of &lt;tt&gt;printf&lt;/tt&gt;    instead of a separate assignment statement. &lt;/span&gt;&lt;/div&gt; &lt;span style="font-size:85%;"&gt;  &lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;This last    change is an instance of a general rule - in any context where it is permissible    to use the value of some type, you can use a more complicated expression of    that type. Since the third argument of &lt;tt&gt;printf&lt;/tt&gt; must be a floating-point    value to match the &lt;tt&gt;%6.1f&lt;/tt&gt;, any floating-point expression can occur here.    &lt;/span&gt;  &lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The &lt;tt&gt;for&lt;/tt&gt;    statement is a loop, a generalization of the &lt;tt&gt;while&lt;/tt&gt;. If you compare    it to the earlier &lt;tt&gt;while&lt;/tt&gt;, its operation should be clear. Within the    parentheses, there are three parts, separated by semicolons. The first part,    the initialization &lt;/span&gt;  &lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;    &lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   fahr = 0&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;  &lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; is done once, before the    loop proper is entered. The second part is the test or condition that controls    the loop: &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   fahr &lt;= 300 &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  This condition is evaluated; if it is true, the body of the loop (here a single    &lt;tt&gt;ptintf&lt;/tt&gt;) is executed. Then the increment step    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   fahr = fahr + 20&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  is executed, and the condition re-evaluated. The loop terminates if the condition    has become false. As with the &lt;tt&gt;while&lt;/tt&gt;, the body of the loop can be a    single statement or a group of statements enclosed in braces. The initialization,    condition and increment can be any expressions. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The choice between &lt;tt&gt;while&lt;/tt&gt; and &lt;tt&gt;for&lt;/tt&gt; is arbitrary,    based on which seems clearer. The &lt;tt&gt;for&lt;/tt&gt; is usually appropriate for loops    in which the initialization and increment are single statements and logically    related, since it is more compact than &lt;tt&gt;while&lt;/tt&gt; and it keeps the loop    control statements together in one place.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercise 1-5.&lt;/strong&gt; Modify the temperature conversion    program to print the table in reverse order, that is, from 300 degrees to 0.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;h2 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/h2&gt; &lt;h2 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Symbolic Constants&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt; &lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;A final observation before we leave temperature conversion    forever. It's bad practice to bury ``magic numbers'' like 300 and 20 in a program;    they convey little information to someone who might have to read the program    later, and they are hard to change in a systematic way. One way to deal with    magic numbers is to give them meaningful names. A &lt;tt&gt;#define&lt;/tt&gt; line defines    a &lt;em&gt;symbolic name or symbolic constant&lt;/em&gt; to be a particular string of characters:  &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;tt&gt;#define&lt;/tt&gt; &lt;em&gt;name replacement list&lt;/em&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;Thereafter, any occurrence of &lt;em&gt;name&lt;/em&gt; (not in quotes    and not part of another name) will be replaced by the corresponding &lt;em&gt;replacement    text&lt;/em&gt;. The &lt;em&gt;name&lt;/em&gt; has the same form as a variable name: a sequence    of letters and digits that begins with a letter. The &lt;em&gt;replacement text&lt;/em&gt;    can be any sequence of characters; it is not limited to numbers.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; #define LOWER  0     /* lower limit of table */&lt;br /&gt; #define UPPER  300   /* upper limit */&lt;br /&gt; #define STEP   20    /* step size */&lt;br /&gt;&lt;br /&gt; /* print Fahrenheit-Celsius table */&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;     int fahr;&lt;br /&gt;&lt;br /&gt;     for (fahr = LOWER; fahr &lt;= UPPER; fahr = fahr + STEP)           printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));   } &lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The quantities &lt;tt&gt;LOWER&lt;/tt&gt;, &lt;tt&gt;UPPER&lt;/tt&gt; and &lt;tt&gt;STEP&lt;/tt&gt; are symbolic    constants, not variables, so they do not appear in declarations. Symbolic constant    names are conventionally written in upper case so they can ber readily distinguished    from lower case variable names. Notice that there is no semicolon at the end    of a &lt;tt&gt;#define&lt;/tt&gt; line. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;h2 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/h2&gt; &lt;h2 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Character Input and Output&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt; &lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;We are going to consider a family of related programs for    processing character data. You will find that many programs are just expanded    versions of the prototypes that we discuss here. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The model of input and output supported by the standard library    is very simple. Text input or output, regardless of where it originates or where    it goes to, is dealt with as streams of characters. A &lt;em&gt;text stream&lt;/em&gt; is    a sequence of characters divided into lines; each line consists of zero or more    characters followed by a newline character. It is the responsibility of the    library to make each input or output stream confirm this model; the C programmer    using the library need not worry about how lines are represented outside the    program.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The standard library provides several functions for reading    or writing one character at a time, of which &lt;tt&gt;getchar&lt;/tt&gt; and &lt;tt&gt;putchar&lt;/tt&gt;    are the simplest. Each time it is called, &lt;tt&gt;getchar&lt;/tt&gt; reads the &lt;em&gt;next    input character&lt;/em&gt; from a text stream and returns that as its value. That    is, after  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   c = getchar();&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  the variable &lt;tt&gt;c&lt;/tt&gt; contains the next character of input. The characters    normally come from the keyboard; input from files is discussed in Chapter 7.  &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The function &lt;tt&gt;putchar&lt;/tt&gt; prints a character each time    it is called:  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   putchar(c);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  prints the contents of the integer variable &lt;tt&gt;c&lt;/tt&gt; as a character, usually    on the screen. Calls to &lt;tt&gt;putchar&lt;/tt&gt; and &lt;tt&gt;printf&lt;/tt&gt; may be interleaved;    the output will appear in the order in which the calls are made. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;h3 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/h3&gt; &lt;h3 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;1.5.1 File Copying&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;   &lt;div align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Given    getchar and putchar, you can write a surprising amount of useful code without    knowing anything more about input and output. The simplest example is a program    that copies its input to its output one character at a time: &lt;/span&gt; &lt;/div&gt;  &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;em&gt;read a character&lt;/em&gt;&lt;br /&gt;  while (&lt;em&gt;charater is not end-of-file indicator&lt;/em&gt;)&lt;br /&gt;      &lt;em&gt;output the character just read&lt;br /&gt;      read a character&lt;/em&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  Converting this into C gives:    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; /* copy input to output; 1st version  */&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;     int c;&lt;br /&gt;&lt;br /&gt;     c = getchar();&lt;br /&gt;     while (c != EOF) {&lt;br /&gt;         putchar(c);&lt;br /&gt;         c = getchar();&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The relational operator &lt;tt&gt;!=&lt;/tt&gt; means ``not equal to''. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;What appears to be a character on the keyboard or screen is    of course, like everything else, stored internally just as a bit pattern. The    type &lt;tt&gt;char&lt;/tt&gt; is specifically meant for storing such character data, but    any integer type can be used. We used &lt;tt&gt;int&lt;/tt&gt; for a subtle but important    reason.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The problem is distinguishing the end of input from valid data.    The solution is that &lt;tt&gt;getchar&lt;/tt&gt; returns a distinctive value when there    is no more input, a value that cannot be confused with any real character. This    value is called &lt;tt&gt;EOF&lt;/tt&gt;, for ``end of file''. We must declare &lt;tt&gt;c&lt;/tt&gt;    to be a type big enough to hold any value that &lt;tt&gt;getchar&lt;/tt&gt; returns. We    can't use &lt;tt&gt;char&lt;/tt&gt; since &lt;tt&gt;c&lt;/tt&gt; must be big enough to hold &lt;tt&gt;EOF&lt;/tt&gt;    in addition to any possible &lt;tt&gt;char&lt;/tt&gt;. Therefore we use &lt;tt&gt;int&lt;/tt&gt;.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;tt&gt;EOF&lt;/tt&gt; is an integer defined in &lt;stdio.h&gt;, but    the specific numeric value doesn't matter as long as it is not the same as any    &lt;tt&gt;char&lt;/tt&gt; value. By using the symbolic constant, we are assured that nothing    in the program depends on the specific numeric value.  &lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The program for copying would be written more concisely by    experienced C programmers. In C, any assignment, such as  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   c = getchar();&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  is an expression and has a value, which is the value of the left hand side after    the assignment. This means that a assignment can appear as part of a larger    expression. If the assignment of a character to &lt;tt&gt;c&lt;/tt&gt; is put inside the    test part of a &lt;tt&gt;while&lt;/tt&gt; loop, the copy program can be written this way:    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; /* copy input to output; 2nd version  */&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;     int c;&lt;br /&gt;&lt;br /&gt;     while ((c = getchar()) != EOF)&lt;br /&gt;         putchar(c);&lt;br /&gt; }&lt;br /&gt;&lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The &lt;tt&gt;while&lt;/tt&gt; gets a character, assigns it to &lt;tt&gt;c&lt;/tt&gt;, and then tests    whether the character was the end-of-file signal. If it was not, the body of    the &lt;tt&gt;while&lt;/tt&gt; is executed, printing the character. The &lt;tt&gt;while&lt;/tt&gt; then    repeats. When the end of the input is finally reached, the &lt;tt&gt;while&lt;/tt&gt; terminates    and so does &lt;tt&gt;main&lt;/tt&gt;. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;This version centralizes the input - there is now only one    reference to &lt;tt&gt;getchar&lt;/tt&gt; - and shrinks the program. The resulting program    is more compact, and, once the idiom is mastered, easier to read. You'll see    this style often. (It's possible to get carried away and create impenetrable    code, however, a tendency that we will try to curb.)  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The parentheses around the assignment, within the condition    are necessary. The &lt;em&gt;precedence&lt;/em&gt; of &lt;tt&gt;!=&lt;/tt&gt; is higher than that of    &lt;tt&gt;=&lt;/tt&gt;, which means that in the absence of parentheses the relational test    &lt;tt&gt;!=&lt;/tt&gt; would be done before the assignment &lt;tt&gt;=&lt;/tt&gt;. So the statement  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   c = getchar() != EOF&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  is equivalent to    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   c = (getchar() != EOF)&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  This has the undesired effect of setting &lt;tt&gt;c&lt;/tt&gt; to 0 or 1, depending on    whether or not the call of &lt;tt&gt;getchar&lt;/tt&gt; returned end of file. (More on this    in Chapter 2.) &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercsise 1-6.&lt;/strong&gt; Verify that the expression    &lt;tt&gt;getchar() != EOF&lt;/tt&gt; is 0 or 1.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercise 1-7.&lt;/strong&gt; Write a program to print the    value of &lt;tt&gt;EOF&lt;/tt&gt;.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;h3 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/h3&gt; &lt;h3 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;1.5.2 Character Counting&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt; &lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The next program counts characters; it is similar to the    copy program.    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; /* count characters in input; 1st version */&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;     long nc;&lt;br /&gt;&lt;br /&gt;     nc = 0;&lt;br /&gt;     while (getchar() != EOF)&lt;br /&gt;         ++nc;&lt;br /&gt;     printf("%ld\n", nc);&lt;br /&gt; }&lt;br /&gt;&lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The statement    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   ++nc;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  presents a new operator, &lt;tt&gt;++&lt;/tt&gt;, which means &lt;em&gt;increment by one&lt;/em&gt;.    You could instead write &lt;tt&gt;nc = nc + 1&lt;/tt&gt; but &lt;tt&gt;++nc&lt;/tt&gt; is more concise    and often more efficient. There is a corresponding operator &lt;tt&gt;--&lt;/tt&gt; to decrement    by 1. The operators &lt;tt&gt;++&lt;/tt&gt; and &lt;tt&gt;--&lt;/tt&gt; can be either prefix operators    (&lt;tt&gt;++nc&lt;/tt&gt;) or postfix operators (&lt;tt&gt;nc++&lt;/tt&gt;); these two forms have different    values in expressions, as will be shown in Chapter 2, but &lt;tt&gt;++nc&lt;/tt&gt; and    &lt;tt&gt;nc++&lt;/tt&gt; both increment &lt;tt&gt;nc&lt;/tt&gt;. For the moment we will will stick    to the prefix form. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The character counting program accumulates its count in a &lt;tt&gt;long&lt;/tt&gt;    variable instead of an int. &lt;tt&gt;long&lt;/tt&gt; integers are at least 32 bits. Although    on some machines, &lt;tt&gt;int&lt;/tt&gt; and &lt;tt&gt;long&lt;/tt&gt; are the same size, on others    an &lt;tt&gt;int&lt;/tt&gt; is 16 bits, with a maximum value of 32767, and it would take    relatively little input to overflow an &lt;tt&gt;int&lt;/tt&gt; counter. The conversion    specification &lt;tt&gt;%ld&lt;/tt&gt; tells &lt;tt&gt;printf&lt;/tt&gt; that the corresponding argument    is a &lt;tt&gt;long&lt;/tt&gt; integer.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;It may be possible to cope with even bigger numbers by using    a &lt;tt&gt;double&lt;/tt&gt; (double precision &lt;tt&gt;float&lt;/tt&gt;). We will also use a &lt;tt&gt;for&lt;/tt&gt;    statement instead of a &lt;tt&gt;while&lt;/tt&gt;, to illustrate another way to write the    loop.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; /* count characters in input; 2nd version */&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;     double nc;&lt;br /&gt;&lt;br /&gt;     for (nc = 0; gechar() != EOF; ++nc)&lt;br /&gt;         ;&lt;br /&gt;     printf("%.0f\n", nc);&lt;br /&gt; }&lt;br /&gt;&lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;tt&gt;printf&lt;/tt&gt; uses &lt;tt&gt;%f&lt;/tt&gt; for both &lt;tt&gt;float&lt;/tt&gt; and &lt;tt&gt;double&lt;/tt&gt;;    &lt;tt&gt;%.0f&lt;/tt&gt; suppresses the printing of the decimal point and the fraction    part, which is zero. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The body of this &lt;tt&gt;for&lt;/tt&gt; loop is empty, because all the    work is done in the test and increment parts. But the grammatical rules of C    require that a &lt;tt&gt;for&lt;/tt&gt; statement have a body. The isolated semicolon, called    a &lt;em&gt;null statement&lt;/em&gt;, is there to satisfy that requirement. We put it on    a separate line to make it visible.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;Before we leave the character counting program, observe that    if the input contains no characters, the &lt;tt&gt;while&lt;/tt&gt; or &lt;tt&gt;for&lt;/tt&gt; test    fails on the very first call to &lt;tt&gt;getchar&lt;/tt&gt;, and the program produces zero,    the right answer. This is important. One of the nice things about &lt;tt&gt;while&lt;/tt&gt;    and &lt;tt&gt;for&lt;/tt&gt; is that they test at the top of the loop, before proceeding    with the body. If there is nothing to do, nothing is done, even if that means    never going through the loop body. Programs should act intelligently when given    zero-length input. The &lt;tt&gt;while&lt;/tt&gt; and &lt;tt&gt;for&lt;/tt&gt; statements help ensure    that programs do reasonable things with boundary conditions.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;h3 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/h3&gt; &lt;h3 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;1.5.3 Line Counting&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt; &lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The next program counts input lines. As we mentioned above,    the standard library ensures that an input text stream appears as a sequence    of lines, each terminated by a newline. Hence, counting lines is just counting    newlines:    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; /* count lines in input */&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;     int c, nl;&lt;br /&gt;&lt;br /&gt;     nl = 0;&lt;br /&gt;     while ((c = getchar()) != EOF)&lt;br /&gt;         if (c == '\n')&lt;br /&gt;             ++nl;&lt;br /&gt;     printf("%d\n", nl);&lt;br /&gt; }&lt;br /&gt;&lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The body of the &lt;tt&gt;while&lt;/tt&gt; now consists of an &lt;tt&gt;if&lt;/tt&gt;, which in turn    controls the increment &lt;tt&gt;++nl&lt;/tt&gt;. The &lt;tt&gt;if&lt;/tt&gt; statement tests the parenthesized    condition, and if the condition is true, executes the statement (or group of    statements in braces) that follows. We have again indented to show what is controlled    by what. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The double equals sign &lt;tt&gt;==&lt;/tt&gt; is the C notation for ``is    equal to'' (like Pascal's single &lt;tt&gt;=&lt;/tt&gt; or Fortran's &lt;tt&gt;.EQ.&lt;/tt&gt;). This    symbol is used to distinguish the equality test from the single &lt;tt&gt;=&lt;/tt&gt; that    C uses for assignment. A word of caution: newcomers to C occasionally write    &lt;tt&gt;=&lt;/tt&gt; when they mean &lt;tt&gt;==&lt;/tt&gt;. As we will see in Chapter 2, the result    is usually a legal expression, so you will get no warning.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;A character written between single quotes represents an integer    value equal to the numerical value of the character in the machine's character    set. This is called a &lt;em&gt;character constant&lt;/em&gt;, although it is just another    way to write a small integer. So, for example, &lt;tt&gt;'A'&lt;/tt&gt; is a character constant;    in the ASCII character set its value is 65, the internal representation of the    character &lt;tt&gt;A&lt;/tt&gt;. Of course, &lt;tt&gt;'A'&lt;/tt&gt; is to be preferred over &lt;tt&gt;65&lt;/tt&gt;:    its meaning is obvious, and it is independent of a particular character set.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The escape sequences used in string constants are also legal    in character constants, so &lt;tt&gt;'\n'&lt;/tt&gt; stands for the value of the newline    character, which is 10 in ASCII. You should note carefully that &lt;tt&gt;'\n'&lt;/tt&gt;    is a single character, and in expressions is just an integer; on the other hand,    &lt;tt&gt;'\n'&lt;/tt&gt; is a string constant that happens to contain only one character.    The topic of strings versus characters is discussed further in Chapter 2.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercise 1-8.&lt;/strong&gt; Write a program to count blanks,    tabs, and newlines.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercise 1-9.&lt;/strong&gt; Write a program to copy its    input to its output, replacing each string of one or more blanks by a single    blank.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercise 1-10.&lt;/strong&gt; Write a program to copy its    input to its output, replacing each tab by &lt;tt&gt;\t&lt;/tt&gt;, each backspace by &lt;tt&gt;\b&lt;/tt&gt;,    and each backslash by &lt;tt&gt;\\&lt;/tt&gt;. This makes tabs and backspaces visible in    an unambiguous way.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;h3 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/h3&gt; &lt;h3 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;1.5.4 Word Counting&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt; &lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The fourth in our series of useful programs counts lines,    words, and characters, with the loose definition that a word is any sequence    of characters that does not contain a blank, tab or newline. This is a bare-bones    version of the UNIX program &lt;tt&gt;wc&lt;/tt&gt;.    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; #define IN   1  /* inside a word */&lt;br /&gt; #define OUT  0  /* outside a word */&lt;br /&gt;&lt;br /&gt; /* count lines, words, and characters in input */&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;     int c, nl, nw, nc, state;&lt;br /&gt;&lt;br /&gt;     state = OUT;&lt;br /&gt;     nl = nw = nc = 0;&lt;br /&gt;     while ((c = getchar()) != EOF) {&lt;br /&gt;         ++nc;&lt;br /&gt;         if (c == '\n')&lt;br /&gt;             ++nl;&lt;br /&gt;         if (c == ' ' || c == '\n' || c = '\t')&lt;br /&gt;             state = OUT;&lt;br /&gt;         else if (state == OUT) {&lt;br /&gt;             state = IN;&lt;br /&gt;             ++nw;&lt;br /&gt;         }&lt;br /&gt;     }&lt;br /&gt;     printf("%d %d %d\n", nl, nw, nc);&lt;br /&gt; }&lt;br /&gt;&lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  Every time the program encounters the first character of a word, it counts one    more word. The variable &lt;tt&gt;state&lt;/tt&gt; records whether the program is currently    in a word or not; initially it is ``not in a word'', which is assigned the value    &lt;tt&gt;OUT&lt;/tt&gt;. We prefer the symbolic constants &lt;tt&gt;IN&lt;/tt&gt; and &lt;tt&gt;OUT&lt;/tt&gt;    to the literal values 1 and 0 because they make the program more readable. In    a program as tiny as this, it makes little difference, but in larger programs,    the increase in clarity is well worth the modest extra effort to write it this    way from the beginning. You'll also find that it's easier to make extensive    changes in programs where magic numbers appear only as symbolic constants. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The line  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   nl = nw = nc = 0;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  sets all three variables to zero. This is not a special case, but a consequence    of the fact that an assignment is an expression with the value and assignments    associated from right to left. It's as if we had written    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   nl = (nw = (nc = 0));&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The operator &lt;tt&gt;||&lt;/tt&gt; means OR, so the line    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   if (c == ' ' || c == '\n' || c = '\t')&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  says ``if &lt;tt&gt;c&lt;/tt&gt; is a blank &lt;em&gt;or&lt;/em&gt; &lt;tt&gt;c&lt;/tt&gt; is a newline &lt;em&gt;or&lt;/em&gt;    &lt;tt&gt;c&lt;/tt&gt; is a tab''. (Recall that the escape sequence &lt;tt&gt;\t&lt;/tt&gt; is a visible    representation of the tab character.) There is a corresponding operator &lt;tt&gt;&amp;amp;&amp;amp;&lt;/tt&gt;    for AND; its precedence is just higher than &lt;tt&gt;||&lt;/tt&gt;. Expressions connected    by &lt;tt&gt;&amp;amp;&amp;amp;&lt;/tt&gt; or &lt;tt&gt;||&lt;/tt&gt; are evaluated left to right, and it is    guaranteed that evaluation will stop as soon as the truth or falsehood is known.    If &lt;tt&gt;c&lt;/tt&gt; is a blank, there is no need to test whether it is a newline or    tab, so these tests are not made. This isn't particularly important here, but    is significant in more complicated situations, as we will soon see. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The example also shows an &lt;tt&gt;else&lt;/tt&gt;, which specifies an    alternative action if the condition part of an &lt;tt&gt;if&lt;/tt&gt; statement is false.    The general form is &lt;/span&gt;&lt;/span&gt;  &lt;/p&gt;&lt;div align="justify"&gt;   &lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;   if (&lt;em&gt;expression&lt;/em&gt;)&lt;br /&gt;     &lt;em&gt;statement&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;/pre&gt; &lt;/div&gt; &lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;em&gt;&lt;sub&gt;&lt;div align="justify"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;1&lt;/span&gt;&lt;/div&gt;&lt;/sub&gt;&lt;/em&gt;&lt;div align="justify"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;br /&gt; else&lt;br /&gt;     &lt;em&gt;statement&lt;/em&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;em&gt;&lt;sub&gt;&lt;div align="justify"&gt;2&lt;/div&gt;&lt;/sub&gt;&lt;/em&gt;&lt;/span&gt;&lt;/span&gt; &lt;/pre&gt; &lt;div align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;One    and only one of the two statements associated with an &lt;tt&gt;if-else&lt;/tt&gt; is performed.    If the &lt;em&gt;expression&lt;/em&gt; is true, &lt;em&gt;statement&lt;sub&gt;1&lt;/sub&gt;&lt;/em&gt; is executed;    if not, &lt;em&gt;statement&lt;sub&gt;2&lt;/sub&gt;&lt;/em&gt; is executed. Each &lt;em&gt;statement&lt;/em&gt;    can be a single statement or several in braces. In the word count program, the    one after the &lt;tt&gt;else&lt;/tt&gt; is an &lt;tt&gt;if&lt;/tt&gt; that controls two statements in    braces. &lt;/span&gt; &lt;/div&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;strong&gt;Exercise    1-11.&lt;/strong&gt; How would you test the word count program? What kinds of input    are most likely to uncover bugs if there are any? &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;strong&gt;Exercise    1-12.&lt;/strong&gt; Write a program that prints its input one word per line. &lt;/span&gt; &lt;/p&gt;&lt;h2 align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="s1.6"&gt;1.6    Arrays&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt; &lt;div align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;    Let is write a program to count the number of occurrences of each digit, of    white space characters (blank, tab, newline), and of all other characters. This    is artificial, but it permits us to illustrate several aspects of C in one program.    &lt;/span&gt;&lt;/div&gt; &lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;There are    twelve categories of input, so it is convenient to use an array to hold the    number of occurrences of each digit, rather than ten individual variables. Here    is one version of the program: &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;  &lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; /* count digits, white space, others */&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;     int c, i, nwhite, nother;&lt;br /&gt;     int ndigit[10];&lt;br /&gt;&lt;br /&gt;     nwhite = nother = 0;&lt;br /&gt;     for (i = 0; i &lt; c =" getchar())"&gt;= '0' &amp;amp;&amp;amp; c &lt;= '9')               ++ndigit[c-'0'];           else if (c == ' ' || c == '\n' || c == '\t')               ++nwhite;           else               ++nother;        printf("digits =");       for (i = 0; i &lt; space =" %d," other =" %d\n"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;  &lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; The output of this program    on itself is &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   digits = 9 3 0 0 0 0 0 0 0 1, white space = 123, other = 345&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The declaration    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   int ndigit[10];&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  declares &lt;tt&gt;ndigit&lt;/tt&gt; to be an array of 10 integers. Array subscripts always    start at zero in C, so the elements are &lt;tt&gt;ndigit[0], ndigit[1], ..., ndigit[9]&lt;/tt&gt;.    This is reflected in the &lt;tt&gt;for&lt;/tt&gt; loops that initialize and print the array.  &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;A subscript can be any integer expression, which includes integer    variables like &lt;tt&gt;i&lt;/tt&gt;, and integer constants.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;This particular program relies on the properties of the character    representation of the digits. For example, the test  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   if (c &gt;= '0' &amp;amp;&amp;amp; c &lt;= '9') &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  determines whether the character in &lt;tt&gt;c&lt;/tt&gt; is a digit. If it is, the numeric    value of that digit is    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   c - '0'&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  This works only if &lt;tt&gt;'0', '1', ..., '9'&lt;/tt&gt; have consecutive increasing values.    Fortunately, this is true for all character sets. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;By definition, &lt;tt&gt;char&lt;/tt&gt;s are just small integers, so &lt;tt&gt;char&lt;/tt&gt;    variables and constants are identical to &lt;tt&gt;int&lt;/tt&gt;s in arithmetic expressions.    This is natural and convenient; for example &lt;tt&gt;c-'0'&lt;/tt&gt; is an integer expression    with a value between 0 and 9 corresponding to the character &lt;tt&gt;'0'&lt;/tt&gt; to    &lt;tt&gt;'9'&lt;/tt&gt; stored in &lt;tt&gt;c&lt;/tt&gt;, and thus a valid subscript for the array    &lt;tt&gt;ndigit&lt;/tt&gt;.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The decision as to whether a character is a digit, white space,    or something else is made with the sequence  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   if (c &gt;= '0' &amp;amp;&amp;amp; c &lt;= '9')       ++ndigit[c-'0'];   else if (c == ' ' || c == '\n' || c == '\t')       ++nwhite;   else       ++nother; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The pattern &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;   &lt;div align="justify"&gt;   &lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;   if (&lt;em&gt;condition&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;/pre&gt; &lt;/div&gt; &lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;em&gt;&lt;sub&gt;&lt;div align="justify"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;1&lt;/span&gt;&lt;/div&gt;&lt;/sub&gt;&lt;/em&gt;&lt;div align="justify"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;)&lt;br /&gt;     &lt;em&gt;statement&lt;/em&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;em&gt;&lt;sub&gt;&lt;div align="justify"&gt;1&lt;/div&gt;&lt;/sub&gt;&lt;/em&gt;&lt;div align="justify"&gt;&lt;br /&gt; else if (&lt;em&gt;condition&lt;/em&gt;&lt;/div&gt;&lt;em&gt;&lt;sub&gt;&lt;div align="justify"&gt;2&lt;/div&gt;&lt;/sub&gt;&lt;/em&gt;&lt;div align="justify"&gt;)&lt;br /&gt;     &lt;em&gt;statement&lt;/em&gt;&lt;/div&gt;&lt;em&gt;&lt;sub&gt;&lt;div align="justify"&gt;2&lt;/div&gt;&lt;/sub&gt;&lt;/em&gt;&lt;div align="justify"&gt;&lt;br /&gt;     ...&lt;br /&gt;     ...&lt;br /&gt; else&lt;br /&gt;     &lt;em&gt;statement&lt;/em&gt;&lt;/div&gt;&lt;em&gt;&lt;sub&gt;&lt;div align="justify"&gt;n&lt;/div&gt;&lt;/sub&gt;&lt;/em&gt;&lt;/span&gt;&lt;/span&gt; &lt;/pre&gt; &lt;div align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;occurs    frequently in programs as a way to express a multi-way decision. The &lt;em&gt;conditions&lt;/em&gt;    are evaluated in order from the top until some &lt;em&gt;condition&lt;/em&gt; is satisfied;    at that point the corresponding &lt;em&gt;statement&lt;/em&gt; part is executed, and the    entire construction is finished. (Any &lt;em&gt;statement&lt;/em&gt; can be several statements    enclosed in braces.) If none of the conditions is satisfied, the &lt;em&gt;statement&lt;/em&gt;    after the final &lt;tt&gt;else&lt;/tt&gt; is executed if it is present. If the final &lt;tt&gt;else&lt;/tt&gt;    and &lt;em&gt;statement&lt;/em&gt; are omitted, as in the word count program, no action    takes place. There can be any number of &lt;/span&gt; &lt;/div&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;tt&gt;else    if&lt;/tt&gt;(&lt;em&gt;condition&lt;/em&gt;)&lt;br /&gt;   &lt;em&gt;statement&lt;/em&gt; &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;groups    between the initial &lt;tt&gt;if&lt;/tt&gt; and the final &lt;tt&gt;else&lt;/tt&gt;. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;As    a matter of style, it is advisable to format this construction as we have shown;    if each &lt;tt&gt;if&lt;/tt&gt; were indented past the previous &lt;tt&gt;else&lt;/tt&gt;, a long sequence    of decisions would march off the right side of the page. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The    &lt;tt&gt;switch&lt;/tt&gt; statement, to be discussed in Chapter 4, provides another way    to write a multi-way branch that is particulary suitable when the condition    is whether some integer or character expression matches one of a set of constants.    For contrast, we will present a &lt;tt&gt;switch&lt;/tt&gt; version of this program in Section    3.4. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;strong&gt;Exercise    1-13.&lt;/strong&gt; Write a program to print a histogram of the lengths of words    in its input. It is easy to draw the histogram with the bars horizontal; a vertical    orientation is more challenging. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;strong&gt;Exercise    1-14.&lt;/strong&gt; Write a program to print a histogram of the frequencies of different    characters in its input. &lt;/span&gt; &lt;/p&gt;&lt;h2 align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="s1.7"&gt;1.7    Functions&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt; &lt;div align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;    In C, a function is equivalent to a subroutine or function in Fortran, or a    procedure or function in Pascal. A function provides a convenient way to encapsulate    some computation, which can then be used without worrying about its implementation.    With properly designed functions, it is possible to ignore &lt;em&gt;how&lt;/em&gt; a job    is done; knowing &lt;em&gt;what&lt;/em&gt; is done is sufficient. C makes the sue of functions    easy, convinient and efficient; you will often see a short function defined    and called only once, just because it clarifies some piece of code. &lt;/span&gt;&lt;/div&gt; &lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;So far we    have used only functions like &lt;tt&gt;printf&lt;/tt&gt;, &lt;tt&gt;getchar&lt;/tt&gt; and &lt;tt&gt;putchar&lt;/tt&gt;    that have been provided for us; now it's time to write a few of our own. Since    C has no exponentiation operator like the &lt;tt&gt;**&lt;/tt&gt; of Fortran, let us illustrate    the mechanics of function definition by writing a function &lt;tt&gt;power(m,n)&lt;/tt&gt;    to raise an integer &lt;tt&gt;m&lt;/tt&gt; to a positive integer power &lt;tt&gt;n&lt;/tt&gt;. That    is, the value of &lt;tt&gt;power(2,5)&lt;/tt&gt; is 32. This function is not a practical    exponentiation routine, since it handles only positive powers of small integers,    but it's good enough for illustration.(The standard library contains a function    &lt;tt&gt;pow(x,y)&lt;/tt&gt; that computes &lt;em&gt;x&lt;sup&gt;y&lt;/sup&gt;&lt;/em&gt;.) &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;Here is    the function &lt;tt&gt;power&lt;/tt&gt; and a main program to exercise it, so you can see    the whole structure at once. &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;  &lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; int power(int m, int n);&lt;br /&gt;&lt;br /&gt;  /* test power function */&lt;br /&gt;  main()&lt;br /&gt;  {&lt;br /&gt;      int i;&lt;br /&gt;&lt;br /&gt;      for (i = 0; i &lt;&gt;= 0 */&lt;br /&gt;  int power(int base, int n)&lt;br /&gt;  {&lt;br /&gt;      int i,  p;&lt;br /&gt;&lt;br /&gt;      p = 1;&lt;br /&gt;      for (i = 1; i &lt;= n; ++i)            p = p * base;        return p;    } &lt;/stdio.h&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;  &lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; A function definition has    this form: &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;return-type function-name(parameter declarations, if any)&lt;br /&gt;{&lt;br /&gt; declarations&lt;br /&gt; statements&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  Function definitions can appear in any order, and in one source file or several,    although no function can be split between files. If the source program appears    in several files, you may have to say more to compile and load it than if it    all appears in one, but that is an operating system matter, not a language attribute.    For the moment, we will assume that both functions are in the same file, so    whatever you have learned about running C programs will still work. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The function &lt;tt&gt;power&lt;/tt&gt; is called twice by &lt;tt&gt;main&lt;/tt&gt;,    in the line  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   printf("%d %d %d\n", i, power(2,i), power(-3,i));&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  Each call passes two arguments to &lt;tt&gt;power&lt;/tt&gt;, which each time returns an    integer to be formatted and printed. In an expression, &lt;tt&gt;power(2,i)&lt;/tt&gt; is    an integer just as &lt;tt&gt;2&lt;/tt&gt; and &lt;tt&gt;i&lt;/tt&gt; are. (Not all functions produce    an integer value; we will take this up in Chapter 4.) &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The first line of &lt;tt&gt;power&lt;/tt&gt; itself,  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    int power(int base, int n)&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  declares the parameter types and names, and the type of the result that the    function returns. The names used by &lt;tt&gt;power&lt;/tt&gt; for its parameters are local    to &lt;tt&gt;power&lt;/tt&gt;, and are not visible to any other function: other routines    can use the same names without conflict. This is also true of the variables    &lt;tt&gt;i&lt;/tt&gt; and &lt;tt&gt;p&lt;/tt&gt;: the &lt;tt&gt;i&lt;/tt&gt; in &lt;tt&gt;power&lt;/tt&gt; is unrelated to    the &lt;tt&gt;i&lt;/tt&gt; in &lt;tt&gt;main&lt;/tt&gt;. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;We will generally use &lt;em&gt;parameter&lt;/em&gt; for a variable named    in the parenthesized list in a function. The terms &lt;em&gt;formal argument&lt;/em&gt;    and &lt;em&gt;actual argument&lt;/em&gt; are sometimes used for the same distinction.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The value that &lt;tt&gt;power&lt;/tt&gt; computes is returned to &lt;tt&gt;main&lt;/tt&gt;    by the &lt;tt&gt;return&lt;/tt&gt;: statement. Any expression may follow &lt;tt&gt;return&lt;/tt&gt;:  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   return &lt;em&gt;expression&lt;/em&gt;;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  A function need not return a value; a return statement with no expression causes    control, but no useful value, to be returned to the caller, as does ``falling    off the end'' of a function by reaching the terminating right brace. And the    calling function can ignore a value returned by a function. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;You may have noticed that there is a &lt;tt&gt;return&lt;/tt&gt; statement    at the end of &lt;tt&gt;main&lt;/tt&gt;. Since &lt;tt&gt;main&lt;/tt&gt; is a function like any other,    it may return a value to its caller, which is in effect the environment in which    the program was executed. Typically, a return value of zero implies normal termination;    non-zero values signal unusual or erroneous termination conditions. In the interests    of simplicity, we have omitted &lt;tt&gt;return&lt;/tt&gt; statements from our &lt;tt&gt;main&lt;/tt&gt;    functions up to this point, but we will include them hereafter, as a reminder    that programs should return status to their environment.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The declaration  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    int power(int base, int n);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  just before &lt;tt&gt;main&lt;/tt&gt; says that &lt;tt&gt;power&lt;/tt&gt; is a function that expects    two &lt;tt&gt;int&lt;/tt&gt; arguments and returns an &lt;tt&gt;int&lt;/tt&gt;. This declaration, which    is called a &lt;em&gt;function prototype&lt;/em&gt;, has to agree with the definition and    uses of &lt;tt&gt;power&lt;/tt&gt;. It is an error if the definition of a function or any    uses of it do not agree with its prototype. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;parameter names need not agree. Indeed, parameter names are    optional in a function prototype, so for the prototype we could have written  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    int power(int, int);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  Well-chosen names are good documentation however, so we will often use them.  &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;A note of history: the biggest change between ANSI C and earlier    versions is how functions are declared and defined. In the original definition    of C, the &lt;tt&gt;power&lt;/tt&gt; function would have been written like this:  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   /* power:  raise base to n-th power; n &gt;= 0 */&lt;br /&gt; /*         (old-style version) */&lt;br /&gt; power(base, n)&lt;br /&gt; int base, n;&lt;br /&gt; {&lt;br /&gt;     int i, p;&lt;br /&gt;&lt;br /&gt;     p = 1;&lt;br /&gt;     for (i = 1; i &lt;= n; ++i)           p = p * base;       return p;   } &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The parameters are named between the parentheses, and their types are declared    before opening the left brace; undeclared parameters are taken as &lt;tt&gt;int&lt;/tt&gt;.    (The body of the function is the same as before.) &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The declaration of &lt;tt&gt;power&lt;/tt&gt; at the beginning of the program    would have looked like this:  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    int power();&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  No parameter list was permitted, so the compiler could not readily check that    &lt;tt&gt;power&lt;/tt&gt; was being called correctly. Indeed, since by default &lt;tt&gt;power&lt;/tt&gt;    would have been assumed to return an &lt;tt&gt;int&lt;/tt&gt;, the entire declaration might    well have been omitted. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The new syntax of function prototypes makes it much easier    for a compiler to detect errors in the number of arguments or their types. The    old style of declaration and definition still works in ANSI C, at least for    a transition period, but we strongly recommend that you use the new form when    you have a compiler that supports it.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercise 1.15.&lt;/strong&gt; Rewrite the temperature conversion    program of Section 1.2 to use a function for conversion.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;h2 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/h2&gt; &lt;h2 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;1.8 Arguments- Call by Value&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt; &lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;One aspect of C functions may be unfamiliar to programmers    who are used to some other languages, particulary Fortran. In C, all function    arguments are passed ``by value.'' This means that the called function is given    the values of its arguments in temporary variables rather than the originals.    This leads to some different properties than are seen with ``call by reference''    languages like Fortran or with &lt;tt&gt;var&lt;/tt&gt; parameters in Pascal, in which the    called routine has access to the original argument, not a local copy. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;Call by value is an asset, however, not a liability. It usually    leads to more compact programs with fewer extraneous variables, because parameters    can be treated as conveniently initialized local variables in the called routine.    For example, here is a version of &lt;tt&gt;power&lt;/tt&gt; that makes use of this property.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   /* power:  raise base to n-th power; n &gt;= 0; version 2 */&lt;br /&gt; int power(int base, int n)&lt;br /&gt; {&lt;br /&gt;     int p;&lt;br /&gt;&lt;br /&gt;     for (p = 1; n &gt; 0; --n)&lt;br /&gt;         p = p * base;&lt;br /&gt;     return p;&lt;br /&gt; }&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The parameter &lt;tt&gt;n&lt;/tt&gt; is used as a temporary variable, and is counted down    (a &lt;tt&gt;for&lt;/tt&gt; loop that runs backwards) until it becomes zero; there is no    longer a need for the variable &lt;tt&gt;i&lt;/tt&gt;. Whatever is done to &lt;tt&gt;n&lt;/tt&gt; inside    &lt;tt&gt;power&lt;/tt&gt; has no effect on the argument that &lt;tt&gt;power&lt;/tt&gt; was originally    called with. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;When necessary, it is possible to arrange for a function to    modify a variable in a calling routine. The caller must provide the &lt;em&gt;address&lt;/em&gt;    of the variable to be set (technically a &lt;em&gt;pointer&lt;/em&gt; to the variable),    and the called function must declare the parameter to be a pointer and access    the variable indirectly through it. We will cover pointers in Chapter 5.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The story is different for arrays. When the name of an array    is used as an argument, the value passed to the function is the location or    address of the beginning of the array - there is no copying of array elements.    By subscripting this value, the function can access and alter any argument of    the array. This is the topic of the next section.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;h2 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/h2&gt; &lt;h2 align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;1.9 Character Arrays&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt; &lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;The most common type of array in C is the array of characters.    To illustrate the use of character arrays and functions to manipulate them,    let's write a program that reads a set of text lines and prints the longest.    The outline is simple enough:    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   while (&lt;em&gt;there's another line&lt;/em&gt;)&lt;br /&gt;     if (&lt;em&gt;it's longer than the previous longest&lt;/em&gt;)&lt;br /&gt;         (&lt;em&gt;save it&lt;/em&gt;)&lt;br /&gt;         (&lt;em&gt;save its length&lt;/em&gt;)&lt;br /&gt; &lt;em&gt;print longest line&lt;/em&gt; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  This outline makes it clear that the program divides naturally into pieces.    One piece gets a new line, another saves it, and the rest controls the process.  &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;Since things divide so nicely, it would be well to write them    that way too. Accordingly, let us first write a separate function &lt;tt&gt;getline&lt;/tt&gt;    to fetch the next line of input. We will try to make the function useful in    other contexts. At the minimum, &lt;tt&gt;getline&lt;/tt&gt; has to return a signal about    possible end of file; a more useful design would be to return the length of    the line, or zero if end of file is encountered. Zero is an acceptable end-of-file    return because it is never a valid line length. Every text line has at least    one character; even a line containing only a newline has length 1.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;When we find a line that is longer than the previous longest    line, it must be saved somewhere. This suggests a second function, &lt;tt&gt;copy&lt;/tt&gt;,    to copy the new line to a safe place.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;Finally, we need a main program to control &lt;tt&gt;getline&lt;/tt&gt;    and &lt;tt&gt;copy&lt;/tt&gt;. Here is the result.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   #include &lt;stdio.h&gt;&lt;br /&gt; #define MAXLINE 1000   /* maximum input line length */&lt;br /&gt;&lt;br /&gt; int getline(char line[], int maxline);&lt;br /&gt; void copy(char to[], char from[]);&lt;br /&gt;&lt;br /&gt; /* print the longest input line */&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;     int len;            /* current line length */&lt;br /&gt;     int max;            /* maximum length seen so far */&lt;br /&gt;     char line[MAXLINE];    /* current input line */&lt;br /&gt;     char longest[MAXLINE]; /* longest line saved here */&lt;br /&gt;&lt;br /&gt;     max = 0;&lt;br /&gt;     while ((len = getline(line, MAXLINE)) &gt; 0)&lt;br /&gt;         if (len &gt; max) {&lt;br /&gt;             max = len;&lt;br /&gt;             copy(longest, line);&lt;br /&gt;         }&lt;br /&gt;     if (max &gt; 0)  /* there was a line */&lt;br /&gt;         printf("%s", longest);&lt;br /&gt;     return 0;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /* getline:  read a line into s, return length  */&lt;br /&gt; int getline(char s[],int lim)&lt;br /&gt; {&lt;br /&gt;     int c, i;&lt;br /&gt;&lt;br /&gt;     for (i=0; i &lt; c="getchar())!="EOF" c ="="" i =" 0;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  The functions &lt;tt&gt;getline&lt;/tt&gt; and &lt;tt&gt;copy&lt;/tt&gt; are declared at the beginning    of the program, which we assume is contained in one file. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;tt&gt;main&lt;/tt&gt; and &lt;tt&gt;getline&lt;/tt&gt; communicate through a pair    of arguments and a returned value. In &lt;tt&gt;getline&lt;/tt&gt;, the arguments are declared    by the line  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;   int getline(char s[], int lim);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;  which specifies that the first argument, &lt;tt&gt;s&lt;/tt&gt;, is an array, and the second,    &lt;tt&gt;lim&lt;/tt&gt;, is an integer. The purpose of supplying the size of an array in    a declaration is to set aside storage. The length of an array &lt;tt&gt;s&lt;/tt&gt; is    not necessary in &lt;tt&gt;getline&lt;/tt&gt; since its size is set in &lt;tt&gt;main&lt;/tt&gt;. &lt;tt&gt;getline&lt;/tt&gt;    uses &lt;tt&gt;return&lt;/tt&gt; to send a value back to the caller, just as the function    &lt;tt&gt;power&lt;/tt&gt; did. This line also declares that &lt;tt&gt;getline&lt;/tt&gt; returns an    &lt;tt&gt;int&lt;/tt&gt;; since &lt;tt&gt;int&lt;/tt&gt; is the default return type, it could be omitted.  &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;Some functions return a useful value; others, like &lt;tt&gt;copy&lt;/tt&gt;,    are used only for their effect and return no value. The return type of &lt;tt&gt;copy&lt;/tt&gt;    is &lt;tt&gt;void&lt;/tt&gt;, which states explicitly that no value is returned.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;tt&gt;getline&lt;/tt&gt; puts the character &lt;tt&gt;'\0'&lt;/tt&gt; (the &lt;em&gt;null    character&lt;/em&gt;, whose value is zero) at the end of the array it is creating,    to mark the end of the string of characters. This conversion is also used by    the C language: when a string constant like &lt;/span&gt;&lt;/span&gt;  &lt;/p&gt;&lt;div align="justify"&gt;   &lt;pre&gt;   &lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;"hello\n"&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;/div&gt; &lt;p align="justify"&gt;   &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;The    &lt;tt&gt;%s&lt;/tt&gt; format specification in &lt;tt&gt;printf&lt;/tt&gt; expects the corresponding    argument to be a string represented in this form. &lt;tt&gt;copy&lt;/tt&gt; also relies    on the fact that its input argument is terminated with a &lt;tt&gt;'\0'&lt;/tt&gt;, and    copies this character into the output. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;It    is worth mentioning in passing that even a program as small as this one presents    some sticky design problems. For example, what should &lt;tt&gt;main&lt;/tt&gt; do if it    encounters a line which is bigger than its limit? &lt;tt&gt;getline&lt;/tt&gt; works safely,    in that it stops collecting when the array is full, even if no newline has been    seen. By testing the length and the last character returned, &lt;tt&gt;main&lt;/tt&gt; can    determine whether the line was too long, and then cope as it wishes. In the    interests of brevity, we have ignored this issue. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;There    is no way for a user of &lt;tt&gt;getline&lt;/tt&gt; to know in advance how long an input    line might be, so &lt;tt&gt;getline&lt;/tt&gt; checks for overflow. On the other hand, the    user of &lt;tt&gt;copy&lt;/tt&gt; already knows (or can find out) how big the strings are,    so we have chosen not to add error checking to it. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;strong&gt;Exercise    1-16.&lt;/strong&gt; Revise the main routine of the longest-line program so it will    correctly print the length of arbitrary long input lines, and as much as possible    of the text. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;strong&gt;Exercise    1-17.&lt;/strong&gt; Write a program to print all input lines that are longer than    80 characters. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;strong&gt;Exercise    1-18.&lt;/strong&gt; Write a program to remove trailing blanks and tabs from each    line of input, and to delete entirely blank lines. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;strong&gt;Exercise    1-19.&lt;/strong&gt; Write a function &lt;tt&gt;reverse(s)&lt;/tt&gt; that reverses the character    string &lt;tt&gt;s&lt;/tt&gt;. Use it to write a program that reverses its input a line    at a time. &lt;/span&gt; &lt;/p&gt;&lt;h2 align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;&lt;a name="s1.10"&gt;1.10    External Variables and Scope&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt; &lt;div align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;    The variables in &lt;tt&gt;main&lt;/tt&gt;, such as &lt;tt&gt;line&lt;/tt&gt;, &lt;tt&gt;longest&lt;/tt&gt;, etc.,    are private or local to &lt;tt&gt;main&lt;/tt&gt;. Because they are declared within &lt;tt&gt;main&lt;/tt&gt;,    no other function can have direct access to them. The same is true of the variables    in other functions; for example, the variable &lt;tt&gt;i&lt;/tt&gt; in &lt;tt&gt;getline&lt;/tt&gt;    is unrelated to the &lt;tt&gt;i&lt;/tt&gt; in copy. Each local variable in a function comes    into existence only when the function is called, and disappears when the function    is exited. This is why such variables are usually known as &lt;em&gt;automatic&lt;/em&gt;    variables, following terminology in other languages. We will use the term automatic    henceforth to refer to these local variables. (Chapter 4 discusses the &lt;tt&gt;static&lt;/tt&gt;    storage class, in which local variables do retain their values between calls.)    &lt;/span&gt; &lt;/div&gt; &lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;Because    automatic variables come and go with function invocation, they do not retain    their values from one call to the next, and must be explicitly set upon each    entry. If they are not set, they will contain garbage. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;As    an alternative to automatic variables, it is possible to define variables that    are &lt;em&gt;external&lt;/em&gt; to all functions, that is, variables that can be accessed    by name by any function. (This mechanism is rather like Fortran COMMON or Pascal    variables declared in the outermost block.) Because external variables are globally    accessible, they can be used instead of argument lists to communicate data between    functions. Furthermore, because external variables remain in existence permanently,    rather than appearing and disappearing as functions are called and exited, they    retain their values even after the functions that set them have returned. &lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;An    external variable must be &lt;em&gt;defined&lt;/em&gt;, exactly once, outside of any function;    this sets aside storage for it. The variable must also be &lt;em&gt;declared&lt;/em&gt;    in each function that wants to access it; this states the type of the variable.    The declaration may be an explicit &lt;tt&gt;extern&lt;/tt&gt; statement or may be implicit    from context. To make the discussion concrete, let us rewrite the longest-line    program with &lt;tt&gt;line&lt;/tt&gt;, &lt;tt&gt;longest&lt;/tt&gt;, and &lt;tt&gt;max&lt;/tt&gt; as external variables.    This requires changing the calls, declarations, and bodies of all three functions.    &lt;/span&gt; &lt;/p&gt;&lt;div align="justify"&gt;   &lt;pre&gt;&lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt;   #include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt; #define MAXLINE 1000    /* maximum input line size */&lt;br /&gt;&lt;br /&gt; int max;                /* maximum length seen so far */&lt;br /&gt; char line[MAXLINE];     /* current input line */&lt;br /&gt; char longest[MAXLINE];  /* longest line saved here */&lt;br /&gt;&lt;br /&gt; int getline(void);&lt;br /&gt; void copy(void);&lt;br /&gt;&lt;br /&gt; /* print longest input line; specialized version */&lt;br /&gt; main()&lt;br /&gt; {&lt;br /&gt;     int len;&lt;br /&gt;     extern int max;&lt;br /&gt;     extern char longest[];&lt;br /&gt;&lt;br /&gt;     max = 0;&lt;br /&gt;     while ((len = getline()) &gt; 0)&lt;br /&gt;         if (len &gt; max) {&lt;br /&gt;             max = len;&lt;br /&gt;             copy();&lt;br /&gt;         }&lt;br /&gt;     if (max &gt; 0)  /* there was a line */&lt;br /&gt;         printf("%s", longest);&lt;br /&gt;     return 0;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /* getline:  specialized version */&lt;br /&gt; int getline(void)&lt;br /&gt; {&lt;br /&gt;     int c, i;&lt;br /&gt;     extern char line[];&lt;br /&gt;&lt;br /&gt;     for (i = 0; i &lt; c="getchar))" c ="="" i =" 0;"&gt;&lt;/span&gt;&lt;/pre&gt;   &lt;span style=";font-family:Verdana,Arial,Helvetica,sans-serif;font-size:85%;"  &gt; The external variables    in &lt;tt&gt;main&lt;/tt&gt;, &lt;tt&gt;getline&lt;/tt&gt; and &lt;tt&gt;copy&lt;/tt&gt; are defined by the first    lines of the example above, which state their type and cause storage to be allocated    for them. Syntactically, external definitions are just like definitions of local    variables, but since they occur outside of functions, the variables are external.    Before a function can use an external variable, the name of the variable must    be made known to the function; the declaration is the same as before except    for the added keyword &lt;tt&gt;extern&lt;/tt&gt;. &lt;/span&gt;&lt;/div&gt; &lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;In certain    circumstances, the &lt;tt&gt;extern&lt;/tt&gt; declaration can be omitted. If the definition    of the external variable occurs in the source file before its use in a particular    function, then there is no need for an &lt;tt&gt;extern&lt;/tt&gt; declaration in the function.    The &lt;tt&gt;extern&lt;/tt&gt; declarations in &lt;tt&gt;main&lt;/tt&gt;, &lt;tt&gt;getline&lt;/tt&gt; and &lt;tt&gt;copy&lt;/tt&gt;    are thus redundant. In fact, common practice is to place definitions of all    external variables at the beginning of the source file, and then omit all extern    declarations. &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;If the program    is in several source files, and a variable is defined in &lt;em&gt;file1&lt;/em&gt; and    used in &lt;em&gt;file2&lt;/em&gt; and &lt;em&gt;file3&lt;/em&gt;, then &lt;tt&gt;extern&lt;/tt&gt; declarations    are needed in &lt;em&gt;file2&lt;/em&gt; and &lt;em&gt;file3&lt;/em&gt; to connect the occurrences of    the variable. The usual practice is to collect &lt;tt&gt;extern&lt;/tt&gt; declarations    of variables and functions in a separate file, historically called a &lt;em&gt;header&lt;/em&gt;,    that is included by &lt;tt&gt;#include&lt;/tt&gt; at the front of each source file. The    suffix &lt;tt&gt;.h&lt;/tt&gt; is conventional for header names. The functions of the standard    library, for example, are declared in headers like &lt;tt&gt;&lt;stdio.h&gt;&lt;/stdio.h&gt;&lt;/tt&gt;.    This topic is discussed at length in Chapter 4, and the library itself in Chapter    7.&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;Since the    specialized versions of &lt;tt&gt;getline&lt;/tt&gt; and &lt;tt&gt;copy&lt;/tt&gt; have no arguments,    logic would suggest that their prototypes at the beginning of the file should    be &lt;tt&gt;getline()&lt;/tt&gt; and &lt;tt&gt;copy()&lt;/tt&gt;. But for compatibility with older    C programs the standard takes an empty list as an old-style declaration, and    turns off all argument list checking; the word &lt;tt&gt;void&lt;/tt&gt; must be used for    an explicitly empty list. We will discuss this further in Chapter 4. &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;You should    note that we are using the words &lt;em&gt;definition&lt;/em&gt; and &lt;em&gt;declaration&lt;/em&gt;    carefully when we refer to external variables in this section.``Definition''    refers to the place where the variable is created or assigned storage; ``declaration''    refers to places where the nature of the variable is stated but no storage is    allocated. &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;By the way,    there is a tendency to make everything in sight an &lt;tt&gt;extern&lt;/tt&gt; variable    because it appears to simplify communications - argument lists are short and    variables are always there when you want them. But external variables are always    there even when you don't want them. Relying too heavily on external variables    is fraught with peril since it leads to programs whose data connections are    not all obvious - variables can be changed in unexpected and even inadvertent    ways, and the program is hard to modify. The second version of the longest-line    program is inferior to the first, partly for these reasons, and partly because    it destroys the generality of two useful functions by writing into them the    names of the variables they manipulate. &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;At this    point we have covered what might be called the conventional core of C. With    this handful of building blocks, it's possible to write useful programs of considerable    size, and it would probably be a good idea if you paused long enough to do so.    These exercises suggest programs of somewhat greater complexity than the ones    earlier in this chapter. &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercise    1-20.&lt;/strong&gt; Write a program &lt;tt&gt;detab&lt;/tt&gt; that replaces tabs in the input    with the proper number of blanks to space to the next tab stop. Assume a fixed    set of tab stops, say every &lt;em&gt;n&lt;/em&gt; columns. Should &lt;em&gt;n&lt;/em&gt; be a variable    or a symbolic parameter? &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercise    1-21.&lt;/strong&gt; Write a program &lt;tt&gt;entab&lt;/tt&gt; that replaces strings of blanks    by the minimum number of tabs and blanks to achieve the same spacing. Use the    same tab stops as for &lt;tt&gt;detab&lt;/tt&gt;. When either a tab or a single blank would    suffice to reach a tab stop, which should be given preference? &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercise    1-22.&lt;/strong&gt; Write a program to ``fold'' long input lines into two or more    shorter lines after the last non-blank character that occurs before the &lt;em&gt;n&lt;/em&gt;-th    column of input. Make sure your program does something intelligent with very    long lines, and if there are no blanks or tabs before the specified column.    &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercise    1-23.&lt;/strong&gt; Write a program to remove all comments from a C program. Don't    forget to handle quoted strings and character constants properly. C comments    don't nest. &lt;/span&gt; &lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana,Arial,Helvetica,sans-serif;"&gt;&lt;strong&gt;Exercise    1-24.&lt;/strong&gt; Write a program to check a C program for rudimentary syntax errors    like unmatched parentheses, brackets and braces. Don't forget about quotes,    both single and double, escape sequences, and comments. (This program is hard    if you do it in full generality.) &lt;/span&gt;&lt;/span&gt;  &lt;/p&gt;&lt;p align="justify"&gt;   &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3800941631712763981-2878726171022551264?l=ab-ebooks.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ab-ebooks.blogspot.com/feeds/2878726171022551264/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3800941631712763981&amp;postID=2878726171022551264' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3800941631712763981/posts/default/2878726171022551264'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3800941631712763981/posts/default/2878726171022551264'/><link rel='alternate' type='text/html' href='http://ab-ebooks.blogspot.com/2007/09/c.html' title='About c'/><author><name>Niranjan</name><uri>http://www.blogger.com/profile/13413521883177554840</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3800941631712763981.post-1292531978111893029</id><published>2007-09-23T22:52:00.000-07:00</published><updated>2007-09-23T22:55:46.062-07:00</updated><title type='text'>Qbasic</title><content type='html'>&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;b&gt;&lt;a name="introdcution"&gt;&lt;/a&gt;Introduction&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;  In the early days of programming, it was usually the scientific elite doing    the programming and they were usually trained above and beyond the average American    to do their programming work. It was not until 1964 at Dartsmouth college that    the Beginner's All-purpose Symbolic Instruction Code would be introduced --    more commonly known as BASIC. Using common English to perform processor tasks,    BASIC became quickly popular, although it was disliked by programmers of more    "low-level" languages such as assembly and FORTRAN. In 1985 Microsoft    released their own version of BASIC called QBasic with their MS-DOS 5.0 operating    system. Since then, nearly every PC user owns their own copy of QBasic, making    it a widely known language. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; QBasic is a very    simple language to pick up, and yet it can accomplish a great deal. Granted    you will probably never write Doom or Word Perfect with QBasic, but it has it's    strong points. One of them is to introduce people to programming without having    to worry about the internal workings of the computer. It's simple to create    games, business applications, simple databases, and graphics. The best aspect    of the language is it's close resemblance to English. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; This small tutorial    introduces the simple concepts of programming to get you started, so if you    already know another language or are already familiar with programming, you    may want to skim through the first couple sections. Good luck!&lt;br /&gt;  &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;b&gt; &lt;a name="variables"&gt;&lt;/a&gt;VARIABLES    &lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;A variable, simply    defined, is a name which can contain a value. Programming involves giving values    to these names and presenting them in some form to the user. A variable has    a type which is defined by the kind of value it holds. If the variable holds    a number, it may be of integer, floating decimal, long integer, or imaginary.    If the variable holds symbols or text, it may be a character variable or a string    variable. These are terms you will become accustomed to as you continue programming.    &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Here are some examples    of values a variable might contain: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; STRING            "hello, this is a string"&lt;br /&gt;  INTEGER       5&lt;br /&gt;  LONG            92883&lt;br /&gt;  SINGLE         39.2932&lt;br /&gt;  DOUBLE        983288.18&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The first is a    string. Strings contain text. The last four are number types. But the computer    does not know what kind of value you are trying to give a variable unless you    tell it! There are two methods of telling the computer what kind of variable    you are using: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; Explicitly declare    the variable AS a type. This is done by using the DIM statement. Say you wanted    to make a variable called number which would contain an integer (whole number,    no digits after the decimal point). You would do it like this: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;DIM number AS INTEGER&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Then you would    use that variable as an integer. The word DIM actually originates from the word    Dimension, but you won't see why until we discuss arrays. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; Put a symbol after    the variable name which is defined as representing that type. QBasic has a set    of symbols which represent each variable type: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; $ String&lt;br /&gt;  % Integer&lt;br /&gt;  &amp;amp; Long&lt;br /&gt;  ! Single&lt;br /&gt;  # Double&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Appending one of    these symbols to the name of a variable when you use it in the program tells    the computer that you are using it as that type. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This is actually    a difficult concept to grasp for newcomers to programming. The most common error    in QBasic is the infamous Type Mismatch which you will see a lot. This means    that you are trying to put a value into a variable of the wrong type. You might    be trying to put the letters "hi there" into an integer variable.    If you don't define the type of the variable, then QBasic assumes it is of the    Single type, which can often yield unexpected results. I personally prefer to    use the type symbols after variable names, but come explicitly declare them    usually at the head of their programs. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;  &lt;b&gt;&lt;a name="interactingwiththecomputer"&gt;&lt;/a&gt; INTERACTING WITH THE COMPUTER&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;You know what a    variable is and how to control them, it's time you learned some programming.    QBasic (like all other languages) is set up using pre-defined statements according    to the syntax specified for that statement. It may be helpful to look in the    help index to learn a statement, although I've heard many complaint's that the    help index is too hard. Indeed it is too hard for new programmers, but as you    learn more and more statements and their syntaxes, you'll become accustomed    to the index and use it as a casual reference. Lets make a program that prints    some text on the screen. Type qbasic at the DOS prompt and enter the following    program. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CLS&lt;br /&gt;  PRINT "This text will appear on the screen"&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The first statement    -- CLS -- stands for "clear screen." It erases whatever was on the    screen before it was executed. PRINT simply displays its argument to the screen    at the current text cursor location. The argument in this case is the text enclosed    in quotes. PRINT displays text within quotes directly, or it can display the    value of a variable, like this: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CLS&lt;br /&gt;  a% = 50&lt;br /&gt;  b% = 100&lt;br /&gt;  PRINT "The value of a is "; a%; " and the value of b is ";    b%&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This will yield    the output; The value of a is 50 and the value of b is 100. The semicolons indicate    that the next time something is printed, it will be right after where the last    PRINT statement left off. Remember that PRINT prints literally what is inside    quotes, and the value of the variable which is not in quotes. a% and b% are    integers containing values in this example, and their values are printed using    the PRINT statement. Say you want to interact with the user now. You'll need    to learn a statement called INPUT. INPUT displays a prompt (the first argument)    and assigns what the user types in to a variable (the second argument) &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CLS&lt;br /&gt;  INPUT "What is your name? ", yourName$&lt;br /&gt;  INPUT "How old are you? ", age%&lt;br /&gt;  PRINT "So, "; yourName$; ", you are "; age%; " years    old. That's interesting."&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This firsts asks    the user for their name and assigns it to the string variable yourName$. Then    the age is requested, and the result is printed in a sentence. Try it out! So    what happens if you input I DON'T KNOW for the age prompt? You'll get a weird    message that says REDO FROM START. Why? The program is trying to assign a string    (text) to an integer (number) type, and this makes no sense so the user is asked    to do it over again. Another cornerstone of programming is the conditional test.    Basically, the program tests if a condition is true, and if it is, it does something.    It looks like English so it's not as hard as it sounds. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CLS&lt;br /&gt;  PRINT "1. Say hello" ' option 1&lt;br /&gt;  PRINT "2. Say nice tie" ' option 2&lt;br /&gt;  INPUT "Enter your selection ", selection%&lt;br /&gt;  IF selection% = 1 THEN PRINT "hello"&lt;br /&gt;  IF selection% = 2 THEN PRINT "nice tie"&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The user is given    a set of options, and then they input a value which is assigned to the variable    selection%. The value of selection% is then tested, and code is executed based    on the value. If the user pressed 1, it prints hello, but if they pressed 2,    it prints nice tie. Also notice the text after the ' in the code. These are    remark statements. Anything printed after a ' on a line does not affect the    outcome of the program. Back to the actual code -- but what if the user doesn't    input 1 or 2? What if they input 328? This must be taken into account as part    of programming. You usually can't assume that the user has half a brain, so    if they do something wrong, you can't screw up the program. So the ELSE statement    comes into play. The logic goes like this: IF the condition is true,THEN do    something, but if the condition is anything ELSE, then do something else. You    follow? The ELSE statement is used with IF...THEN to test if a condition is    anything else. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CLS&lt;br /&gt;  INPUT "Press 1 if you want some pizza.", number%&lt;br /&gt;  IF number% = 1 THEN PRINT "Here's your pizza" ELSE PRINT "You    don't get pizza"&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;That's a fairly    simple example, and real life things will be much more complex. Lets try a "real    life" program. QBasic is capable of fairly sophisticated math, so lets    put some of it to use. Say your Algebra teacher tells you to find the areas    of the circles with the following radiuses (radii, whatever), and he gives you    a sheet with hundreds of radii. You decide to boot up your computer and write    the following program: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CLS&lt;br /&gt;  pi! = 3.1415&lt;br /&gt;  INPUT "What is the radius of the circle? ", radius!&lt;br /&gt;  area! = pi! * radius! ^ 2&lt;br /&gt;  PRINT "The area of the circle is ", area!&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;First, we're defining    the variable pi. It's a single number, which means that it can be a fairly large    number with some decimal places. The exclamation mark tells QBasic that pi is    of the single type. Next, the user is prompted for the radius of their circle.    Then the area is calculated. The * means "times," and the ^ (carrot)    means "to the power of." radius! ^ 2 means "radius squared."    This could also be written as pi! * radius! * radius!. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;There's one big    problem with that program. The teacher gave you a sheet with hundreds of radii    (please email me if you know how to spell this!). For every radius, you must    run the program over again. This is not practical. If we had some kind of a    loop until we wanted to quit that just kept on repeating over and over it would    be much more useful. Of course, QBasic has the means of performing this feat.    Loop structures. They start with the statement DO, and end with the statement    LOOP. You can LOOP UNTIL or WHILE , or DO UNTIL or WHILE a condition is true.    Another option (which we will use) is to break out of the loop manually as soon    as a condition is true. Lets revise the previous code: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CLS&lt;br /&gt;  pi! = 3.1415&lt;br /&gt;  DO ' Begin the loop here&lt;br /&gt;  INPUT "What is the radius of the circle? (-1 to end) ", radius!&lt;br /&gt;  IF radius! = -1 THEN EXIT DO&lt;br /&gt;  area! = pi! * radius! ^ 2&lt;br /&gt;  PRINT "The area of the circle is ", area!&lt;br /&gt;  PRINT&lt;br /&gt;  LOOP ' End the loop here&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Now we can end    the program by entering -1 as the radius. The program checks the radius after    the user inputs it and checks if it is -1. If it is, it exits the loop. If it    isn't it just keeps going it's merry way. The PRINT with no arguments prints    a blanks line so we can separate our answers. I highly recommend entering this    program into QBasic just so you can see exactly how it works. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Say you want to    print something in a certain pre-defined format. Say you want to print a series    of digits with only 2 places after the decimal point and a dollar sign before    the first digit. To do this requires the PRINT USING statement, which is very    handy in applications for businesses. The PRINT USING statement accepts two    types of arguments. The first is a string which has already been defined. This    is a special type of string, in that it contains format specifiers, which specify    the format of the variables passed as the other arguments. Confused? You won't    be. Here's a quick list of the most common format specifiers &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; ### digits&lt;br /&gt;  &amp;amp; Prints an entire string&lt;br /&gt;  \ \ Prints a string fit within the backslashes.&lt;br /&gt;  Any thing longer is truncated&lt;br /&gt;  $$ Puts a dollar sign to the left of a number&lt;br /&gt;  . Prints a decimal point&lt;br /&gt;  , Prints a comma every third digit to the left&lt;br /&gt;  of the decimal point.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;And these can be    combined in a format string to make a user defined way to print something. So    $$#,###.## will print a number with a dollar sign to the left of it. If the    number has more than two decimal places, it is truncated to two. If it is more    than four digits long to the left of the decimal place, it is also truncated    to fit. To use a PRINT USING statement, you must first define the format string    containing the format specifiers. Then you use PRINT USING, then the name of    the format string, and variable values to fill the places defined in the format    string. Here's a code example &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CLS ' get user    input&lt;br /&gt;  INPUT "Enter item name: ", itemname$&lt;br /&gt;  INPUT "How many items?: ", numitems%&lt;br /&gt;  INPUT "What does one cost?: ", itemcost!&lt;br /&gt;  CLS ' display inputs&lt;br /&gt;  format$ = "\ \ #,### $$#,###.## $$#,###,###.##"&lt;br /&gt;  PRINT "Item Name Quantity Cost Total Cost "&lt;br /&gt;  PRINT "-------------- -------- ---------- --------------"&lt;br /&gt;  totalcost! = numitems% * itemcost!&lt;br /&gt;  PRINT USING format$; itemname$; numitems%; itemcost!; totalcost!&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;First, we get the    item name, number of items, and cost per item from the user. Then we clear the    screen and define the format string to be used. It contains a static length    string (text that will be truncated if it is too long), up to 4 digits for the    quantity, 4 digits and two decimals for the item cost, and 7 digits and two    decimals for the total cost. Then we print out some column headers so we know    what each value will represent, and some nice lines to go under the column headers.    Then the total cost is calculated by multiplying the number of items by the    item cost. Finally, the four variable's values are displayed under the column    headers using the PRINT USING statement. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;b&gt;&lt;a name="more"&gt;&lt;/a&gt;MORE    ADVANCED DATA MANIPULATION&lt;/b&gt; &lt;/span&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;There are numerous    methods to manipulate data and present it to the user in QBasic. One is called    an array. An array is a variable which can contain more than one value. For    example, you might have an array called a, and you could assign data to the    members of that array. There might be a value for a(1), and a different value    for a(6). Before an array can be used, it must be declared. Arrays are declared    with the DIM statement used in section 1. Here is an example of an array declaration:    &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;DIM a(1 TO 100)    AS INTEGER&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;There are now 100    different values that can be assigned to the array a, and they must all be integers.    It could also look like this: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;DIM a%(1 TO 100)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Using the symbol    % for integer. We call the different values for the array members of the array.    Array a has 100 members. Array members can be assigned values by using a subscript    number within parentheses after the array name, like this: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;a%(1) = 10&lt;br /&gt;  a%(2) = 29&lt;br /&gt;  a%(3) = 39&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;And so on. Now    you're probably wondering why the statement for declare is DIM. This comes from    a term used in earlier programming languages that means dimension. That still    doesn't answer the question... why not use the statement DECLARE? Well, an array    can have more than one dimension. Arrays with multiple dimensions have y members    in the second dimension for every x member of the first dimension in the following    algorithm: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;DIM array( 1 TO    x, 1 TO y) AS INTEGER&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;So if the actual    declaration looked like this: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;DIM a$( 1 TO 3,    1 TO 3)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;You would have    the following members to assign values to: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;a$(1,1) a$(1,2)    a$(1,3)&lt;br /&gt;  a$(2,1) a$(2,2) a$(2,3)&lt;br /&gt;  a$(3,1) a$(3,2) a$(3,3)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;A two dimensional    array is useful for tracking the status of each piece in a checkers game, or    something of the like. Recall the last example program of section that we had    a program that would ask the user for the item name, the item cost, and the    quantity of that item, the spit out the data just given in a nice format with    the total in the right hand column. Well, with only one item, this program isn't    very practical. But now with our newfound knowledge of arrays and the knowledge    we already have of loops, we can create a&lt;br /&gt;  somewhat useful application. The process will start with the program prompting    the user for the number of items that will be calculated. Then the program loops    for the number of times that the user entered at the beginning, assigning the    data entered into a member of an array we will declare. A variable called netTotal!    will be displayed at the end of the program which will contain the total costs    of the items. netTotal! will accumulate each time through the loop as the current    totalCost! is added to it. Type the following code: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CLS&lt;br /&gt;  INPUT "How many items to be calculated? ", totalItems%&lt;br /&gt;  DIM itemName$(1 TO totalItems%) ' Declare our arrays&lt;br /&gt;  DIM itemCost!(1 TO totalItems%)&lt;br /&gt;  DIM numItems%(1 TO totalItems%)&lt;br /&gt;  DIM totalCost!(1 TO totalItems%)&lt;br /&gt;  FOR i% = 1 TO totalItems% 'First loop: get inputs&lt;br /&gt;  CLS&lt;br /&gt;  PRINT "Item "; i% ' Display the current item number&lt;br /&gt;  PRINT&lt;br /&gt;  INPUT "Item name -- ", itemName$(i%)&lt;br /&gt;  INPUT "Item cost -- ", itemCost!(i%)&lt;br /&gt;  INPUT "Quantity --- ", numItems%(i%)&lt;br /&gt;  totalCost!(i%) = itemCost!(i%) * numItems%(i%)&lt;br /&gt;  NEXT i%&lt;br /&gt;  CLS&lt;br /&gt;  PRINT "Summary"&lt;br /&gt;  PRINT&lt;br /&gt;  format$ = "\ \ $$#,###.## #,### $$#,###,###.##"&lt;br /&gt;  PRINT "Item name Item Cost Quantity Total Cost "&lt;br /&gt;  PRINT "----------------- ---------- -------- --------------"&lt;br /&gt;  FOR i% = 1 TO totalItems%&lt;br /&gt;  PRINT USING format$; itemName$(i%); itemCost!(i%); numItems%(i%); totalCost!(i%)&lt;br /&gt;  netTotal! = netTotal! + totalCost!(i%)&lt;br /&gt;  NEXT i%&lt;br /&gt;  PRINT&lt;br /&gt;  PRINT "Net Total = "; netTotal!&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This program is    much larger than anything we've done as of yet. It is kind of a review of everything    we've done so far and one additional feature: the FOR...NEXT loop. This kind    of loop loops for the number of times specified. A value is given to a variable    and the program loops until that variable is equal or greater than the number    specified after the TO. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;FOR i% = 1 TO 10&lt;br /&gt;  PRINT i%&lt;br /&gt;  NEXT i%&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Will loop 10 times,    printing the numbers 1 through 10. The loop ends with a NEXT statement followed    by the variable the loop increments for. So in our program, we have loops with    index numbers (i%) starting at 1 and increasing for every number between 1 and    the totalItems%, which is given by the user in the first part of the program.    After the user inputs the number of items that will be calculated, four arrays    are DIMensioned. They are one dimensional arrays, so they aren't very complex.    The first FOR...NEXT loop prompts the user for each item. Then the format string    is defined and the column headers are printed. The second FOR...NEXT loop cycles    through the members of the four arrays and prints the data using the format    string. The data for each member was assigned in the first FOR...NEXT loop.    Each cycle through the second loop, the totalCost! of the current item being    printed is added to the variable netTotal!. The netTotal! is the total sum of    the total costs. After the second FOR...NEXT loop, the net total is printed    and the program ends. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Say we have a game    and when the user makes a record score, they get to write their name on a list    of the 10 best scores. But the next time the user plays the game, we want the    name and position they recorded the last time they played to still be there.    To do this, we must write to what is called a file, and then read it again later.    If you are computer literate, then no doubt you know what a file is, and since    you are using the internet to read this, I'm assuming you are. If you don't    know what a file is and you really want me to explain it, then email me and    I will. So we need to write to file. Before you can do anything to a file, you    must open it, and there are different ways you can open a file, believe it or    not. A file can be opened so you can read from it or write to it, or it can    be opened and split into records like a database. Here is a quick table of the    different ways you can open a file: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; Input: Read data    from the file&lt;br /&gt;  Output: Write data to the file&lt;br /&gt;  Append: Write data to the end of a file&lt;br /&gt;  Binary: Read from or write to a file in binary mode&lt;br /&gt;  Random: Read from or write to a file which is split up in records like a database    &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The syntax for    the OPEN statement is quite peculiar. It's arguments require us to specify a    file name, an access type (the 5 types defined above), and a file number. When    the file is open, QBasic recognizes it by a number which we assign to the file    when we open it. All references made to the file use this number. It can be    any number from 1 to 255. An open statement may look like this: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;OPEN "sample.txt"    FOR INPUT AS #1&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;We will be reading    data from this file because it was opened for input. Back to our problem about    the game scores. Lets set up a program which will ask for their name and give    them a random score. Then it will put their name on the list at the appropriate    place on the top 10 (if it makes the list). We'll call the file "top10.dat."    But say when the user buys the game, there are already 10 names and scores in    there. We write the following program to put default names and scores into top10.dat:    &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CLS&lt;br /&gt;  OPEN "top10.dat" FOR OUTPUT AS #1&lt;br /&gt;  FOR i% = 1 TO 10&lt;br /&gt;  playername$ = "Player" + STR$(i%)&lt;br /&gt;  playerscore% = 1000 - (i% * 100)&lt;br /&gt;  WRITE #1, playername$, playerscore%&lt;br /&gt;  NEXT i%&lt;br /&gt;  CLOSE #1&lt;br /&gt;  PRINT "Data written to file"&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;  There are a couple strange features of this program that we have not seen yet.    In the second line of the program the file is opened for output so we can write    to it. In the fourth line of the program we get into some light string manipulation.    A name is generated from the word player, and is concatenated with string form    of the current loop number. You can concatenate two strings by using the + operator.    The STR$ function returns the string representation of the number passed to    it. The opposite of the STR$ function is the VAL function, which returns the    numeric value of the string passed to it. Lastly, the WRITE statement writes    to the file number specified as the first argument the values of the following    arguments. Data is written to file in a format readable by the INPUT # statement    which we will use in the actual program. We need this short program for the    big one to work so we can give the program data to read from, or else we will    get a nasty INPUT PAST END OF FILE error when we try to run it. Note that the    file should be closed when we are done with it by using the CLOSE statement    followed by the file number. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;And now we come    to the big program, as I have referred to it. It is quite large and complex,    and I have not fully described all the statements used in it, so I have broken    it down to five sections which I will describe in detail afterwards. Here, at    last, is the code: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;' section 1&lt;br /&gt;  CLS&lt;br /&gt;  RANDOMIZE TIMER&lt;br /&gt;  yourScore% = INT(RND * 1000)&lt;br /&gt;  PRINT "Game Over"&lt;br /&gt;  PRINT "Your score is "; yourScore%&lt;br /&gt;  DIM playername$(1 TO 10) 'Declare arrays for the 10 entries on the list&lt;br /&gt;  DIM playerscore%(1 TO 10) &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;' section 2&lt;br /&gt;  OPEN "top10.dat" FOR INPUT AS #1&lt;br /&gt;  DO WHILE NOT EOF(1) ' EOF means "end of file"&lt;br /&gt;  i% = i% + 1&lt;br /&gt;  INPUT #1, playername$(i%) 'Read from file&lt;br /&gt;  INPUT #1, playerscore%(i%)&lt;br /&gt;  LOOP&lt;br /&gt;  CLOSE #1&lt;br /&gt;  PRINT &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;' section 3&lt;br /&gt;  FOR i% = 1 TO 10&lt;br /&gt;  IF yourScore% &gt;= playerscore%(i%) THEN&lt;br /&gt;  FOR ii% = 10 TO i% + 1 STEP -1 'Go backwards (i% &lt; 10)&lt;br /&gt;  playername$(ii%) = playername$(ii% - 1)&lt;br /&gt;  playerscore%(ii%) = playerscore%(ii% - 1)&lt;br /&gt;  NEXT ii%&lt;br /&gt;  PRINT "Congratulations! You have made the top 10!"&lt;br /&gt;  INPUT "What is your name? ", yourName$&lt;br /&gt;  playername$(i%) = yourName$&lt;br /&gt;  playerscore%(i%) = yourScore%&lt;br /&gt;  EXIT FOR&lt;br /&gt;  END IF&lt;br /&gt;  NEXT i%&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;' section 4&lt;br /&gt;  OPEN "top10.dat" FOR OUTPUT AS #1&lt;br /&gt;  FOR i% = 1 TO 10&lt;br /&gt;  WRITE #1, playername$(i%), playerscore%(i%)&lt;br /&gt;  NEXT i%&lt;br /&gt;  CLOSE #1&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;' section 5&lt;br /&gt;  PRINT&lt;br /&gt;  PRINT "Here is the top 10"&lt;br /&gt;  format$ = "\ \ #### "&lt;br /&gt;  PRINT "Player Name Score"&lt;br /&gt;  PRINT "-------------------------- -----"&lt;br /&gt;  FOR i% = 1 TO 10&lt;br /&gt;  PRINT USING format$; playername$(i%); playerscore%(i%)&lt;br /&gt;  NEXT i%&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; Section 1: The    screen is cleared. The second line contains the statement RANDOMIZE TIMER. When    dealing with random numbers, we must give the computer a number so it has something    to base the random number it will create from. This number is called the random    seed generator. A random seed generator can be specified with the RANDOMIZE    statement. For the seed, we need a number that will not be the same every time    we run a program, so we decide to use the number of seconds which have elapsed    since midnight. The TIMER statement accesses a system device called the system    timer, and returns the current number of seconds which have elapsed since midnight.    Since this number will change in each program we run, this can be used for the    random seed. The variable yourScore% is given a random number from 0 to 1000.    In the last part of section one, we declare two arrays with 10 members each.    &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; Section 2: In    the first line we open the file for input, so we can read from it. The second    line appears to be very weird at first. We are starting a loop with the DO statement,    and then a condition to do while. The function EOF tests the file number passed    to the function -- in this case 1 -- and if the end of the file (EOF) has been    encountered it returns true. So EOF(1) is true if we are reading the end of    the file. But we are using the Boolean operator NOT, so we want to loop while    the end of file condition is false. We want to do the loop while we are not    reading from the end of file 1. You will learn more about Boolean operators    (NOT, AND, OR, XOR, etc.) as you continue programming. Then we assign the current    data in the file to the arrays we declared in section 1. The INPUT # statement    is used to read from the specified file into the specified variable(s) until    a comma or carriage return is encountered. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; Section 3: The    main purpose of this section is to re-write the top 10 list if the player's    randomly generated score places on the list. We do this by cycling through the    list, and testing if yourScore% is greater than or equal to (&gt;=) the current    playerscore% being tested. If it is, then we have to shift each existing score    below the current one down one to make room for the new score being added. The    user is congratulated and prompted for their name. The loop is then exited using    the EXIT FOR statement, which then goes to section 4. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; Section 4: This    short section simply opens the file for output so we can write to it. Then we    write each of the members of the array to file. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; Section 5: In    this final section we define the format string, print the headers, and then    print all the members of the top 10 and their scores. And that's the end of    the program! &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Now on to a new    topic, which will later become related to the previous. User defined types.    Recall that a type is the type of value a variable can have, such as integer,    string, long, double, or single. You can create your own types which contain    one or more of the already defined types. Here is an example of a user defined    type: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;TYPE employeeType&lt;br /&gt;  firstname AS STRING * 30&lt;br /&gt;  lastname AS STRING * 30&lt;br /&gt;  age AS INTEGER&lt;br /&gt;  wage AS SINGLE&lt;br /&gt;  END TYPE&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;We have defined    a new type, which consists of four data members, as I call them. We can now    declare a variable of this type: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;DIM employee AS    employeeType&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;A variable of a    user defined type is like an array, in that it can have more than one value    assigned to it. But you can have an array of a variable of a user defined type    as well, so things can get rather complex. Anyway, now that you have a user    defined type, you can assign values to the data members of that variable. Use    a period to access a data member of a type, like this: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;employee.firstname    = "Bob"&lt;br /&gt;  employee.lastname = "Foster"&lt;br /&gt;  employee.age = 24&lt;br /&gt;  employee.wage = 6.78&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This could have    been helpful in the last program we made with the top 10 list. We could have    declared a user defined type called playerType, like this: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;TYPE playerType&lt;br /&gt;  name AS STRING * 20&lt;br /&gt;  score AS INTEGER&lt;br /&gt;  END TYPE&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;and then declared    an array of variables of that type &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;DIM player(1 TO    10) AS playerType&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;That would have    made our code more efficient, but not necessarily more readable. Notice when    we declare a string in a user defined type that it seems as if we are multiplying    it by a number. Actually, we the number after the * defines the maximum length    of the string. You must define this because the size of a user defined type    must be known by the computer. Any value assigned to this string data member    which exceeds the length specified is truncated. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;User defined types    can serve more than to be efficient. They are the heart of the random access    file mode, which is commonly used in database files. A database is a method    of organizing large quantities of information in records and fields. In a record,    there are a set of fields which are constant in every record. A field's value    changes from record to record, however. Just the name of the field remains constant.    So how does this relate to user defined types? Well think of a variable of a    user defined type as a record in the&lt;br /&gt;  database, and the data members fields of the records. Employee may be a record,    and firstname, lastname, age, and wage may be fields. Values can be assigned    to the fields in each record, thus constructing a database. A file opened for    random access is organized in this fashion, with records split into fields.    Each record in the random access file is given a record number which can be    convenient in a database environment. In the OPEN statement for opening a random    access file there is one extra argument. We must specify the length in bytes    of how much space one record will occupy -- the record length. This can be easily    taken by taking the LENgth of a variable defined as the user defined type we    are going to use. So back to our employee example, we could use the LEN function    to get the size in bytes of the employee variable, which is an employeeType.    Here's the code: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;recordLen# = LEN(employee)&lt;br /&gt;  OPEN "database.dat" FOR RANDOM AS #1 LEN = recordLen#&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;LEN stands for    length. You can also use the LEN function to get the number of characters in    a string, but that is kind of irrelevant right now. So let's construct a simple    database that will keep track of the employees of a business. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;' Section 1&lt;br /&gt;  CLS&lt;br /&gt;  TYPE employeeType&lt;br /&gt;  firstname AS STRING * 30&lt;br /&gt;  lastname AS STRING * 30&lt;br /&gt;  age AS INTEGER&lt;br /&gt;  wage AS SINGLE&lt;br /&gt;  END TYPE&lt;br /&gt;  DIM employee AS employeeType&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;' Section 2&lt;br /&gt;  PRINT "1.) Create new recordset"&lt;br /&gt;  PRINT "2.) View existing recordset"&lt;br /&gt;  INPUT "Which option? ", selection%&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;' Section 3&lt;br /&gt;  IF selection% = 1 THEN&lt;br /&gt;  INPUT "How many employees are in the company? ", numRecords%&lt;br /&gt;  recordLen# = LEN(employee)&lt;br /&gt;  OPEN "database.dat" FOR RANDOM AS #1 LEN = recordLen#&lt;br /&gt;  FOR i% = 1 TO numRecords%&lt;br /&gt;  CLS&lt;br /&gt;  INPUT "First name: ", employee.firstname&lt;br /&gt;  INPUT "Last name: ", employee.lastname&lt;br /&gt;  INPUT "Age: ", employee.age&lt;br /&gt;  INPUT "Wage: ", employee.wage&lt;br /&gt;  PUT #1, ,employee&lt;br /&gt;  NEXT i%&lt;br /&gt;  CLS&lt;br /&gt;  CLOSE #1&lt;br /&gt;  PRINT "Recordset creation complete"&lt;br /&gt;  END&lt;br /&gt;  END IF&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;' Section 4&lt;br /&gt;  IF selection% = 2 THEN&lt;br /&gt;  recordLen# = LEN(employee)&lt;br /&gt;  OPEN "database.dat" FOR RANDOM AS #1 LEN = recordLen#&lt;br /&gt;  format$ = "\ \,\ \ ### $$##.##"&lt;br /&gt;  PRINT "Last name First name Age Wage "&lt;br /&gt;  PRINT "------------------ ------------------ --- -------"&lt;br /&gt;  DO WHILE NOT EOF(1)&lt;br /&gt;  GET #1, ,employee 'Sorry about the length of this line!!!&lt;br /&gt;  PRINT USING format$; employee.lastname; employee.firstname; employee.age; employee.wage&lt;br /&gt;  LOOP&lt;br /&gt;  CLOSE #1&lt;br /&gt;  END&lt;br /&gt;  END IF&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;I've split this    program into sections again because that seems to work well for the larger ones.    &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; Section 1: We're    defining the user defined type and declaring a variable of that type. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; Section 2: The    first thing the user sees is a menu with the option to either create a new database    (recordset) or view the existing one. The user is prompted to make a selection    which is stored in the variable selection%. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; Section 3: If    the user chose option 1 -- create a new recordset -- then this code is executed.    First we prompt the user for how many employees are in the company so we know    how many times to go through a loop. Then we open the file, prompt the user    for the data for each variable, and write the whole record to file. The record    is written using the PUT statement. The first argument in PUT is the file number,    the second is the record number, and the third is the data to be written to    file. If no record number is specified for the second argument, the current    file position is used, which will just append what we specify after what is    already there. This works fine, so we don't need to worry about explicit record    numbers. Notice that we are writing the whole employee variable to file. This    is because we write records to file, and the whole variable contains the data    for the data members (fields). &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; Section 4: If    the user chooses to view the existing recordset, then we first open the file,    define a format string for the printout, and print the headers. Next we have    a loop until the end of file is encountered. Notice the GET statement, which    is used to read from a random access file. The first argument is the file number    we want to read from, the second is the record number (which we are leaving    blank because we can read from the current position [CP] like we did in the    PUT statement), and the third is the variable in&lt;br /&gt;  which we read the data in to. This variable must be of the same type that we    wrote with or else the types will be incompatible. You'd probably get a TYPE    MISMATCH error if a different variable is used because the fields are not equal,    so the program does not know what to assign the data to. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Well that's it    for random access. If you have understood half of what I've said, feel good.    You have a good knowledge of what QBasic is about. Now on to some more advanced    programming!&lt;br /&gt;  &lt;/span&gt;&lt;/p&gt; &lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;br /&gt;&lt;b&gt; &lt;a name="graphics"&gt;&lt;/a&gt;GRAPHICS&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;  &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Graphics programming    in QBasic can get fairly complex. Lets start from the beginning. Your screen    is made up of hundreds of pixels. The number of pixels horizontally and the    vertically determines the resolution of your monitor. Right now, your monitor    is set up in a video graphics mode which determines how many pixels can be displayed    on screen. My resolution is set to 800x600 right now, but the most common is    640x480. Your graphics mode is determined by the screen resolution in pixels,    the text resolution (how many lines and columns of text can fit on your screen),    the number of pages of video memory, and the color palette. There are 13 screen    graphics modes in QBasic, and each has its different purpose. You can look in    the help index in QBasic for a listing of the screen graphics modes and their    specifications. Each of the aspects of a screen graphics type can be changed    to create effects. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;There are a number    of graphics routines used in QBasic which allow a variety of graphical effects.    Lets try a few: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;SCREEN 12&lt;br /&gt;  LINE (0,0)-(640,480), 1&lt;br /&gt;  CIRCLE (320, 240), 20, 2&lt;br /&gt;  PSET (10,10), 14&lt;br /&gt;  DRAW "c15 bm100,400 l5e5f5l5"&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The first line    initializes the graphics mode to 12, which is 16 colors, 1 page of video memory,    and 640x480 resolution. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; LINE draws a line    from one coordinate to another. The first optional argument after the coordinates    (which are not optional) is the color. After that, a B ("box") or    BF ("box fill") can be used to draw a box or a box filled with the    color specified. The first coordinate can be omitted and the - left in to draw    a line from the current graphics position (CP) to the relative coordinates specified.    LINE -(100,0) will draw a line from the current graphics position to 100 pixels    to the right.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; CIRCLE draws a    circle with the center at the coordinates specified. The first argument (required)    after the coordinates is the radius of the circle. Then comes the color. After    that, if you want to draw an arc, is the starting angle of the arc in radians,    then the ending angle of the arc. To make an arc, first touch up on your geometry,    then recall that to convert from degrees to radians is PI (3.14159265) divided    by 180. The last argument is used if you want to make an ellipse, and is the    ratio of the y axis to the x axis. So CIRCLE (320,240), 20, 2, 3.1415, 0, .5    would draw an elliptical green arc with the center at the middle of the screen,    starting at 180 degrees (PI) and going to 0 degrees, with a compression ratio    of 1 to 2 (x axis twice as big as the y). This looks like a wide smiley face    mouth.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; PSET fills a pixel    at the screen coordinate you specify with the color you specify. In this case,    yellow.&lt;br /&gt; &lt;br /&gt;  Finally, the DRAW statement. The DRAW statement has it's own commands which    I strongly suggest you memorize. When we get in to scaling and rotation you    will need to know your draw commands pretty well. The draw command in the above    code example can be read as "color 15 (white), move without drawing to    screen coordinate 100,400, draw left 5 units, draw up and right 5 units, draw    down and right 5 units, and draw left 5 units." In other words, a triangle.    A unit is set by the current scale mode, which by&lt;br /&gt;  default is 4. Since default scale mode is 4, one unit represents 4 pixels. So    our triangle is 40 pixels wide at the base. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;There are 16 defined    colors in QBasic. The COLOR statement sets the current color for text output.    I highly recommend memorizing the colors as well. Run this program: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;SCREEN 12&lt;br /&gt;  FOR i% = 0 TO 15&lt;br /&gt;  COLOR i%&lt;br /&gt;  PRINT "COLOR"; i%&lt;br /&gt;  NEXT i%&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This will print    out the 16 colors used in QBasic. 0 is black, so that obviously won't show up.    An quick reference for colors while you're in the QBasic IDE (integrated development    environment) is to look under the OPTIONS | DISPLAY menu. The colors listed    there are in the QBasic order, starting with black and ending with bright white.    &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Now you know the    basic graphics routines and their uses... lets make a couple programs that demonstrate    them to a greater extent. First, a program which prompts the user for a radius,    calculates the area and circumference, and draws the circle in a random color    on the screen. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;SCREEN 12&lt;br /&gt;  RANDOMIZE TIMER&lt;br /&gt;  CONST pi! = 3.1415&lt;br /&gt;  DO&lt;br /&gt;  COLOR 15: INPUT "Radius (-1 to quit) --&gt; ", radius!&lt;br /&gt;  IF radius! = -1 THEN EXIT DO&lt;br /&gt;  area! = pi! * radius! ^ 2&lt;br /&gt;  circum! = pi! * 2 * radius!&lt;br /&gt;  COLOR 14&lt;br /&gt;  PRINT "Area = "; area!&lt;br /&gt;  PRINT "Circumference = "; circum!&lt;br /&gt;  CIRCLE (320,240), radius!, INT(RND * 15 + 1)&lt;br /&gt;  DO: LOOP WHILE INKEY$ = ""&lt;br /&gt;  CLS&lt;br /&gt;  LOOP&lt;br /&gt;  COLOR 9: PRINT "Good Bye!"&lt;br /&gt;  END&lt;br /&gt;  &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;We first set the    screen graphics mode and generate a random seed number based on the system timer.    Then we prompt for the radius in a vivid bright white, and test to see if we    should end the program. We then calculate the area and circumference, and print    the results in yellow. Then we draw the circle from the middle of the screen    at the radius given in a random color. This random color is set by first generating    a random number from 0 to 14, adding 1 to it, and converting it to an integer    with the INT function. The next line seems weird. The INKEY$ statement reads    the keyboard and returns the string representation of the key pressed. We are    looping while INKEY$ is nothing, or in other words, while the user isn't pressing    anything. The loop goes on forever until the user presses any key, and at this    time a value will be given to INKEY$ which you might decide to use. The screen    is then cleared for the next entry. If the user breaks the loop by entering    -1 for the radius, we print Good Bye! in bright blue letters. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;There are a lot    more colors than just 16. In fact, you can change the values of each of the    16 colors to represent some other color that you specify. You do this with the    PALETTE statement. The following applies to screen modes 12 and 13. This statement    has two arguments: the color you want to change and the color you specify. Specifying    a color is the hard part. Here is my version of the syntax of the palette statement    &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;PALETTE color,    blueValue * 256 ^ 2 + greenValue * 256 + redValue &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;color is the color    you are changing. The _Values are numbers from 0 to 63 which specify the intensity    of that color. You must use the multipliers after the values and use the addition    operator to separate them. So lets make a program that fades the screen in and    out, from black to purple. (blue and red make purple). &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;SCREEN 12&lt;br /&gt;  DO&lt;br /&gt;  FOR i% = 1 TO 63&lt;br /&gt;  PALETTE 0, i% * 256 ^ 2 + i%&lt;br /&gt;  NEXT i%&lt;br /&gt;  FOR i% = 63 TO 1 STEP -1&lt;br /&gt;  PALETTE 0, i% * 256 ^ 2 + i%&lt;br /&gt;  NEXT i%&lt;br /&gt;  LOOP WHILE INKEY$ = ""&lt;br /&gt;  END &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;We start by changing    the value of black (0), which is the background color to purple, from one degree    of blue + red to the next. Then we bring it back down to black by decreasing    the blue + red value. We do this over and over until the user presses a key    or begins to have seizures. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Scaling and rotation    can be accomplished quite easily with the DRAW statement, although it involves    some weird looking code. First, lets define a shape that we can scale and rotate.    &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;box$ = "bu5    l5 d10 r10 u10 l5 bd5"&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Interpretation:    "move up 5 spaces without drawing, draw 5 spaces left, draw 10 spaces down,    draw 10 spaces right, draw 10 spaces up, draw 5 spaces left, and move 5 spaces    down without drawing." This forms a box. Notice that I started at the center    and not at a corner or side which would seem to be easier. Well, when you rotate    something, it draws based on the starting point of the object, and we want it    to rotate so if we put a pen at each corner of the box, it would draw a perfect    circle. Therefore we set the center of the box as the starting point of the    object. I call this the "object handle," not to be confused with the    handle used in the Windows API. The ta draw command stands for "turn angle,"    and obviously turns the object in the degrees you specify. So if we turned the    box from 0 to 360 degrees, drawing the box at each step and erasing the previous    image, we would get a rotating box. But we need one more function: VARPTR$.    VARPTR$ stands for "variable pointer," a term you can completely ignore    unless you get into C or Assembly programming. We need to somehow get the box$    shape into the draw string command we use implement in the loop, so we have    to take the address of the object string and plug it into the draw string. This    can be accomplished by using the X command, which tells VARPTR$ where to plug    in the string's address so it can be used. With box$ defined above, here's the    code for a rotating box: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;DO&lt;br /&gt;  angle% = angle% + 1&lt;br /&gt;  IF angle% &gt;= 360 THEN angle% = 1&lt;br /&gt;  DRAW "c0 bm320,240 ta" + STR$(angle% - 1) + "X" + VARPTR$(box$)&lt;br /&gt;  DRAW "c1 bm320,240 ta" + STR$(angle%) + "X" + VARPTR$(box$)&lt;br /&gt;  LOOP WHILE INKEY$ = ""&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Not that hard is    it? We draw the box at the previous angle in black, and then draw the box at    the current angle in blue. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Scaling is done    pretty much the same way, but instead of changing the angle and erasing the    previous image, we change the scale factor and erase the previous image. Recall    that the default scale factor for the DRAW statement is 4 pixels per unit. Well,    if we increase this factor then we will have more pixels per unit, thus giving    the image the effect of enlargement. So if we set up a FOR...NEXT loop which    will increase the scale factor from 2 to, say, 200, we will get the effect of    scaling. But lets start with a smaller image which is maybe 8 pixels wide from    the start instead of 40 so we get a more dramatic effect. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;SCREEN 12&lt;br /&gt;  box$ = "bu4 l4 d8 r8 u8 l4 bd4"&lt;br /&gt;  FOR s% = 2 TO 200&lt;br /&gt;  DRAW "c0 bm320,240 s" + STR$(s% - 1) + "X" + VARPTR$(box$)&lt;br /&gt;  DRAW "c2 bm320,240 s" + STR$(s%) + "X" + VARPTR$(box$)&lt;br /&gt;  NEXT s%&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Notice what we're    doing here. We are starting the scale factor at one half of default (2) because    the FOR...NEXT loop starts with s% at 2. The s draw command sets the scale factor.    Notice also that we must continuously anchor the object handle at a point to    keep it scaling about the handle. We do this by moving the object handle to    320,240 (center of screen) each time through the loop. Whenever we want to put    a number into the draw string, we must concatenate the string format (STR$)    of the number within the string. Instead of concatenating the box$ with the    rest of the string, it is faster to only pass the address of the substring with    the VARPTR$ function. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;So what if you    want to scale and rotate something at the same time? Simple, just set up a FOR...NEXT    loop which increases the scale factor as before, and within the loop increase    the angle. But instead of subtracting a factor for the angle to erase the previous    angle, lets do it this way: erase the previous image with the current angle,    increase the angle, then draw the current image with the new current angle.    This way if we want to change the factor at which the angle increases, we will    only have to change one number instead of two &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;SCREEN 12&lt;br /&gt;  box$ = "bu4 l4 d8 r8 u8 l4 bd4"&lt;br /&gt;  FOR s% = 2 TO 250&lt;br /&gt;  DRAW "c0 bm320,240 ta" + STR$(a%) + "s" + STR$(s% - 1) +    "X" + VARPTR$(box$)&lt;br /&gt;  a% = a% + 1&lt;br /&gt;  IF a% &gt;= 360 THEN a% = 1&lt;br /&gt;  DRAW "c1 bm320,240 ta" + STR$(a%) + "s" + STR$(s%) + "X"    + VARPTR$(box$)&lt;br /&gt;  NEXT s%&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Try it out! Draw    strings can get fairly complex, but you'll get used to them with practice and    when you memorize the draw string commands. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The screen coordinates    for different screen modes can be fairly difficult to work with, and they do    tend to be weird numbers. To make your code simpler to write, you can define    a logical plane over the physical plane. An example of a physical plane is the    640x480 resolution established by the SCREEN 12 screen mode. You can define    a logical, or alternate user-defined plane with the WINDOW statement. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;SCREEN 12&lt;br /&gt;  WINDOW (0,0)-(100,100)&lt;br /&gt;  CIRCLE (50,50),10,4&lt;br /&gt;  LINE (0,0)-(50,50),2&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This trivial example    defines a logical plane which is 100x100. 50,50 is now the center of the screen,    so this draws a red circle from the center with a radius of 10. The line statement    draws a green line from the lower left corner to the center of the screen. Notice    that defining a logical plane sets the origin (0,0) to the bottom left of the    screen, instead of the default upper left. If you want the origin to be in the    upper left with a logical plane, add the SCREEN keyword after WINDOW. So to    define the graphics mode 12 screen resolution, the code is: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;SCREEN 12&lt;br /&gt;  WINDOW SCREEN (0,0)-(640,480)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Use whatever is    more comfortable, but I would recommend using WINDOW SCREEN because there is    less confusion when converting from logical to physical planes. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Finally, a little    information on creating DRAW effects with the other QBasic graphics routines.    Hope you know some trigonometry for this part. Recall that in the unit circle,    which has a radius of 1, that the coordinates of a point on the circle given    an angle is defined as ( COS(angle), SIN(angle) ). Furthermore, if we are given    a point on the circle, we can find the angle by drawing a vertical line perpendicular    to the x axis from the point. If we take the arctangent of the vertical length    of this line divided by the horizontal distance of this line from the origin,    we will get the angle. So the angle is defined as ATN(Y/X). With this knowledge,    it would be possible to create a spinning line using only the line command.    If we create a loop which increments the angle from 0 to 360 then we can take    to COS,SIN of the angle to get the point we should draw to. But there's only    one more problem. The QBasic functions COS and SIN think in radians, so we must    first convert the angle to radians by multiplying PI / 180. That is quite easily    done . Here is the code: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;SCREEN 12&lt;br /&gt;  CONST PI = 3.1415&lt;br /&gt;  WINDOW SCREEN (-1,1)-(1,-1)&lt;br /&gt;  DO&lt;br /&gt;  LINE (0,0)-(COS(a% * PI / 180),SIN(a% * PI / 180)), 0&lt;br /&gt;  a% = a% + 1&lt;br /&gt;  IF a% &gt;= 360 THEN a% = 1&lt;br /&gt;  LINE (0,0)-(COS(a% * PI / 180),SIN(a% * PI / 180)), 14&lt;br /&gt;  LOOP WHILE INKEY$ = ""&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;We start by initializing    the graphics mode, then defining PI as a constant - a variable which will never    change in the program execution. Then define the logical plane, and start the    loop. The line starts from the center of the screen and goes to the coordinate    specified by the COS,SIN of the angle. We loop until the user presses a key.    &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;There is one more    type of graphics that QBasic has a strong point for : text. Graphical effects    can be made quite easily using only text in QBasic. There are a few functions    that are quite useful when dealing with text. The first is the CHR$ function.    If you pass a number to the CHR$ function, it will return the ASCII (American    standard code for information interchange) text value of that number. To find    a listing of the ASCII character codes, look in the help contents, and there    is a listing there. For example, to print a smiley face on the screen, the code    is this: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CLS&lt;br /&gt;  PRINT CHR$(1)&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Since the ASCII    character code for a smiley face is 1, you can use the CHR$ function to get    this. Another useful function is ASC, which returns the ASCII value of a text    value you pass to it. So ASC("A") will return 65 because the ASCII    value of A is 65. Every printable character (and then some) have an ASCII value,    so these two functions make it quite easy. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Finally, the LOCATE    statement is extremely useful for any text based program. LOCATE sets the text    CP to the coordinates you specify. The first argument is the column, and the    second is the row. So &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CLS&lt;br /&gt;  LOCATE 5,10&lt;br /&gt;  PRINT CHR$(219)&lt;br /&gt;  END&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Will print a solid    white block at column 5, row 10. And that's it for graphics! You now know nearly    every graphics routine in QBasic, and have the knowledge to make a game or highly    graphical program. Graphics depend on how you arrange them, so it requires an    artistic skill to some degree. If you get creative with these graphics commands,    you can create nearly any effect you need. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;b&gt; &lt;a name="designing"&gt;&lt;/a&gt;DESIGNING    APPLICATIONS&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;It is not practical    in real world terms to set up an application in one long list of code. Many    early programming languages were purely linear, meaning that they started from    one point on a list of code, and ended at another point. All of the code I have    written in this tutorial so far has been purely linear. However, linear programming    is not practical in a team environment. If one person could write one aspect    of code, and another write another part of the program, things would be much    more organized. QBasic contains the capability to meet these needs, called modular    programming. You can break a program into different "modules" which    are separate from the main program and yet can be accessed by any part of it.    I highly recommend the use of separate modules in programming applications,    although it is not a simple task to learn. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;These separate    modules are also known as procedures in the QBasic environment. There are two    types of procedures: subs and functions. Subs merely execute a task and return    to the main program, which functions execute a task and return a value to the    main program. An example of a sub might be a procedure which displays a title    screen on the screen, while a function may be a procedure that returns a degree    in degrees given a number in radians. Function procedures are also used in Calculus,    so you Calculus people should already be familiar with functions. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Procedures can    accept arguments in what is called an argument list. Each argument in the argument    list has a defined type, and an object of that type must be passed to the procedure    when it is called. For example, the CHR$ QBasic function accepts a numeric argument.    The function itself converts this numeric argument into a string representation    of the ASCII value of the number passed, and returns this one character string.    &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Procedures in QBasic    are given their own screen. When you enter the QBasic IDE, you are in the main    procedure which can access all the others. Other procedures are created by typing    the type of procedure (SUB or FUNCTION), the procedure name, followed by the    complete argument list. You can view your procedures through the VIEW menu.    Here is an example of a sub procedure which performs some operations for a program    that will be using graphics, random numbers, and a logical plane. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;SUB initProgram()&lt;br /&gt;  RANDOMIZE TIMER&lt;br /&gt;  SCREEN 12&lt;br /&gt;  WINDOW (0,0)-(100,100)&lt;br /&gt;  COLOR 15&lt;br /&gt;  END SUB&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The only thing    you need to type is SUB initProgram (), and the screen will be switched to that    procedure. The END SUB is placed there for you, so the only thing you need to    type then is the code within the sub. Try typing this out on your own to see    how this works. This procedure is called by simply typing initProgram in the    main procedure. An alternative method is CALL initProcedure (). Right here the    parentheses are optional, but if you were to pass arguments to the procedure,    parentheses would be required with the CALL statement. Now lets try passing    an argument to a procedure. We will pass two arguments to a procedure called    center which are a string containing the text to be centered, and the horizontal    location on the screen at which you wish to center it. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;SUB center( text$,    hLoc% )&lt;br /&gt;  LOCATE hLoc%, 41 - (LEN(text$) / 2)&lt;br /&gt;  PRINT text$&lt;br /&gt;  END SUB&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The first line    after the sub declaration positions the starting point of the text at the horizontal    location we passed at the second argument and vertical coordinate. The vertical    coordinate is calculated by subtracting one half the screen's width in characters    (41) and half the LENgth of the text we passed as the first argument. We would    call center from the main procedure like this: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;center "Programmed    by qp7@pobox.com", 12&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Or like this &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CALL center ("Programmed    by qp7@pobox.com", 12)&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;It's quite simple    actually. Functions are slightly different and involve an additional part which    subs do not: a return value. The return value is specified by assigning the    value you want to return to the function name from within the function definition.    When calling the function from within the main procedure, the name of the function    is treated as a value which is evaluated at compile-time. Here is an example    of a function definition: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;FUNCTION convert.To.Radians    (degree!)&lt;br /&gt;  LET PI = 3.1415&lt;br /&gt;  convert.To.Radians = degree! * PI / 180&lt;br /&gt;  END SUB&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The function is    implicitly called in this program &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;CLS&lt;br /&gt;  INPUT "Enter a value in degrees: ", degreeValue!&lt;br /&gt;  radianValue! = convert.To.Radians(degreeValue!)&lt;br /&gt;  PRINT "The radian equivalent is"; radianValue!; "radians"&lt;br /&gt
