<?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'><id>tag:blogger.com,1999:blog-1165683755437997580</id><updated>2009-10-14T00:30:52.846-07:00</updated><title type='text'>Some Logics We Need</title><subtitle type='html'>Get all latest information on C++ programming. All advanced logic and source codes for C / C++ programming.
Also oracle, Java ,Linux ,Windows, Games etc</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://somelogics.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default'/><link rel='alternate' type='text/html' href='http://somelogics.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Priyank</name><uri>http://www.blogger.com/profile/16749090935925725720</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1165683755437997580.post-6502832571145867963</id><published>2008-12-04T06:55:00.001-08:00</published><updated>2008-12-04T06:59:25.489-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Index'/><title type='text'>Quick Contents</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://somelogics.blogspot.com/"&gt;&lt;img style="cursor: pointer; width: 320px; height: 73px;" src="http://1.bp.blogspot.com/_N6ah0svGQ54/STfvJVDCavI/AAAAAAAAAA8/2pqX-MhT6jI/s320/logo.JPG" alt="" id="BLOGGER_PHOTO_ID_5275948432035572466" border="0"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://somelogics.blogspot.com/2008/12/INDEX.html"&gt;&lt;br /&gt;&lt;/a&gt;&lt;h1&gt; &lt;/h1&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://somelogics.blogspot.com/2008/12/INDEX.html"&gt;&lt;img style="cursor: pointer; width: 274px; height: 48px;" src="http://4.bp.blogspot.com/_N6ah0svGQ54/STeZfpkcsZI/AAAAAAAAAAc/XnL3uGjgq-o/s320/C%2B%2B+1.2.bmp" alt="" id="BLOGGER_PHOTO_ID_5275854257501548946" border="0"&gt;&lt;/a&gt;&lt;br /&gt;&lt;font style="font-weight: bold; color: rgb(204, 0, 0);" size="4"&gt;&lt;br /&gt;Please Click on the links below to see details :-&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font style="font-weight: bold; color: rgb(0, 0, 102);"&gt;&lt;font style="color: rgb(204, 51, 204);"&gt;I&lt;/font&gt; Some basic Concepts Of C++&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font face="trebuchet ms"&gt;1.&lt;/font&gt;&lt;a style="font-family: trebuchet ms;" href="http://somelogics.blogspot.com/2008/12/introduction-to-c.html"&gt; An introduction to C++&lt;/a&gt;&lt;br /&gt;               1.1 &lt;a href="http://somelogics.blogspot.com/2008/12/introducing-c.html"&gt;Another article on introduction&lt;/a&gt;&lt;br /&gt;&lt;font face="trebuchet ms"&gt;2. &lt;/font&gt;&lt;a style="font-family: trebuchet ms;" href="http://somelogics.blogspot.com/2008/12/structure-of-program-first-program.html"&gt;Structure of a program- The first program&lt;/a&gt;&lt;br /&gt;&lt;font face="trebuchet ms"&gt;3. &lt;/font&gt;&lt;a style="font-family: trebuchet ms;" href="http://somelogics.blogspot.com/2008/12/data-types.html"&gt;Data Types&lt;/a&gt;&lt;br /&gt;4. &lt;a href="http://somelogics.blogspot.com/2008/12/constants.html"&gt;Constants&lt;/a&gt;&lt;br /&gt;5. &lt;a href="http://somelogics.blogspot.com/2008/12/language-comparisons.html"&gt;Language Comparisons&lt;/a&gt;&lt;br /&gt;                    5.1 &lt;a href="http://somelogics.blogspot.com/2008/12/comparison-with-c.html"&gt;Comparison with C&lt;/a&gt;&lt;br /&gt;                             5.2 &lt;a href="http://somelogics.blogspot.com/2008/12/comparison-with-java.html"&gt;Comparison with Java&lt;/a&gt;&lt;br /&gt;              5.3 &lt;a href="http://somelogics.blogspot.com/2008/12/some-documentation.html"&gt;Some Dcumentation&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;General information about the C++ programming language, including non-technical documents and descriptions:&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1165683755437997580-6502832571145867963?l=somelogics.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://somelogics.blogspot.com/feeds/6502832571145867963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://somelogics.blogspot.com/2008/12/please-click-on-links-below-to-see.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/6502832571145867963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/6502832571145867963'/><link rel='alternate' type='text/html' href='http://somelogics.blogspot.com/2008/12/please-click-on-links-below-to-see.html' title='Quick Contents'/><author><name>Priyank</name><uri>http://www.blogger.com/profile/16749090935925725720</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='12361015692322800765'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_N6ah0svGQ54/STfvJVDCavI/AAAAAAAAAA8/2pqX-MhT6jI/s72-c/logo.JPG' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1165683755437997580.post-9097749688160299795</id><published>2008-12-04T06:50:00.000-08:00</published><updated>2008-12-10T17:46:46.353-08:00</updated><title type='text'></title><content type='html'>&lt;a href="http://somelogics.blogspot.com/" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5275947659843550082" src="http://2.bp.blogspot.com/_N6ah0svGQ54/STfucYaHO4I/AAAAAAAAAAs/U63ugO9thuQ/s320/logo.JPG" style="cursor: pointer; height: 77px; width: 337px;" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Please Click on the links below to see details :-&lt;br /&gt;&lt;br /&gt;I Some basic Concepts Of C++&lt;br /&gt;&lt;br /&gt;1. An introduction to C++&lt;br /&gt;1.1 Another article on introduction&lt;br /&gt;2. Structure of a program- The first program&lt;br /&gt;3. Data Types&lt;br /&gt;4. Constants&lt;br /&gt;5. Language Comparisons&lt;br /&gt;5.1 Comparison with C&lt;br /&gt;5.2 Comparison with Java&lt;br /&gt;5.3 Some Dcumentation&lt;br /&gt;&lt;br /&gt;General information about the C++ programming language, including non-technical documents and descriptions:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.awsurveys.com/HomeMain.cfm?RefID=remember.priyank"&gt; $6.00 Welcome Survey After Free Registration!&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1165683755437997580-9097749688160299795?l=somelogics.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://somelogics.blogspot.com/feeds/9097749688160299795/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://somelogics.blogspot.com/2008/12/please-click-on-links-below-to-see_04.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/9097749688160299795'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/9097749688160299795'/><link rel='alternate' type='text/html' href='http://somelogics.blogspot.com/2008/12/please-click-on-links-below-to-see_04.html' title=''/><author><name>Priyank</name><uri>http://www.blogger.com/profile/16749090935925725720</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='12361015692322800765'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_N6ah0svGQ54/STfucYaHO4I/AAAAAAAAAAs/U63ugO9thuQ/s72-c/logo.JPG' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1165683755437997580.post-6943452102750967481</id><published>2008-12-04T06:48:00.001-08:00</published><updated>2008-12-04T06:49:33.121-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++ programming'/><title type='text'>Some Documentation</title><content type='html'>&lt;h3&gt;&lt;span class="mw-headline"&gt;Document your code&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;There are a number of good reasons to document your code, and a number of aspects of it that can be documented. Documentation provides you with a shortcut for obtaining an overview of the system or for understanding the code that provides a particular feature.&lt;/p&gt; &lt;p&gt;&lt;a name="Why_.3F" id="Why_.3F"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h4&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline"&gt;Why ?&lt;/span&gt;&lt;/h4&gt; &lt;p&gt;The purpose of comments is to explain and clarify the source code to anyone examining it (or just as a reminder to yourself). Good commenting conventions are essential to any non-trivial program so that a person reading the code can understand what it is expected to do and to make it easy to follow on the rest of the code. In the next topics some of the most &lt;b&gt;How?&lt;/b&gt; and &lt;b&gt;When?&lt;/b&gt; rules to use comments will be listed for you.&lt;/p&gt; &lt;p&gt;Documentation of programming is essential when programming not just just in C++, but in any programming language. Many companies have moved away from the idea of "hero programmers" (i.e., one programmer who codes for the entire company) to a concept of groups of programmers working in a team. Many times programmers will only be working on small parts of a larger project. In this particular case, documentation is essential because:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;Other programmers may be tasked to develop your project;&lt;/li&gt;&lt;li&gt;Your finished project may be submitted to editors to assemble your code into other projects;&lt;/li&gt;&lt;li&gt;A person other than you may be required to read, understand, and present your code.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Even if you are not programming for a living or for a company, documentation of your code is still essential. Though many programs can be completed in a few hours, more complex programs can take longer time to complete (days, weeks, etc.). In this case, documentation is essential because:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;You may not be able to work on your project in one sitting;&lt;/li&gt;&lt;li&gt;It provides a reference to what was changed the last time you programmed;&lt;/li&gt;&lt;li&gt;It allows you to record &lt;i&gt;why&lt;/i&gt; you made the decisions you did, including why you chose &lt;b&gt;not&lt;/b&gt; to explore certain solutions;&lt;/li&gt;&lt;li&gt;It can provide a place to document known limitations and bugs (for the latter a defect tracking system may be the appropriate place for documentation);&lt;/li&gt;&lt;li&gt;It allows easy searching and referencing within the program (from a non-technical stance);&lt;/li&gt;&lt;li&gt;It is considered to be good programming practice.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a name="Comments_Should_Be_Written_For_the_Appropriate_Audience" id="Comments_Should_Be_Written_For_the_Appropriate_Audience"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h5&gt;&lt;span class="editsection"&gt;&lt;/span&gt; &lt;span class="mw-headline"&gt;Comments Should Be Written For the Appropriate Audience&lt;/span&gt;&lt;/h5&gt; &lt;p&gt;When writing code to be read by those who are in the initial stages of learning a new programming language, it can be helpful to include a lot of comments about what the code does. For "production" code, written to be read by professionals, it is considered unhelpful and counterproductive to include comments which say things that are already clear in the code. Some from the &lt;span class="extiw"&gt;Extreme Programming&lt;/span&gt; community say that excessive commenting is indicative of &lt;span class="extiw"&gt;code smell&lt;/span&gt; -- which is &lt;i&gt;not&lt;/i&gt; to say that comments are bad, but that they are often a clue that code would benefit from &lt;span class="extiw"&gt;refactoring&lt;/span&gt;. Adding comments as an alternative to writing understandable code is considered poor practice.&lt;/p&gt; &lt;p&gt;&lt;a name="What.3F" id="What.3F"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h4&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline"&gt;What?&lt;/span&gt;&lt;/h4&gt; &lt;p&gt;What needs to be documented in a program/source code can be divided into what is documented before the specific program execution (that is before "main") and what is executed ("what is in main").&lt;/p&gt; &lt;p&gt;Documentation before program execution:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;Programmer information and license information (if applicable)&lt;/li&gt;&lt;li&gt;User defined function declarations&lt;/li&gt;&lt;li&gt;Interfaces&lt;/li&gt;&lt;li&gt;Context&lt;/li&gt;&lt;li&gt;Relevant standards/specifications&lt;/li&gt;&lt;li&gt;Algorithm steps&lt;/li&gt;&lt;li&gt;How to convert the source code into executable file(s) (perhaps by using make)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Documentation for code inside main:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;Statements, Loops, and Cases&lt;/li&gt;&lt;li&gt;Public and Private Sectors within Classes&lt;/li&gt;&lt;li&gt;Algorithms used&lt;/li&gt;&lt;li&gt;Unusual features of the implementation&lt;/li&gt;&lt;li&gt;Reasons why other choices have been avoided&lt;/li&gt;&lt;li&gt;User defined function implementation&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;If used carelessly comments can make source code hard to read and maintain and may be even unnecessary if the code is self-explanatory -- but remember that what seems self-explanatory today may not seem the same six months or six years from now.&lt;/p&gt; &lt;p&gt;&lt;a name="Document_Decisions" id="Document_Decisions"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h5&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline"&gt;Document Decisions&lt;/span&gt;&lt;/h5&gt; &lt;p&gt;Comments should document decisions. At every point where you had a choice of what to do place a comment describing which choice you made and why. Archaeologists will find this the most useful information.&lt;/p&gt; &lt;p&gt;&lt;a name="Comment_Layout" id="Comment_Layout"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h5&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline"&gt;Comment Layout&lt;/span&gt;&lt;/h5&gt; &lt;p&gt;Each part of the project should at least have a single comment layout, and it would be better yet to have the complete project share the same layout if possible.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h4&gt;&lt;span class="mw-headline"&gt;How ?&lt;/span&gt;&lt;/h4&gt; &lt;p&gt;Documentation can be done within the source code itself through the use of comments as seen above. Comments are useful in documenting portions of an algorithm to be executed, explaining function calls and variable names, or providing reasons as to why a specific choice or method was used. Block comments are used as follows:&lt;/p&gt; &lt;div dir="ltr" style="text-align: left;"&gt; &lt;pre class="source-cpp"&gt;&lt;span class="coMULTI"&gt;/*&lt;br /&gt;get timepunch algorithm - this algorithm gets a time punch for use later&lt;br /&gt;1. user enters their number and selects "in" or "out"&lt;br /&gt;2. time is retrieved from the computer&lt;br /&gt;3. time punch is assigned to user&lt;br /&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p&gt;Alternately, line comments can be used as follows:&lt;/p&gt; &lt;div dir="ltr" style="text-align: left;"&gt; &lt;pre class="source-cpp"&gt;GetPunch&lt;span class="br0"&gt;(&lt;/span&gt;user_id, &lt;span class="kw3"&gt;time&lt;/span&gt;, punch&lt;span class="br0"&gt;)&lt;/span&gt;; &lt;span class="co1"&gt;//this function gets the time punch&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p&gt;An example of a full program using comments as documentation is:&lt;/p&gt; &lt;div dir="ltr" style="text-align: left;"&gt; &lt;pre class="source-cpp"&gt;&lt;span class="coMULTI"&gt;/*&lt;br /&gt;Chris Seedyk&lt;br /&gt;BORD Technologies&lt;br /&gt;29 December 2006&lt;br /&gt;Test&lt;br /&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span class="kw4"&gt;int&lt;/span&gt; main&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span class="kw3"&gt;cout&lt;/span&gt; &lt;&lt; &lt;span class="st0"&gt;"Hello world!"&lt;/span&gt; &lt;&lt; class="co1"&gt;//predefined cout prints stuff in " " to screen&lt;/span&gt;&lt;br /&gt;&lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="nu0"&gt;0&lt;/span&gt;;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p&gt;It should be noted that while comments are useful for in-program documentation, it is also a good idea to have an external form of documentation separate from the source code as well. Commenting code is also no substitute for well-planned and meaningful variable, function, and class names. This is often called "self-documenting code," as it is easy to see from a carefully chosen and descriptive name what the variable, function, or class is meant to do. To illustrate this point, note the relatively equal simplicity with which the following two ways of documenting code, despite the use of comments in the first and their absence in the second, are understood. The first style is often encountered in very old C source by people who understood well what they were doing and had no doubt anyone else might not comprehend it. The second style is more "human-friendly" and while much easier to read is nevertheless not as frequently encountered.&lt;/p&gt; &lt;div dir="ltr" style="text-align: left;"&gt; &lt;pre class="source-cpp"&gt;&lt;span class="co1"&gt;// Returns the area of a triangle cast as an int&lt;/span&gt;&lt;br /&gt;&lt;span class="kw4"&gt;int&lt;/span&gt; area_ftoi&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw4"&gt;float&lt;/span&gt; a, &lt;span class="kw4"&gt;float&lt;/span&gt; b&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="br0"&gt;{&lt;/span&gt; &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw4"&gt;int&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; a * b / &lt;span class="nu0"&gt;2&lt;/span&gt;; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kw4"&gt;int&lt;/span&gt; iTriangleArea&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw4"&gt;float&lt;/span&gt; fBase, &lt;span class="kw4"&gt;float&lt;/span&gt; fHeight&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;  &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="kw4"&gt;int&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; fBase * fHeight / &lt;span class="nu0"&gt;2&lt;/span&gt;;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p&gt;Both functions perform the same task, however the second has such practical names chosen for the function and the variables that its purpose is clear even without comments. As the complexity of the code increases, well-chosen naming schemes increase vastly in importance.&lt;/p&gt; &lt;p&gt;Regardless of what method is preferred, comments in code are helpful, save time (and headaches), and ensure that both the author and others understand the layout and purpose of the program fully.&lt;/p&gt; &lt;p&gt;&lt;a name="Automatic_Documentation" id="Automatic_Documentation"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h5&gt;&lt;span class="editsection"&gt;[edit]&lt;/span&gt; &lt;span class="mw-headline"&gt;Automatic Documentation&lt;/span&gt;&lt;/h5&gt; &lt;p&gt;Various tools are available to help with documenting C++ code; &lt;span class="extiw"&gt;Literate Programming&lt;/span&gt; is a whole school of thought on how to approach this, but a very effective tool is &lt;span class="external text"&gt;Doxygen&lt;/span&gt; (also supports several languages), it can even use hand written comments in order to generate more than the bare structure of the code, bringing Javadoc-like documentation comments to C++ and can generate documentation in HTML, PDF and other formats.&lt;/p&gt; &lt;p&gt;&lt;a name="Comments_Should_Tell_a_Story" id="Comments_Should_Tell_a_Story"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h5&gt;&lt;span class="editsection"&gt;[edit]&lt;/span&gt; &lt;span class="mw-headline"&gt;Comments Should Tell a Story&lt;/span&gt;&lt;/h5&gt; &lt;p&gt;Consider your comments a story describing the system. Expect your comments to be extracted by a robot and formed into a manual page. Class comments are one part of the story, method signature comments are another part of the story, method arguments another part, and method implementation yet another part. All these parts should weave together and inform someone else at another point of time just exactly what you did and why.&lt;/p&gt; &lt;dl&gt;&lt;dt&gt;Do not use comments for flowcharts or pseudocode&lt;/dt&gt;&lt;/dl&gt; &lt;p&gt;You should refrain from using comments to do ASCII art or pseudocode (some programmers attempt to explain their code with an ASCII-art flowchart). If you want to flowchart or otherwise model your design there are tools that will do a better job at it using standardized methods. See for example: &lt;a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language" class="extiw" title="w:Unified Modeling Language"&gt;UML&lt;/a&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1165683755437997580-6943452102750967481?l=somelogics.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://somelogics.blogspot.com/feeds/6943452102750967481/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://somelogics.blogspot.com/2008/12/some-documentation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/6943452102750967481'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/6943452102750967481'/><link rel='alternate' type='text/html' href='http://somelogics.blogspot.com/2008/12/some-documentation.html' title='Some Documentation'/><author><name>Priyank</name><uri>http://www.blogger.com/profile/16749090935925725720</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='12361015692322800765'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1165683755437997580.post-8604566582710080850</id><published>2008-12-04T06:44:00.000-08:00</published><updated>2008-12-04T06:46:57.472-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++ programming'/><title type='text'>Comparison with Java</title><content type='html'>&lt;h4&gt;&lt;span class="mw-headline"&gt;Java&lt;/span&gt;&lt;/h4&gt; &lt;p&gt;This is a comparison of the &lt;a href="http://en.wikibooks.org/wiki/Java_Programming" title="Java Programming"&gt;Java programming language&lt;/a&gt; with the C++ programming language. C++ and Java share many common traits. You can get a better understanding of Java in the &lt;a href="http://en.wikibooks.org/wiki/Programming:Java" title="Programming:Java" class="mw-redirect"&gt;Java Programming WikiBook&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;&lt;b&gt;Java&lt;/b&gt; was created initially to support &lt;a href="http://en.wikipedia.org/wiki/network_computing" class="extiw" title="w:network computing"&gt;network computing&lt;/a&gt; on &lt;a href="http://en.wikipedia.org/wiki/embedded_system" class="extiw" title="w:embedded system"&gt;embedded systems&lt;/a&gt;. Java was designed to be extremely &lt;a href="http://en.wikipedia.org/wiki/porting" class="extiw" title="w:porting"&gt;portable&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/computer_security" class="extiw" title="w:computer security"&gt;secure&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/thread_%28computer_science%29" class="extiw" title="w:thread (computer science)"&gt;multi-threaded&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/distributed_computing" class="extiw" title="w:distributed computing"&gt;distributed&lt;/a&gt;, none of which were design goals for C++. The syntax of Java was chosen to be familiar to C programmers, but direct compatibility with C was not maintained. Java also was specifically designed to be simpler than C++ but it keeps evolving above that simplification.&lt;/p&gt; &lt;dl&gt;&lt;dd&gt; &lt;table class="wikitable"&gt; &lt;tbody&gt;&lt;tr&gt; &lt;th&gt;&lt;b&gt;C++&lt;/b&gt;&lt;/th&gt; &lt;th&gt;&lt;b&gt;Java&lt;/b&gt;&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;backwards compatible with C&lt;/td&gt; &lt;td&gt;backwards compatibility with previous versions&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;execution efficiency&lt;/td&gt; &lt;td&gt;developer productivity&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;trusts the programmer&lt;/td&gt; &lt;td&gt;restrains the programmer's abilities&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="http://en.wikipedia.org/wiki/pointer" class="extiw" title="w:pointer"&gt;arbitrary memory access possible&lt;/a&gt;&lt;/td&gt; &lt;td&gt;memory access only through objects&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;concise expression&lt;/td&gt; &lt;td&gt;explicit operation&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;can arbitrarily override types&lt;/td&gt; &lt;td&gt;&lt;a href="http://en.wikipedia.org/wiki/type_safety" class="extiw" title="w:type safety"&gt;type safety&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="http://en.wikipedia.org/wiki/procedural" class="extiw" title="w:procedural"&gt;procedural&lt;/a&gt; or &lt;a href="http://en.wikipedia.org/wiki/object-oriented" class="extiw" title="w:object-oriented"&gt;object-oriented&lt;/a&gt;&lt;/td&gt; &lt;td&gt;object-oriented&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="http://en.wikipedia.org/wiki/operator_overloading" class="extiw" title="w:operator overloading"&gt;operator overloading&lt;/a&gt;&lt;/td&gt; &lt;td&gt;meaning of operators immutable&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;powerful capabilities of language&lt;/td&gt; &lt;td&gt;feature-rich, easy to use standard library&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;p&gt;Differences between C++ and Java are:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;C++ parsing is somewhat more complicated than with Java; for example, &lt;code&gt;Foo&lt;1&gt;(3);&lt;/code&gt; is a sequence of comparisons if Foo is a variable, but it creates an object if Foo is the name of a class template.&lt;/li&gt;&lt;li&gt;C++ allows namespace level constants, variables, and functions. All such Java declarations must be inside a class or &lt;a href="http://en.wikipedia.org/wiki/interface_%28Java%29" class="extiw" title="w:interface (Java)"&gt;interface&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;&lt;code&gt;&lt;a href="http://en.wikipedia.org/wiki/const" class="extiw" title="w:const"&gt;const&lt;/a&gt;&lt;/code&gt; in C++ indicates data to be 'read-only,' and is applied to types. &lt;code&gt;final&lt;/code&gt; in java indicates that the variable is not to be reassigned. For basic types such as &lt;code&gt;const int&lt;/code&gt; vs &lt;code&gt;final int&lt;/code&gt; these are identical, but for complex classes, they are different.&lt;/li&gt;&lt;li&gt;C++ doesn't supports constructor delegation.&lt;/li&gt;&lt;li&gt;C++ runs on the hardware, Java runs on a virtual machine so with C++ you have greater power at the cost of portability.&lt;/li&gt;&lt;li&gt;C++, &lt;tt&gt;int main()&lt;/tt&gt; is a function by itself, without a class.&lt;/li&gt;&lt;li&gt;C++ access specification (&lt;b&gt;public&lt;/b&gt;, &lt;b&gt;private&lt;/b&gt;) is done with labels and in groups.&lt;/li&gt;&lt;li&gt;C++ access to class members default to &lt;tt&gt;private&lt;/tt&gt;, in Java it is &lt;tt&gt;protected&lt;/tt&gt;.&lt;/li&gt;&lt;li&gt;C++ classes declarations end in a semicolon.&lt;/li&gt;&lt;li&gt;C++ lacks language level support for garbage collection while Java has built-in garbage collection to handle memory deallocation.&lt;/li&gt;&lt;li&gt;C++ supports &lt;code&gt;&lt;a href="http://en.wikipedia.org/wiki/goto" class="extiw" title="w:goto"&gt;goto&lt;/a&gt;&lt;/code&gt; statements; Java does not, but its &lt;a href="http://en.wikipedia.org/wiki/labelled_break" class="extiw" title="w:labelled break"&gt;labeled break&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/labelled_continue" class="extiw" title="w:labelled continue"&gt;labeled continue&lt;/a&gt; statements provide some structured goto-like functionality. In fact, Java enforces &lt;a href="http://en.wikipedia.org/wiki/structured_control_flow" class="extiw" title="w:structured control flow"&gt;structured control flow&lt;/a&gt;, with the goal of code being easier to understand.&lt;/li&gt;&lt;li&gt;C++ provides some low-level features which Java lacks. In C++, pointers can be used to manipulate specific memory locations, a task necessary for writing low-level &lt;a href="http://en.wikipedia.org/wiki/operating_system" class="extiw" title="w:operating system"&gt;operating system&lt;/a&gt; components. Similarly, many C++ compilers support &lt;a href="http://en.wikipedia.org/wiki/inline_assembler" class="extiw" title="w:inline assembler"&gt;inline assembler&lt;/a&gt;. In Java, assembly code can still be accessed as libraries, through the &lt;a href="http://en.wikipedia.org/wiki/Java_Native_Interface" class="extiw" title="w:Java Native Interface"&gt;Java Native Interface&lt;/a&gt;. However, there is significant overhead for each call.&lt;/li&gt;&lt;li&gt;C++ allows a range of implicit conversions between native types, and also allows the programmer to define implicit conversions involving compound types. However, Java only permits widening conversions between native types to be implicit; any other conversions require explicit cast syntax. &lt;ul&gt;&lt;li&gt;A consequence of this is that although loop conditions (&lt;code&gt;if&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt; and the exit condition in &lt;code&gt;for&lt;/code&gt;) in Java and C++ both expect a boolean expression, code such as &lt;code&gt;if(a = 5)&lt;/code&gt; will cause a compile error in Java because there is no implicit narrowing conversion from int to boolean. This is handy if the code were a typo for &lt;code&gt;if(a == 5)&lt;/code&gt;, but the need for an explicit cast can add verbosity when statements such as &lt;code&gt;if (x)&lt;/code&gt; are translated from Java to C++.&lt;/li&gt;&lt;/ul&gt; &lt;/li&gt;&lt;li&gt;For passing parameters to functions, C++ supports both true &lt;a href="http://en.wikipedia.org/wiki/pass-by-reference" class="extiw" title="w:pass-by-reference"&gt;pass-by-reference&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/pass-by-value" class="extiw" title="w:pass-by-value"&gt;pass-by-value&lt;/a&gt;. As in C, the programmer can simulate by-reference parameters with by-value parameters and &lt;a href="http://en.wikipedia.org/wiki/indirection" class="extiw" title="w:indirection"&gt;indirection&lt;/a&gt;. In Java, all parameters are passed by value, but object (non-primitive) parameters are &lt;a href="http://en.wikipedia.org/wiki/reference_%28computer_science%29" class="extiw" title="w:reference (computer science)"&gt;reference&lt;/a&gt; values, meaning &lt;a href="http://en.wikipedia.org/wiki/indirection" class="extiw" title="w:indirection"&gt;indirection&lt;/a&gt; is built-in.&lt;/li&gt;&lt;li&gt;Generally, Java built-in types are of a specified size and range; whereas C++ types have a variety of possible sizes, ranges and representations, which may even change between different versions of the same compiler, or be configurable via compiler switches. &lt;ul&gt;&lt;li&gt;In particular, Java characters are 16-bit &lt;a href="http://en.wikipedia.org/wiki/Unicode" class="extiw" title="w:Unicode"&gt;Unicode&lt;/a&gt; characters, and strings are composed of a sequence of such characters. C++ offers both narrow and wide characters, but the actual size of each is platform dependent, as is the character set used. Strings can be formed from either type.&lt;/li&gt;&lt;/ul&gt; &lt;/li&gt;&lt;li&gt;The rounding and precision of floating point values and operations in C++ is platform dependent. Java provides a &lt;a href="http://en.wikipedia.org/wiki/strictfp" class="extiw" title="w:strictfp"&gt;strict floating-point model&lt;/a&gt; that guarantees consistent results across platforms, though normally a more lenient mode of operation is used to allow optimal floating-point performance.&lt;/li&gt;&lt;li&gt;In C++, &lt;a href="http://en.wikipedia.org/wiki/pointers" class="extiw" title="w:pointers"&gt;pointers&lt;/a&gt; can be manipulated directly as memory address values. Java does not have pointers—it only has object references and array references, neither of which allow direct access to memory addresses. In C++ one can construct pointers to pointers, while Java references only access objects.&lt;/li&gt;&lt;li&gt;In C++ pointers can point to functions or member functions (&lt;a href="http://en.wikipedia.org/wiki/function_pointer" class="extiw" title="w:function pointer"&gt;function pointers&lt;/a&gt; or &lt;a href="http://en.wikipedia.org/wiki/functor" class="extiw" title="w:functor"&gt;functors&lt;/a&gt;). The equivalent mechanism in Java uses object or interface references.&lt;/li&gt;&lt;li&gt;C++ features programmer-defined &lt;a href="http://en.wikipedia.org/wiki/operator_overloading" class="extiw" title="w:operator overloading"&gt;operator overloading&lt;/a&gt;. The only overloaded operators in Java are the "&lt;code&gt;+&lt;/code&gt;" and "&lt;code&gt;+=&lt;/code&gt;" operators, which concatenate strings as well as performing addition.&lt;/li&gt;&lt;li&gt;Java features standard &lt;a href="http://en.wikipedia.org/wiki/Application_programming_interface" class="extiw" title="w:Application programming interface"&gt;API&lt;/a&gt; support for &lt;a href="http://en.wikipedia.org/wiki/Reflection_%28computer_science%29" class="extiw" title="w:Reflection (computer science)"&gt;reflection&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/dynamic_loading" class="extiw" title="w:dynamic loading"&gt;w:dynamic loading&lt;/a&gt; of arbitrary new code.&lt;/li&gt;&lt;li&gt;Java has generics. C++ has templates.&lt;/li&gt;&lt;li&gt;Both Java and C++ distinguish between native types (these are also known as "fundamental" or "built-in" types) and user-defined types (these are also known as "compound" types). In Java, native types have value semantics only, and compound types have reference semantics only. In C++ all types have value semantics, but a reference can be created to any object, which will allow the object to be manipulated via reference semantics.&lt;/li&gt;&lt;li&gt;C++ supports &lt;a href="http://en.wikipedia.org/wiki/multiple_inheritance" class="extiw" title="w:multiple inheritance"&gt;multiple inheritance&lt;/a&gt; of arbitrary classes. Java supports multiple inheritance of types, but only single inheritance of implementation. In Java a class can derive from only one class, but a class can implement multiple &lt;a href="http://en.wikipedia.org/wiki/Interface_%28Java%29" class="extiw" title="w:Interface (Java)"&gt;interfaces&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;Java explicitly distinguishes between interfaces and classes. In C++ multiple inheritance and pure virtual functions makes it possible to define classes that function just as Java interfaces do.&lt;/li&gt;&lt;li&gt;Java has both language and standard library support for &lt;a href="http://en.wikipedia.org/wiki/multi-threading" class="extiw" title="w:multi-threading"&gt;multi-threading&lt;/a&gt;. The &lt;code&gt;synchronized&lt;/code&gt; &lt;a href="http://en.wikipedia.org/wiki/Java_keywords" class="extiw" title="w:Java keywords"&gt;keyword in Java&lt;/a&gt; provides simple and secure &lt;a href="http://en.wikipedia.org/wiki/Mutual_exclusion" class="extiw" title="w:Mutual exclusion"&gt;mutex locks&lt;/a&gt; to support multi-threaded applications. While mutex lock mechanisms are available through libraries in C++, the lack of language semantics makes writing &lt;a href="http://en.wikipedia.org/wiki/thread_safe" class="extiw" title="w:thread safe"&gt;thread safe&lt;/a&gt; code more difficult and error prone.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a name="Memory_management" id="Memory_management"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h5&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline"&gt;Memory management&lt;/span&gt;&lt;/h5&gt; &lt;ul&gt;&lt;li&gt;Java requires automatic &lt;a href="http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29" class="extiw" title="w:Garbage collection (computer science)"&gt;garbage collection&lt;/a&gt;. Memory management in C++ is usually done by hand, or through &lt;a href="http://en.wikipedia.org/wiki/smart_pointer" class="extiw" title="w:smart pointer"&gt;smart pointers&lt;/a&gt;. The C++ standard permits garbage collection, but does not require it; garbage collection is rarely used in practice. When permitted to relocate objects, modern garbage collectors can improve overall application space and time efficiency over using explicit deallocation.&lt;/li&gt;&lt;li&gt;C++ can allocate arbitrary blocks of memory. Java only allocates memory through object instantiation. (Note that in Java, the programmer can simulate allocation of arbitrary memory blocks by creating an array of bytes. Still, Java &lt;a href="http://en.wikipedia.org/wiki/array" class="extiw" title="w:array"&gt;arrays&lt;/a&gt; are objects.)&lt;/li&gt;&lt;li&gt;Java and C++ use different idioms for resource management. Java relies mainly on garbage collection, while C++ relies mainly on the &lt;a href="http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization" class="extiw" title="w:Resource Acquisition Is Initialization"&gt;RAII (Resource Acquisition Is Initialization)&lt;/a&gt; idiom. This is reflected in several differences between the two languages: &lt;ul&gt;&lt;li&gt;In C++ it is common to allocate objects of compound types as local stack-bound variables which are destructed when they go out of scope. In Java compound types are always allocated on the heap and collected by the garbage collector (except in virtual machines that use &lt;a href="http://en.wikipedia.org/wiki/escape_analysis" class="extiw" title="w:escape analysis"&gt;escape analysis&lt;/a&gt; to convert heap allocations to stack allocations).&lt;/li&gt;&lt;li&gt;C++ has destructors, while Java has &lt;a href="http://en.wikipedia.org/wiki/finalizer" class="extiw" title="w:finalizer"&gt;finalizers&lt;/a&gt;. Both are invoked prior to an object's deallocation, but they differ significantly. A C++ object's destructor must be implicitly (in the case of stack-bound variables) or explicitly invoked to deallocate the object. The destructor executes &lt;a href="http://en.wikipedia.org/wiki/Synchronization" class="extiw" title="w:Synchronization"&gt;synchronously&lt;/a&gt; at the point in the program at which the object is deallocated. Synchronous, coordinated uninitialization and deallocation in C++ thus satisfy the RAII idiom. In Java, object deallocation is implicitly handled by the garbage collector. A Java object's finalizer is invoked &lt;a href="http://en.wikipedia.org/wiki/Asynchrony" class="extiw" title="w:Asynchrony"&gt;asynchronously&lt;/a&gt; some time after it has been accessed for the last time and before it is actually deallocated, which may never happen. Very few objects require finalizers; a finalizer is only required by objects that must guarantee some clean up of the object state prior to deallocation—typically releasing resources external to the JVM. In Java safe synchronous deallocation of resources is performed using the try/finally construct.&lt;/li&gt;&lt;li&gt;In C++ it is possible to have a &lt;a href="http://en.wikipedia.org/wiki/dangling_pointer" class="extiw" title="w:dangling pointer"&gt;dangling pointer&lt;/a&gt; – a &lt;a href="http://en.wikipedia.org/wiki/reference_%28computer_science%29" class="extiw" title="w:reference (computer science)"&gt;reference&lt;/a&gt; to an object that has been destructed; attempting to use a dangling pointer typically results in program failure. In Java, the garbage collector won't destruct a referenced object.&lt;/li&gt;&lt;li&gt;In C++ it is possible to have an object that is allocated, but unreachable. An &lt;a href="http://en.wikipedia.org/wiki/unreachable_object" class="extiw" title="w:unreachable object"&gt;unreachable object&lt;/a&gt; is one that has no reachable references to it. An unreachable object cannot be destructed (deallocated), and results in a &lt;a href="http://en.wikipedia.org/wiki/memory_leak" class="extiw" title="w:memory leak"&gt;memory leak&lt;/a&gt;. By contrast, in Java an object will not be deallocated by the garbage collector &lt;i&gt;until&lt;/i&gt; it becomes unreachable (by the user program). (Note: &lt;i&gt;&lt;a href="http://en.wikipedia.org/wiki/weak_reference" class="extiw" title="w:weak reference"&gt;weak references&lt;/a&gt;&lt;/i&gt; are supported, which work with the Java garbage collector to allow for different &lt;i&gt;strengths&lt;/i&gt; of reachability.) Garbage collection in Java prevents many memory leaks, but leaks are still possible under some circumstances.&lt;/li&gt;&lt;/ul&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a name="Libraries" id="Libraries"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h5&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline"&gt;Libraries&lt;/span&gt;&lt;/h5&gt; &lt;ul&gt;&lt;li&gt;&lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/STL" title="C++ Programming/STL"&gt;C++ standard library&lt;/a&gt; only provides components that are relatively general purpose, such as strings, containers, and I/O streams. Java has a considerably larger standard library. This additional functionality is available for C++ by (often free) third party libraries, but third party libraries do not provide the same ubiquitous cross-platform functionality as standard libraries.&lt;/li&gt;&lt;li&gt;C++ is mostly &lt;a href="http://en.wikipedia.org/wiki/backward_compatible" class="extiw" title="w:backward compatible"&gt;backward compatible&lt;/a&gt; with C, and C libraries (such as the &lt;a href="http://en.wikipedia.org/wiki/Application_programming_interface" class="extiw" title="w:Application programming interface"&gt;APIs&lt;/a&gt; of most &lt;a href="http://en.wikipedia.org/wiki/operating_system" class="extiw" title="w:operating system"&gt;operating systems&lt;/a&gt;) are directly accessible from C++. In Java, the richer functionality of the standard library is that it provides &lt;a href="http://en.wikipedia.org/wiki/cross-platform" class="extiw" title="w:cross-platform"&gt;cross-platform&lt;/a&gt; access to many features typically available in platform-specific libraries. Direct access from Java to native operating system and hardware functions requires the use of the &lt;a href="http://en.wikipedia.org/wiki/Java_Native_Interface" class="extiw" title="w:Java Native Interface"&gt;Java Native Interface&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a name="Runtime" id="Runtime"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h5&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline"&gt;Runtime&lt;/span&gt;&lt;/h5&gt; &lt;ul&gt;&lt;li&gt;C++ is normally compiled directly to &lt;a href="http://en.wikipedia.org/wiki/machine_code" class="extiw" title="w:machine code"&gt;machine code&lt;/a&gt; which is then executed directly by the &lt;a href="http://en.wikipedia.org/wiki/operating_system" class="extiw" title="w:operating system"&gt;operating system&lt;/a&gt;. Java is normally compiled to &lt;a href="http://en.wikipedia.org/wiki/byte-code" class="extiw" title="w:byte-code"&gt;byte-code&lt;/a&gt; which the &lt;a href="http://en.wikipedia.org/wiki/Java_virtual_machine" class="extiw" title="w:Java virtual machine"&gt;Java virtual machine&lt;/a&gt; (JVM) then either &lt;a href="http://en.wikipedia.org/wiki/Interpreter_%28computing%29" class="extiw" title="w:Interpreter (computing)"&gt;interprets&lt;/a&gt; or &lt;a href="http://en.wikipedia.org/wiki/Just-in-time_compilation" class="extiw" title="w:Just-in-time compilation"&gt;JIT&lt;/a&gt; compiles to machine code and then executes.&lt;/li&gt;&lt;li&gt;Due to the lack of constraints in the use of some C++ language features (e.g. unchecked array access, raw pointers), programming errors can lead to low-level &lt;a href="http://en.wikipedia.org/wiki/buffer_overflow" class="extiw" title="w:buffer overflow"&gt;buffer overflows&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/page_fault" class="extiw" title="w:page fault"&gt;page faults&lt;/a&gt;, and &lt;a href="http://en.wikipedia.org/wiki/segmentation_fault" class="extiw" title="w:segmentation fault"&gt;segmentation faults&lt;/a&gt;. The &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/STL" title="C++ Programming/STL"&gt;Standard Template Library&lt;/a&gt;, however, provides higher-level abstractions (like vector, list and map) to help avoid such errors. In Java, such errors either simply cannot occur or are detected by the &lt;a href="http://en.wikipedia.org/wiki/Java_virtual_machine" class="extiw" title="w:Java virtual machine"&gt;JVM&lt;/a&gt; and reported to the application in the form of an &lt;a href="http://en.wikipedia.org/wiki/exception_handling" class="extiw" title="w:exception handling"&gt;exception&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;In Java, &lt;a href="http://en.wikipedia.org/wiki/bounds_checking" class="extiw" title="w:bounds checking"&gt;w:bounds checking&lt;/a&gt; is implicitly performed for all array access operations. In C++, array access operations on native arrays are not bounds-checked, and bounds checking for random-access element access on standard library collections like std::vector and std::deque is optional.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a name="Miscellaneous" id="Miscellaneous"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h5&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline"&gt;Miscellaneous&lt;/span&gt;&lt;/h5&gt; &lt;ul&gt;&lt;li&gt;Java and C++ use different techniques for splitting up code in multiple source files. Java uses a package system that dictates the file name and path for all program definitions. In Java, the compiler imports the executable &lt;a href="http://en.wikipedia.org/wiki/class_%28file_format%29" class="extiw" title="w:class (file format)"&gt;class files&lt;/a&gt;. C++ uses a &lt;a href="http://en.wikipedia.org/wiki/header_file" class="extiw" title="w:header file"&gt;header file&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/source_code" class="extiw" title="w:source code"&gt;source code&lt;/a&gt; inclusion system for sharing declarations between source files. (See &lt;a href="http://en.wikipedia.org/wiki/Comparison_of_imports_and_includes" class="extiw" title="w:Comparison of imports and includes"&gt;Comparison of imports and includes&lt;/a&gt;.)&lt;/li&gt;&lt;li&gt;Templates and macros in C++, including those in the standard library, can result in duplication of similar code after compilation. Second, &lt;a href="http://en.wikipedia.org/wiki/library_%28computer_science%29#Dynamic_linking" class="extiw" title="w:library (computer science)"&gt;dynamic linking&lt;/a&gt; with standard libraries eliminates binding the libraries at compile time.&lt;/li&gt;&lt;li&gt;C++ compilation features a textual &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Compiler/Preprocessor" title="C++ Programming/Compiler/Preprocessor"&gt;preprocessing&lt;/a&gt; phase, while Java does not. Java supports many optimizations that mitigate the need for a preprocessor, but some users add a preprocessing phase to their build process for better support of conditional compilation.&lt;/li&gt;&lt;li&gt;In Java, arrays are container objects which you can inspect the length of at any time. In both languages, arrays have a fixed size. Further, C++ programmers often refer to an array only by a pointer to its first element, from which they cannot retrieve the array size. However, C++ and Java both provide container classes (&lt;b&gt;std::vector&lt;/b&gt; and &lt;b&gt;java.util.ArrayList&lt;/b&gt; respectively) which are resizable and store their size.&lt;/li&gt;&lt;li&gt;Java's division and modulus operators are well defined to truncate to zero. C++ does not specify whether or not these operators truncate to zero or "truncate to -infinity". -3/2 will always be -1 in Java, but a C++ compiler may return either -1 or -2, depending on the platform. &lt;a href="http://en.wikipedia.org/wiki/C99" class="extiw" title="w:C99"&gt;C99&lt;/a&gt; defines division in the same fashion as Java. Both languages guarantee that &lt;code&gt;(a/b)*b + (a%b) == a&lt;/code&gt; for all a and b (b != 0). The C++ version will sometimes be faster, as it is allowed to pick whichever truncation mode is native to the processor.&lt;/li&gt;&lt;li&gt;The sizes of integer types is defined in Java (int is 32-bit, long is 64-bit), while in C++ the size of integers and pointers is compiler-dependent. Thus, carefully-written C++ code can take advantage of the 64-bit processor's capabilities while still functioning properly on 32-bit processors. However, C++ programs written without concern for a processor's word size may fail to function properly with some compilers. In contrast, Java's fixed integer sizes mean that programmers need not concern themselves with varying integer sizes, and programs will run exactly the same. This may incur a performance penalty since Java code cannot run using an arbitrary processor's word size.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a name="Performance" id="Performance"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h5&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline"&gt;Performance&lt;/span&gt;&lt;/h5&gt; &lt;p&gt;Computing performance is a measure of resource consumption when a system of hardware and software performs a piece of computing work such as an algorithm or a transaction. Higher performance is defined to be 'using fewer resources'. Resources of interest include memory, bandwidth, persistent storage and CPU cycles. Because of the high availability of all but the latter on modern desktop and server systems, performance is colloquially taken to mean the least CPU cycles; which often converts directly into the least wall clock time. Comparing the performance of two software languages requires a fixed hardware platform and (often relative) measurements of two or more software subsystems. This section compares the relative computing performance of C++ and Java on common operating systems such as Windows and Linux.&lt;/p&gt; &lt;p&gt;Early versions of Java were significantly outperformed by statically compiled languages such as C++. This is because the program statements of these two closely related &lt;a href="http://www.theadvisors.com/langcomparison.htm" class="external text" title="http://www.theadvisors.com/langcomparison.htm" rel="nofollow"&gt;Level 6&lt;/a&gt; languages may compile to a few machine instructions with C++, while compiling into several byte codes involving several machine instructions each when interpreted by a Java &lt;a href="http://en.wikipedia.org/wiki/JVM" class="extiw" title="w:JVM"&gt;JVM&lt;/a&gt;. For example:&lt;/p&gt; &lt;table class="wikitable"&gt; &lt;tbody&gt;&lt;tr&gt; &lt;th&gt;Java/C++ statement&lt;/th&gt; &lt;th&gt;C++ generated code&lt;/th&gt; &lt;th&gt;Java generated byte code&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;vector[i]++;&lt;/td&gt; &lt;td&gt;mov edx,[ebp+4h]&lt;br /&gt;&lt;p&gt;mov eax,[ebp+1Ch]&lt;br /&gt;inc dword ptr [edx+eax*4]&lt;/p&gt; &lt;/td&gt; &lt;td&gt;aload_1&lt;br /&gt;&lt;p&gt;iload_2&lt;br /&gt;dup2&lt;br /&gt;iaload&lt;br /&gt;iconst_1&lt;br /&gt;iadd&lt;br /&gt;iastore&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;While this may still be the case for &lt;a href="http://en.wikipedia.org/wiki/embedded_systems" class="extiw" title="w:embedded systems"&gt;embedded systems&lt;/a&gt; because of the requirement for a small footprint, advances in &lt;a href="http://en.wikipedia.org/wiki/Just-in-time_compilation" class="extiw" title="w:Just-in-time compilation"&gt;just in time (JIT)&lt;/a&gt; compiler technology for long-running server and desktop Java processes has closed the performance gap and in some cases given the performance advantage to Java. In effect, Java byte code is compiled into machine instructions at run time, in a similar manner to C++ static compilation, resulting in similar instruction sequences.&lt;/p&gt; &lt;p&gt;C++ is still faster in most operations than Java at the moment, even at low-level and numeric computation. For in-depth information you could check &lt;a href="http://www.idiom.com/%7Ezilla/Computer/javaCbenchmark.html" class="external text" title="http://www.idiom.com/~zilla/Computer/javaCbenchmark.html" rel="nofollow"&gt;Performance of Java versus C++&lt;/a&gt;. It's a bit pro-Java but very detailed.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1165683755437997580-8604566582710080850?l=somelogics.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://somelogics.blogspot.com/feeds/8604566582710080850/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://somelogics.blogspot.com/2008/12/comparison-with-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/8604566582710080850'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/8604566582710080850'/><link rel='alternate' type='text/html' href='http://somelogics.blogspot.com/2008/12/comparison-with-java.html' title='Comparison with Java'/><author><name>Priyank</name><uri>http://www.blogger.com/profile/16749090935925725720</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='12361015692322800765'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1165683755437997580.post-6068786566261813196</id><published>2008-12-04T06:42:00.000-08:00</published><updated>2008-12-04T06:43:56.870-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++ programming'/><title type='text'>Comparison with C</title><content type='html'>&lt;h4&gt;&lt;span class="mw-headline"&gt;C 89/99&lt;/span&gt;&lt;/h4&gt; &lt;p&gt;C was essentially the core language of C++ when Bjarne Stroustrup, decided to create a "better C". Many of the syntax conventions and rules still hold true and so we can even state that C was a subset of C++, most recent C++ compilers will also compile C code taking into consideration the small incompatibilities, since C99 and C++ 2003 are not compatible any more. You can also check more information about the C language on the C Programming Wikibook ( &lt;a href="http://en.wikibooks.org/wiki/C_Programming" class="external free" title="http://en.wikibooks.org/wiki/C_Programming" rel="nofollow"&gt;http://en.wikibooks.org/wiki/C_Programming&lt;/a&gt; ).&lt;/p&gt; &lt;p&gt;C++ as defined by the ANSI standard in 98 (called C++98 at times) is very nearly, but not quite, a superset of the C language as it was defined by its first ANSI standard in 1989 (known as C89). There are a number of ways in which C++ is not a strict superset, in the sense that not all valid C89 programs are valid C++ programs, but the process of converting C code to valid C++ code is fairly trivial (avoiding reserved words, getting around the stricter C++ type checking with casts, declaring every called function, and so on).&lt;/p&gt; &lt;p&gt;In 1999, C was revised and many new features were added to it. As of 2004, most of these new "C99" features are not there in C++. Some (including Stroustrup himself) have argued that the changes brought about in C99 have a philosophy distinct from what C++98 adds to C89, and hence these C99 changes are directed towards increasing incompatibility between C and C++.&lt;/p&gt; &lt;p&gt;The merging of the languages seems a dead issue as coordinated actions by the C and C++ standards committees leading to a practical result didn't happen and it can be said that the languages started even to diverge.&lt;/p&gt; &lt;p&gt;Some of the differences are:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;C++ supports function overloading (absent in C89, allowed only for some standard library code in C99).&lt;/li&gt;&lt;li&gt;C++ supports &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming_Languages/Paradigms/Inheritance" title="C++ Programming/Programming Languages/Paradigms/Inheritance"&gt;inheritance&lt;/a&gt; and &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming_Languages/Paradigms/Polymorphism" title="C++ Programming/Programming Languages/Paradigms/Polymorphism"&gt;polymorphism&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;C++ adds keyword &lt;b&gt;class&lt;/b&gt;, but keeps &lt;b&gt;struct&lt;/b&gt; from C, with compatible semantics.&lt;/li&gt;&lt;li&gt;C++ supports access control for class members.&lt;/li&gt;&lt;li&gt;C++ supports generic programming through the use of &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Template" title="C++ Programming/Template"&gt;templates&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;C++ extends the C89 standard library with its own standard library.&lt;/li&gt;&lt;li&gt;C++ and C99 offer different complex number facilities.&lt;/li&gt;&lt;li&gt;C++ has &lt;b&gt;bool&lt;/b&gt; and &lt;b&gt;wchar_t&lt;/b&gt; as primitive types, while typedefs in C.&lt;/li&gt;&lt;li&gt;C++ comparison operators return &lt;b&gt;bool&lt;/b&gt;, while C returns &lt;b&gt;int&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;C++ supports overloading of operators.&lt;/li&gt;&lt;li&gt;C++ character constants have type &lt;b&gt;char&lt;/b&gt;, while C character constants have type &lt;b&gt;int&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;C++ has additional &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Type_Casting" title="C++ Programming/Type Casting"&gt;cast operators&lt;/a&gt; (&lt;b&gt;static_cast&lt;/b&gt;, &lt;b&gt;dynamic_cast&lt;/b&gt;, &lt;b&gt;const_cast&lt;/b&gt; and &lt;b&gt;reinterpret_cast&lt;/b&gt;).&lt;/li&gt;&lt;li&gt;C++ adds &lt;b&gt;mutable&lt;/b&gt; keyword to address the imperfect match between physical and logical constness.&lt;/li&gt;&lt;li&gt;C++ extends the type system with &lt;i&gt;references&lt;/i&gt;.&lt;/li&gt;&lt;li&gt;C++ supports &lt;b&gt;member functions&lt;/b&gt;, &lt;b&gt;constructors&lt;/b&gt; and &lt;b&gt;destructors&lt;/b&gt; for user-defined types to establish invariants and to manage resources.&lt;/li&gt;&lt;li&gt;C++ supports &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/RTTI" title="C++ Programming/RTTI"&gt;runtime type identification&lt;/a&gt; (RTTI), via &lt;b&gt;typeid&lt;/b&gt; and &lt;b&gt;dynamic_cast&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;C++ includes &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Exception_Handling" title="C++ Programming/Exception Handling"&gt;exception handling&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;C++ has &lt;tt&gt;std::vector&lt;/tt&gt; as part of its standard library instead of variable-length arrays as in C.&lt;/li&gt;&lt;li&gt;C++ treats &lt;b&gt;sizeof&lt;/b&gt; operator as compile time operation, while C allows it be a runtime operation.&lt;/li&gt;&lt;li&gt;C++ has &lt;b&gt;new&lt;/b&gt; and &lt;b&gt;delete&lt;/b&gt; operators, while C uses &lt;b&gt;malloc&lt;/b&gt; and &lt;b&gt;free&lt;/b&gt; library functions exclusively.&lt;/li&gt;&lt;li&gt;C++ supports object-oriented programming without extensions.&lt;/li&gt;&lt;li&gt;C++ does not require use of macros and careful information-hiding and abstraction for code portability.&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1165683755437997580-6068786566261813196?l=somelogics.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://somelogics.blogspot.com/feeds/6068786566261813196/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://somelogics.blogspot.com/2008/12/comparison-with-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/6068786566261813196'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/6068786566261813196'/><link rel='alternate' type='text/html' href='http://somelogics.blogspot.com/2008/12/comparison-with-c.html' title='Comparison with C'/><author><name>Priyank</name><uri>http://www.blogger.com/profile/16749090935925725720</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='12361015692322800765'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1165683755437997580.post-163302093139978033</id><published>2008-12-04T06:28:00.000-08:00</published><updated>2008-12-04T06:31:43.665-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++ programming'/><title type='text'>Language Comparisons</title><content type='html'>&lt;p&gt;There isn't a perfect language. It all depends on the tools and the objective. The optimal language (in terms of run-time performance) is machine code but &lt;a href="http://en.wikipedia.org/wiki/Machine_code" class="extiw" title="w:Machine code"&gt;machine code&lt;/a&gt; (binary) is the least efficient programming language in terms of coder time. The complexity of writing large systems is enormous with high-level languages, and beyond human capabilities with machine code. In the next section C++ will be compared with other closely related languages like &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming_Languages/Comparisons/C" title="C++ Programming/Programming Languages/Comparisons/C"&gt;C&lt;/a&gt;, &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming_Languages/Comparisons/Java" title="C++ Programming/Programming Languages/Comparisons/Java"&gt;Java&lt;/a&gt;, &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming_Languages/Comparisons/C_Sharp" title="C++ Programming/Programming Languages/Comparisons/C Sharp"&gt;C#&lt;/a&gt; and &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming_Languages/Comparisons/Managed_C%2B%2B" title="C++ Programming/Programming Languages/Comparisons/Managed C++"&gt;C++/CLI&lt;/a&gt;.&lt;/p&gt; &lt;div class="notice metadata" id="cleanup" style="border: 1px solid rgb(170, 170, 170); margin: 12pt 8%; padding: 6pt; background: rgb(249, 249, 249) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; font-family: monospace; width: 84%;"&gt;&lt;i&gt;«When someone says "I want a programming language in which I need only say what I wish done," give him a lollipop.»&lt;/i&gt; &lt;hr /&gt; &lt;div&gt;&lt;b&gt;&lt;small&gt;--published in SIGPLAN Notices Vol. 17, No. 9, September 1982&lt;/small&gt;&lt;/b&gt;&lt;/div&gt; &lt;/div&gt; &lt;p&gt;&lt;br /&gt;The quote above is shown to indicate that no programming language at present can translate directly concepts or ideas into useful code, there are solutions that will help. We will cover the use of &lt;a href="http://en.wikipedia.org/wiki/Computer-aided_software_engineering_%28CASE%29" class="extiw" title="w:Computer-aided software engineering (CASE)"&gt;Computer-aided software engineering (CASE)&lt;/a&gt; tools that will address part of this problem but its use does require planning and some degree of complexity.&lt;/p&gt; &lt;p&gt;The intention of these sections is not to promote one language above another; each has its applicability. Some are better in specific tasks, some are simpler to learn, others only provide a better level of control to the programmer. This all may depend also on the level of control the programmer has of a given language.&lt;/p&gt; &lt;p&gt;&lt;a name="Garbage_Collection" id="Garbage_Collection"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h4&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline"&gt;Garbage Collection&lt;/span&gt;&lt;/h4&gt; &lt;p&gt;In C++ garbage collection is optional rather than required. In the &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Compiler/Linker/Libraries/Garbage_Collection" title="C++ Programming/Compiler/Linker/Libraries/Garbage Collection"&gt;Garbage Collection Section&lt;/a&gt; of this book we will cover this issue deeply.&lt;/p&gt; &lt;p&gt;&lt;a name="Why_doesn.27t_C.2B.2B_include_a_finally_keyword.3F" id="Why_doesn.27t_C.2B.2B_include_a_finally_keyword.3F"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h4&gt;&lt;span class="editsection"&gt;&lt;/span&gt; &lt;span class="mw-headline"&gt;Why doesn't C++ include a &lt;tt&gt;finally&lt;/tt&gt; keyword?&lt;/span&gt;&lt;/h4&gt; &lt;p&gt;As we will see in the &lt;a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/RAII" title="C++ Programming/RAII"&gt;Resource Acquisition Is Initialization (RAII) Section&lt;/a&gt; of the book, RAII can be used to provide a better solution for most issues. When &lt;tt&gt;finally&lt;/tt&gt; is used to clean up, it has to be written by the clients of a class each time that class is used (for example, clients of a &lt;tt&gt;File&lt;/tt&gt; class have to do I/O in a &lt;tt&gt;try&lt;/tt&gt;/&lt;tt&gt;catch&lt;/tt&gt;/&lt;tt&gt;finally&lt;/tt&gt; block so that they can guarantee that the &lt;tt&gt;File&lt;/tt&gt; is closed). With RAII, the destructor of the &lt;tt&gt;File&lt;/tt&gt; class can make that guarantee. Now the cleanup code has to be coded only once — in the destructor of &lt;tt&gt;File&lt;/tt&gt;; the users of the class don't need to do anything.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1165683755437997580-163302093139978033?l=somelogics.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://somelogics.blogspot.com/feeds/163302093139978033/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://somelogics.blogspot.com/2008/12/language-comparisons.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/163302093139978033'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/163302093139978033'/><link rel='alternate' type='text/html' href='http://somelogics.blogspot.com/2008/12/language-comparisons.html' title='Language Comparisons'/><author><name>Priyank</name><uri>http://www.blogger.com/profile/16749090935925725720</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='12361015692322800765'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1165683755437997580.post-3952088347512783247</id><published>2008-12-04T06:14:00.000-08:00</published><updated>2008-12-04T06:25:18.898-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++ programming'/><title type='text'>Introducing C++</title><content type='html'>&lt;p&gt;&lt;b&gt;C++&lt;/b&gt; (pronounced "see plus plus") is a general-purpose, &lt;span class="extiw"&gt;object-oriented&lt;/span&gt;, statically typed, free-form, multi-paradigm programming language supporting procedural programming, data abstraction, and generic programming. During the 1990s, C++ became one of the most popular computer programming languages.&lt;/p&gt; &lt;p&gt;&lt;a name="History" id="History"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline"&gt;History&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;&lt;span class="extiw"&gt;Bjarne Stroustrup&lt;/span&gt; a Computer Scientist, from &lt;span class="extiw"&gt;Bell Labs&lt;/span&gt; was the designer and original implementer of C++ (originally named "C with Classes") during the 1980s as an enhancement to the C programming language. Enhancements started with the addition of classes, followed by, among many features, &lt;span class="mw-redirect"&gt;virtual functions&lt;/span&gt;, &lt;span class="mw-redirect"&gt;operator overloading&lt;/span&gt;, multiple inheritance, templates, and exception handling, these and other features are covered in detail along this book.&lt;/p&gt; &lt;p&gt;The C++ programming language is a standard recognized by the the &lt;span class="extiw"&gt;ANSI&lt;/span&gt; (The American National Standards Institute), BSI (The British Standards Institute), DIN (The German national standards organization), several other national standards bodies, and was ratified in 1998 by the ISO (The International Standards Organization) as &lt;i&gt;&lt;span class="extiw"&gt;ISO/IEC 14882&lt;/span&gt;:1998&lt;/i&gt;, consists of two parts: the Core Language and the Standard Library; the latter includes the Standard Template Library and the Standard C Library (ANSI C 89).&lt;/p&gt; &lt;p&gt;Features introduced in C++ include declarations as statements, function-like casts, &lt;tt&gt;new&lt;/tt&gt;/&lt;tt&gt;delete&lt;/tt&gt;, &lt;tt&gt;bool&lt;/tt&gt;, reference types, &lt;tt&gt;const&lt;/tt&gt;, &lt;tt&gt;inline&lt;/tt&gt; functions, default arguments, function overloading, namespaces, classes (including all class-related features such as inheritance, member functions, virtual functions, abstract classes, and constructors), operator overloading, templates, the &lt;tt&gt;::&lt;/tt&gt; operator, exception handling, run-time type identification, and more type checking in several cases. Comments starting with two slashes ("&lt;tt&gt;//&lt;/tt&gt;") were originally part of &lt;span class="extiw"&gt;BCPL&lt;/span&gt;, and was reintroduced in C++. Several features of C++ were later adopted by C, including &lt;tt&gt;const&lt;/tt&gt;, &lt;tt&gt;inline&lt;/tt&gt;, declarations in &lt;tt&gt;for&lt;/tt&gt; loops, and C++-style comments (using the &lt;tt&gt;//&lt;/tt&gt; symbol).&lt;/p&gt; &lt;p&gt;The current version, which is the 2003 version, &lt;i&gt;ISO/IEC 14882:2003&lt;/i&gt; redefines the standard language as a single item. The STL that pre-dated the standardization of C++, and was originally implemented in Ada is now an integral part of the standard and requirement for a compliant implementation of the same. Many other C++ libraries exist which are not part of the Standard, such as Boost. Also, non-Standard libraries written in C can generally be used by C++ programs.&lt;/p&gt; &lt;p&gt;Since 2004, the standards committee (includes Bjarne Stroustrup) has been busy working out the details of a new revision of the standard, that has been temporarily titled C++0x, due in 2009.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;dl&gt;&lt;dt&gt;&lt;i&gt;C++ source code example&lt;/i&gt;&lt;/dt&gt;&lt;dd&gt;&lt;br /&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;div dir="ltr" style="text-align: left;"&gt; &lt;pre class="source-cpp"&gt;&lt;span style="color: rgb(51, 51, 255); font-weight: bold;" class="co1"&gt;// 'Hello World!' program &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 204, 0); font-weight: bold;" class="co2"&gt;#include &lt;iostream&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;" class="kw4"&gt;int&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; main&lt;/span&gt;&lt;span style="font-weight: bold;" class="br0"&gt;()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;" class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;  std::&lt;/span&gt;&lt;span style="font-weight: bold;" class="kw3"&gt;cout&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; &lt;&lt; &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);" class="st0"&gt;"Hello World!"&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; &lt;&lt;&gt;&lt;span style="font-weight: bold;" class="me2"&gt;endl&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;  &lt;/span&gt;&lt;span style="font-weight: bold;" class="kw1"&gt;return&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(153, 51, 153);" class="nu0"&gt;0&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;" class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;h3&gt;&lt;span class="mw-headline"&gt;Overview&lt;/span&gt;&lt;/h3&gt;  &lt;p&gt;Before you begin your journey to understand how to write programs using C++, it is important to understand a few key concepts that you may encounter. These concepts, while not unique to C++, help in understanding programming in general. Readers who have experience in another programming language may wish to skim through or skip this section entirely.&lt;/p&gt;  &lt;p&gt;There are many different kinds of programs in use today. From the operating system you use that makes sure everything works as it should, to the video games and music applications you use for fun, programs can fulfill many different purposes. What all &lt;b&gt;programs&lt;/b&gt; (also called &lt;b&gt;software&lt;/b&gt; or &lt;b&gt;applications&lt;/b&gt;) have in common is that they all are made up of a sequence of instructions written in some form of programming language. These instructions tell a computer what to do, and generally how to do it. Programs can contain anything from instructions to solve math problems or send emails, to how to behave when a video game character is shot in a game. The computer will follow the instructions of a program one instruction at a time from start to finish.&lt;/p&gt;  &lt;p&gt;&lt;a name="Why_learn_C.2B.2B.3F" id="Why_learn_C.2B.2B.3F"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;&lt;span class="editsection"&gt;&lt;/span&gt;&lt;span class="mw-headline"&gt;Why learn C++?&lt;/span&gt;&lt;/h3&gt;  &lt;p&gt;Why not? This is the most clarifying approach to the decision to learn anything. Although learning is always good, selecting what you learn is more important as it is how you will prioritize tasks. Another side of this problem is that you will be investing some time in getting a new skill set. You must decide how will this benefit you. Check your objectives and compare similar projects or see what the programming market is in need. In any case, the more programming languages you know, the better.&lt;/p&gt;  &lt;p&gt;If you are approaching the learning process only to add another notch under your belt, that is, willing only to dedicate enough effort to understand its major quirks and learn something about its dark corners then you should be best served in learning first two other languages, this will clarify what makes C++ special in its approach to programming problems. You should select one imperative language, and in this C will probably have a better market value and will have a direct relation to C++ (a good substitute would be ASM) and the second language should be an Object Oriented language like Java for the same reasons, as there is a close relation between the three languages.&lt;/p&gt;  &lt;p&gt;If you are willing to dedicate a more than passing interest in C++ then you can even learn C++ as your first language but dedicate some time understanding the different paradigms and why C++ is a multi-paradigm language or how some like to call it a hybrid language.&lt;/p&gt;  &lt;p&gt;Learning C is not a requirement for understanding C++, but knowing how to use an imperative language is, C++ will not make it easy for you to understand and distinguish some of this deeper concepts, since that in C++ you are free to implement solutions with a greater range of freedom. Understanding what options to make will become the cornerstone of mastering the language.&lt;/p&gt;  &lt;p&gt;You should not learn C++ if you are only interested in applying or learning about Object Oriented Programing since the nomenclature used and some of the approaches C++ takes to the problem will probably increase the difficulty level in learning and mastering those concepts, if you are truly interested in Object Oriented programming, the best language for that is Smalltalk.&lt;/p&gt;  &lt;p&gt;As with all languages C++ has a specific scope of application, where it can truly shine, and if we take a quick comparison with the previous mentioned languages, C++ is harder to learn than C and Java but more powerful than both. C++ enables you to abstract from the little things you have to deal with in C or other lower level languages but will grant you a bigger control and responsibility than Java, but it will not provide the default features you can obtain in similar higher level languages. You will have to search and examine several external implementations of these features and freely select those that best serve your purposes or you may even have to implement your own solution.&lt;/p&gt; &lt;h1&gt;&lt;a href="http://somelogics.blogspot.com/2008/12/introduction-to-c.html" rel="bookmark" title="Permanent Link to An Introduction to C++"&gt;&lt;br /&gt;&lt;/a&gt;&lt;span class="item-control blog-admin pid-1897023584"&gt;&lt;a href="post-edit.g?blogID=1165683755437997580&amp;amp;postID=6006912088492984577" title="Edit Post"&gt;&lt;span class="quick-edit-icon"&gt;&lt;br /&gt;&lt;/span&gt; &lt;/a&gt;&lt;/span&gt;&lt;/h1&gt; &lt;pre class="source-cpp"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1165683755437997580-3952088347512783247?l=somelogics.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://somelogics.blogspot.com/feeds/3952088347512783247/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://somelogics.blogspot.com/2008/12/introducing-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/3952088347512783247'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/3952088347512783247'/><link rel='alternate' type='text/html' href='http://somelogics.blogspot.com/2008/12/introducing-c.html' title='Introducing C++'/><author><name>Priyank</name><uri>http://www.blogger.com/profile/16749090935925725720</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='12361015692322800765'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1165683755437997580.post-1089345974140037252</id><published>2008-12-04T06:13:00.000-08:00</published><updated>2008-12-04T06:14:18.140-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++ programming'/><title type='text'>Constants</title><content type='html'>Constants are expressions with a fixed value.&lt;h3&gt;Literals&lt;/h3&gt; Literals are used to express particular values within the source code of a program. We have already used these previously to give concrete values to variables or to express messages we wanted our programs to print out, for example, when we wrote:&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;a = 5;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;the &lt;tt&gt;5&lt;/tt&gt; in this piece of code was a literal constant.&lt;/p&gt;&lt;p&gt;Literal constants can be divided in Integer Numerals, Floating-Point Numerals, Characters, Strings and Boolean Values.&lt;/p&gt;&lt;h4&gt;Integer Numerals&lt;/h4&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;1776&lt;br /&gt;707&lt;br /&gt;-273&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;They are numerical constants that identify integer decimal values. Notice that to express a numerical constant we do not have to write quotes (&lt;tt&gt;"&lt;/tt&gt;) nor any special character. There is no doubt that it is a constant: whenever we write &lt;tt&gt;1776&lt;/tt&gt; in a program, we will be referring to the value 1776.&lt;/p&gt;&lt;p&gt;In addition to decimal numbers (those that all of us are used to use every day) C++ allows the use as literal constants of octal numbers (base 8) and hexadecimal numbers (base 16). If we want to express an octal number we have to precede it with a &lt;tt&gt;0&lt;/tt&gt; (zero character). And in order to express a hexadecimal number we have to precede it with the characters &lt;tt&gt;0x&lt;/tt&gt; (zero, x). For example, the following literal constants are all equivalent to each other: &lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;75         &lt;span class="comm"&gt;// decimal&lt;/span&gt;&lt;br /&gt;0113       &lt;span class="comm"&gt;// octal&lt;/span&gt;&lt;br /&gt;0x4b       &lt;span class="comm"&gt;// hexadecimal &lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;All of these represent the same number: 75 (seventy-five) expressed as a base-10 numeral, octal numeral and hexadecimal numeral, respectively. &lt;/p&gt;&lt;p&gt;Literal constants, like variables, are considered to have a specific data type. By default, integer literals are of type &lt;tt&gt;int&lt;/tt&gt;. However, we can force them to either be unsigned by appending the &lt;tt&gt;u&lt;/tt&gt; character to it, or long by appending &lt;tt&gt;l&lt;/tt&gt;:&lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;75         &lt;span class="comm"&gt;// int&lt;/span&gt;&lt;br /&gt;75u        &lt;span class="comm"&gt;// unsigned int&lt;/span&gt;&lt;br /&gt;75l        &lt;span class="comm"&gt;// long&lt;/span&gt;&lt;br /&gt;75ul       &lt;span class="comm"&gt;// unsigned long &lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;In both cases, the suffix can be specified using either upper or lowercase letters.&lt;/p&gt;&lt;h4&gt;Floating Point Numbers&lt;/h4&gt; They express numbers with decimals and/or exponents. They can include either a decimal point, an &lt;tt&gt;e&lt;/tt&gt; character (that expresses "by ten at the Xth height", where X is an integer value that follows the &lt;tt&gt;e&lt;/tt&gt; character), or both a decimal point and an &lt;tt&gt;e&lt;/tt&gt; character:&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;3.14159    &lt;span class="comm"&gt;// 3.14159&lt;/span&gt;&lt;br /&gt;6.02e23    &lt;span class="comm"&gt;// 6.02 x 10^23&lt;/span&gt;&lt;br /&gt;1.6e-19    &lt;span class="comm"&gt;// 1.6 x 10^-19&lt;/span&gt;&lt;br /&gt;3.0        &lt;span class="comm"&gt;// 3.0 &lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;These are four valid numbers with decimals expressed in C++. The first number is PI, the second one is the number of Avogadro, the third is the electric charge of an electron (an extremely small number) -all of them approximated- and the last one is the number three expressed as a floating-point numeric literal.&lt;/p&gt;&lt;p&gt;The default type for floating point literals is &lt;tt&gt;double&lt;/tt&gt;. If you explicitly want to express a &lt;tt&gt;float&lt;/tt&gt; or &lt;tt&gt;long double&lt;/tt&gt; numerical literal, you can use the &lt;tt&gt;f&lt;/tt&gt; or &lt;tt&gt;l&lt;/tt&gt; suffixes respectively:&lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;3.14159L   &lt;span class="comm"&gt;// long double&lt;/span&gt;&lt;br /&gt;6.02e23f   &lt;span class="comm"&gt;// float &lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Any of the letters than can be part of a floating-point numerical constant (&lt;tt&gt;e&lt;/tt&gt;, &lt;tt&gt;f&lt;/tt&gt;, &lt;tt&gt;l&lt;/tt&gt;) can be written using either lower or uppercase letters without any difference in their meanings.&lt;/p&gt;&lt;h4&gt;Character and string literals&lt;/h4&gt; There also exist non-numerical constants, like: &lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="str"&gt;'z'&lt;/span&gt;&lt;br /&gt;&lt;span class="str"&gt;'p'&lt;/span&gt;&lt;br /&gt;&lt;span class="str"&gt;"Hello world"&lt;/span&gt;&lt;br /&gt;&lt;span class="str"&gt;"How do you do?"&lt;/span&gt; &lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;The first two expressions represent single character constants, and the following two represent string literals composed of several characters. Notice that to represent a single character we enclose it between single quotes (&lt;tt&gt;'&lt;/tt&gt;) and to express a string (which generally consists of more than one character) we enclose it between double quotes (&lt;tt&gt;"&lt;/tt&gt;). &lt;/p&gt;&lt;p&gt;When writing both single character and string literals, it is necessary to put the quotation marks surrounding them to distinguish them from possible variable identifiers or reserved keywords. Notice the difference between these two expressions: &lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;x&lt;br /&gt;&lt;span class="str"&gt;'x'&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;tt&gt;x&lt;/tt&gt; alone would refer to a variable whose identifier is &lt;tt&gt;x&lt;/tt&gt;, whereas &lt;tt&gt;'x'&lt;/tt&gt; (enclosed within single quotation marks) would refer to the character constant &lt;tt&gt;'x'&lt;/tt&gt;.&lt;/p&gt;&lt;p&gt;Character and string literals have certain peculiarities, like the escape codes. These are special characters that are difficult or impossible to express otherwise in the source code of a program, like newline (&lt;tt&gt;\n&lt;/tt&gt;) or tab (&lt;tt&gt;\t&lt;/tt&gt;). All of them are preceded by a backslash (&lt;tt&gt;\&lt;/tt&gt;). Here you have a list of some of such escape codes: &lt;/p&gt;&lt;table class="boxed"&gt; &lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;tt&gt;\n&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;newline&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;\r&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;carriage return&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;\t&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;tab&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;\v&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;vertical tab&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;\b&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;backspace&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;\f&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;form feed (page feed)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;\a&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;alert (beep)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;\'&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;single quote (&lt;tt&gt;'&lt;/tt&gt;)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;\"&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;double quote (&lt;tt&gt;"&lt;/tt&gt;)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;\?&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;question mark (&lt;tt&gt;?&lt;/tt&gt;)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;\\&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;backslash (&lt;tt&gt;\&lt;/tt&gt;)&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;For example: &lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="str"&gt;'\n'&lt;/span&gt;&lt;br /&gt;&lt;span class="str"&gt;'\t'&lt;/span&gt;&lt;br /&gt;&lt;span class="str"&gt;"Left \t Right"&lt;/span&gt;&lt;br /&gt;&lt;span class="str"&gt;"one\ntwo\nthree"&lt;/span&gt; &lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Additionally, you can express any character by its numerical ASCII code by writing a backslash character (&lt;tt&gt;\&lt;/tt&gt;) followed by the ASCII code expressed as an octal (base-8) or hexadecimal (base-16) number. In the first case (octal) the digits must immediately follow the backslash (for example &lt;tt&gt;\23&lt;/tt&gt; or &lt;tt&gt;\40&lt;/tt&gt;), in the second case (hexadecimal), an &lt;tt&gt;x&lt;/tt&gt; character must be written before the digits themselves (for example &lt;tt&gt;\x20&lt;/tt&gt; or &lt;tt&gt;\x4A&lt;/tt&gt;).&lt;/p&gt;&lt;p&gt;String literals can extend to more than a single line of code by putting a backslash sign (&lt;tt&gt;\&lt;/tt&gt;) at the end of each unfinished line.&lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="str"&gt;"string expressed in \&lt;br /&gt;two lines"&lt;/span&gt; &lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;You can also concatenate several string constants separating them by one or several blank spaces, tabulators, newline or any other valid blank character: &lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="str"&gt;"this forms"&lt;/span&gt; &lt;span class="str"&gt;"a single"&lt;/span&gt; &lt;span class="str"&gt;"string"&lt;/span&gt; &lt;span class="str"&gt;"of characters"&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Finally, if we want the string literal to be explicitly made of wide characters (&lt;tt&gt;wchar_t&lt;/tt&gt;), instead of narrow characters (&lt;tt&gt;char&lt;/tt&gt;), we can precede the constant with the L prefix:&lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;L&lt;span class="str"&gt;"This is a wide character string"&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Wide characters are used mainly to represent non-English or exotic character sets.&lt;/p&gt;&lt;h4&gt;Boolean literals&lt;/h4&gt; There are only two valid Boolean values: true and false. These can be expressed in C++ as values of type &lt;tt&gt;bool&lt;/tt&gt; by using the Boolean literals &lt;tt&gt;true&lt;/tt&gt; and &lt;tt&gt;false&lt;/tt&gt;.&lt;h3&gt;Defined constants (#define)&lt;/h3&gt; You can define your own names for constants that you use very often without having to resort to memory-consuming variables, simply by using the &lt;tt&gt;#define&lt;/tt&gt; preprocessor directive. Its format is:&lt;p&gt;&lt;tt&gt;#define identifier value&lt;/tt&gt;&lt;/p&gt;&lt;p&gt;For example: &lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="prep"&gt;#define PI 3.14159265&lt;/span&gt;&lt;br /&gt;&lt;span class="prep"&gt;#define NEWLINE '\n' &lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;This defines two new constants: &lt;tt&gt;PI&lt;/tt&gt; and &lt;tt&gt;NEWLINE&lt;/tt&gt;. Once they are defined, you can use them in the rest of the code as if they were any other regular constant, for example: &lt;/p&gt;&lt;table class="codebox"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="comm"&gt;// defined constants: calculate circumference&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="prep"&gt;#include &lt;iostream&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw"&gt;using&lt;/span&gt; &lt;span class="kw"&gt;namespace&lt;/span&gt; std;&lt;br /&gt;&lt;br /&gt;&lt;span class="prep"&gt;#define PI 3.14159&lt;/span&gt;&lt;br /&gt;&lt;span class="prep"&gt;#define NEWLINE '\n'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kw"&gt;int&lt;/span&gt; main ()&lt;br /&gt;{&lt;br /&gt; &lt;span class="kw"&gt;double&lt;/span&gt; r=5.0;               &lt;span class="comm"&gt;// radius&lt;/span&gt;&lt;br /&gt; &lt;span class="kw"&gt;double&lt;/span&gt; circle;&lt;br /&gt;&lt;br /&gt; circle = 2 * PI * r;&lt;br /&gt; cout &lt;&lt; circle;&lt;br /&gt; cout &lt;&lt; NEWLINE;&lt;br /&gt;&lt;br /&gt; &lt;span class="kw"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class="result"&gt;&lt;pre&gt;31.4159&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;In fact the only thing that the compiler preprocessor does when it encounters &lt;tt&gt;#define&lt;/tt&gt; directives is to literally replace any occurrence of their identifier (in the previous example, these were &lt;tt&gt;PI&lt;/tt&gt; and &lt;tt&gt;NEWLINE&lt;/tt&gt;) by the code to which they have been defined (&lt;tt&gt;3.14159265&lt;/tt&gt; and &lt;tt&gt;'\n'&lt;/tt&gt; respectively).&lt;/p&gt;&lt;p&gt;The &lt;tt&gt;#define&lt;/tt&gt; directive is not a C++ statement but a directive for the preprocessor; therefore it assumes the entire line as the directive and does not require a semicolon (&lt;tt&gt;;&lt;/tt&gt;) at its end. If you append a semicolon character (&lt;tt&gt;;&lt;/tt&gt;) at the end, it will also be appended in all occurrences within the body of the program that the preprocessor replaces.&lt;/p&gt;&lt;h3&gt;Declared constants (const)&lt;/h3&gt; With the &lt;tt&gt;const&lt;/tt&gt; prefix you can declare constants with a specific type in the same way as you would do with a variable: &lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="kw"&gt;const&lt;/span&gt; &lt;span class="kw"&gt;int&lt;/span&gt; pathwidth = 100;&lt;br /&gt;&lt;span class="kw"&gt;const&lt;/span&gt; &lt;span class="kw"&gt;char&lt;/span&gt; tabulator = &lt;span class="str"&gt;'\t'&lt;/span&gt;;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;Here, &lt;tt&gt;pathwidth&lt;/tt&gt; and &lt;tt&gt;tabulator&lt;/tt&gt; are two typed constants. They are treated just like regular variables except that their values cannot be modified after their definition.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1165683755437997580-1089345974140037252?l=somelogics.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://somelogics.blogspot.com/feeds/1089345974140037252/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://somelogics.blogspot.com/2008/12/constants.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/1089345974140037252'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/1089345974140037252'/><link rel='alternate' type='text/html' href='http://somelogics.blogspot.com/2008/12/constants.html' title='Constants'/><author><name>Priyank</name><uri>http://www.blogger.com/profile/16749090935925725720</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='12361015692322800765'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1165683755437997580.post-7208376652596487143</id><published>2008-12-04T00:40:00.000-08:00</published><updated>2008-12-04T06:54:38.858-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Index'/><title type='text'>INDEX</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_N6ah0svGQ54/STfvJVDCavI/AAAAAAAAAA8/2pqX-MhT6jI/s1600-h/logo.JPG"&gt;&lt;img style="cursor: pointer; width: 320px; height: 73px;" src="http://1.bp.blogspot.com/_N6ah0svGQ54/STfvJVDCavI/AAAAAAAAAA8/2pqX-MhT6jI/s320/logo.JPG" alt="" id="BLOGGER_PHOTO_ID_5275948432035572466" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://somelogics.blogspot.com/2008/12/INDEX.html"&gt;&lt;br /&gt;&lt;/a&gt;&lt;h1&gt; &lt;/h1&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://somelogics.blogspot.com/2008/12/INDEX.html"&gt;&lt;img style="cursor: pointer; width: 274px; height: 48px;" src="http://4.bp.blogspot.com/_N6ah0svGQ54/STeZfpkcsZI/AAAAAAAAAAc/XnL3uGjgq-o/s320/C%2B%2B+1.2.bmp" alt="" id="BLOGGER_PHOTO_ID_5275854257501548946" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);font-size:130%;" &gt;Please Click on the links below to see details :-&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 102);"&gt;&lt;span style="color: rgb(204, 51, 204);"&gt;I&lt;/span&gt; Some basic Concepts Of C++&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;1.&lt;/span&gt;&lt;a style="font-family: trebuchet ms;" href="http://somelogics.blogspot.com/2008/12/introduction-to-c.html"&gt; An introduction to C++&lt;/a&gt;&lt;br /&gt;                1.1 &lt;a href="http://somelogics.blogspot.com/2008/12/introducing-c.html"&gt;Another article on introduction&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;2. &lt;/span&gt;&lt;a style="font-family: trebuchet ms;" href="http://somelogics.blogspot.com/2008/12/structure-of-program-first-program.html"&gt;Structure of a program- The first program&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;3. &lt;/span&gt;&lt;a style="font-family: trebuchet ms;" href="http://somelogics.blogspot.com/2008/12/data-types.html"&gt;Data Types&lt;/a&gt;&lt;br /&gt;4. &lt;a href="http://somelogics.blogspot.com/2008/12/constants.html"&gt;Constants&lt;/a&gt;&lt;br /&gt;5. &lt;a href="http://somelogics.blogspot.com/2008/12/language-comparisons.html"&gt;Language Comparisons&lt;/a&gt;&lt;br /&gt;       5.1 &lt;a href="http://somelogics.blogspot.com/2008/12/comparison-with-c.html"&gt;Comparison with C&lt;/a&gt;&lt;br /&gt;                5.2 &lt;a href="http://somelogics.blogspot.com/2008/12/comparison-with-java.html"&gt;Comparison with Java&lt;/a&gt;&lt;br /&gt;                5.3 &lt;a href="http://somelogics.blogspot.com/2008/12/some-documentation.html"&gt;Some Dcumentation&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;General information about the C++ programming language, including non-technical documents and descriptions: &lt;!-- google_ad_section_start --&gt;  &lt;a name="6006912088492984577"&gt;&lt;/a&gt;   &lt;script type="text/javascript"&gt;  var timestamp = "11:52 PM";  if (timestamp != '') {   var timesplit = timestamp.split(",");   var date_yyyy = timesplit[2];   var timesplit = timesplit[1].split(" ");   var date_dd = timesplit[2];   var date_mmm = timesplit[1].substring(0, 3);  } &lt;/script&gt; &lt;script type="text/javascript"&gt;document.write(date_dd);&lt;/script&gt;&lt;h1&gt;&lt;span class="item-control blog-admin pid-1897023584"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=1165683755437997580&amp;amp;postID=6006912088492984577" title="Edit Post"&gt;&lt;span class="quick-edit-icon"&gt;&lt;br /&gt;&lt;/span&gt; &lt;/a&gt;&lt;/span&gt;&lt;/h1&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1165683755437997580-7208376652596487143?l=somelogics.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://somelogics.blogspot.com/feeds/7208376652596487143/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://somelogics.blogspot.com/2008/12/c-language-tutorial.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/7208376652596487143'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/7208376652596487143'/><link rel='alternate' type='text/html' href='http://somelogics.blogspot.com/2008/12/c-language-tutorial.html' title='INDEX'/><author><name>Priyank</name><uri>http://www.blogger.com/profile/16749090935925725720</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='12361015692322800765'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_N6ah0svGQ54/STfvJVDCavI/AAAAAAAAAA8/2pqX-MhT6jI/s72-c/logo.JPG' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1165683755437997580.post-6778154772229848842</id><published>2008-12-04T00:27:00.000-08:00</published><updated>2008-12-04T00:28:21.181-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++ programming'/><title type='text'>Data Types</title><content type='html'>The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting program just to obtain a simple sentence written on the screen as result. It certainly would have been much faster to type the output sentence by ourselves. However, programming is not limited only to printing simple texts on the screen. In order to go a little further on and to become able to write programs that perform useful tasks that really save us work we need to introduce the concept of variable.&lt;p&gt;Let us think that I ask you to retain the number 5 in your mental memory, and then I ask you to memorize also the number 2 at the same time. You have just stored two different values in your memory. Now, if I ask you to add 1 to the first number I said, you should be retaining the numbers 6 (that is 5+1) and 2 in your memory. Values that we could now for example subtract and obtain 4 as result.&lt;/p&gt;&lt;p&gt;The whole process that you have just done with your mental memory is a simile of what a computer can do with two variables. The same process can be expressed in C++ with the following instruction set: &lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;a = 5;&lt;br /&gt;b = 2;&lt;br /&gt;a = a + 1;&lt;br /&gt;result = a - b;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Obviously, this is a very simple example since we have only used two small integer values, but consider that your computer can store millions of numbers like these at the same time and conduct sophisticated mathematical operations with them.&lt;/p&gt;&lt;p&gt;Therefore, we can define a variable as a portion of memory to store a determined value.&lt;/p&gt;&lt;p&gt;Each variable needs an identifier that distinguishes it from the others, for example, in the previous code the variable identifiers were &lt;tt&gt;a&lt;/tt&gt;, &lt;tt&gt;b&lt;/tt&gt; and &lt;tt&gt;result&lt;/tt&gt;, but we could have called the variables any names we wanted to invent, as long as they were valid identifiers.&lt;/p&gt;&lt;h3&gt;Identifiers&lt;/h3&gt; A valid identifier is a sequence of one or more letters, digits or underscore characters (&lt;tt&gt;_&lt;/tt&gt;). Neither spaces nor punctuation marks or symbols can be part of an identifier. Only letters, digits and single underscore characters are valid. In addition, variable identifiers always have to begin with a letter. They can also begin with an underline character (&lt;tt&gt;_&lt;/tt&gt; ), but in some cases these may be reserved for compiler specific keywords or external identifiers, as well as identifiers containing two successive underscore characters anywhere. In no case they can begin with a digit.&lt;p&gt;Another rule that you have to consider when inventing your own identifiers is that they cannot match any keyword of the C++ language nor your compiler's specific ones, which are &lt;i&gt;reserved keywords&lt;/i&gt;. The standard reserved keywords are:&lt;/p&gt;&lt;p&gt;&lt;tt&gt; asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while&lt;br /&gt;&lt;/tt&gt;&lt;/p&gt;&lt;p&gt;Additionally, alternative representations for some operators cannot be used as identifiers since they are reserved words under some circumstances: &lt;/p&gt;&lt;p&gt;&lt;tt&gt; and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq&lt;br /&gt;&lt;/tt&gt;&lt;/p&gt;&lt;p&gt;Your compiler may also include some additional specific reserved keywords.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Very important:&lt;/b&gt; The C++ language is a "case sensitive" language. That means that an identifier written in capital letters is not equivalent to another one with the same name but written in small letters. Thus, for example, the &lt;tt&gt;RESULT&lt;/tt&gt; variable is not the same as the &lt;tt&gt;result&lt;/tt&gt; variable or the &lt;tt&gt;Result&lt;/tt&gt; variable. These are three different variable identifiers.&lt;/p&gt;&lt;h3&gt;Fundamental data types&lt;/h3&gt; When programming, we store the variables in our computer's memory, but the computer has to know what kind of data we want to store in them, since it is not going to occupy the same amount of memory to store a simple number than to store a single letter or a large number, and they are not going to be interpreted the same way.&lt;p&gt;The memory in our computers is organized in bytes. A byte is the minimum amount of memory that we can manage in C++. A byte can store a relatively small amount of data: one single character or a small integer (generally an integer between 0 and 255). In addition, the computer can manipulate more complex data types that come from grouping several bytes, such as long numbers or non-integer numbers.&lt;/p&gt;&lt;p&gt;Next you have a summary of the basic fundamental data types in C++, as well as the range of values that can be represented with each one:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;table class="boxed"&gt; &lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;th&gt;Size*&lt;/th&gt;&lt;th&gt;Range*&lt;/th&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;char&lt;/tt&gt;&lt;/td&gt;  &lt;td&gt;Character or small integer.&lt;/td&gt;  &lt;td&gt;1byte&lt;/td&gt;  &lt;td&gt;signed: -128 to 127&lt;br /&gt;unsigned: 0 to 255&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;short int&lt;/tt&gt; (&lt;tt&gt;short&lt;/tt&gt;)&lt;/td&gt;  &lt;td&gt;Short Integer.&lt;/td&gt;  &lt;td&gt;2bytes&lt;/td&gt;  &lt;td&gt;signed: -32768 to 32767&lt;br /&gt;unsigned: 0 to 65535&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;int&lt;/tt&gt;&lt;/td&gt;  &lt;td&gt;Integer.&lt;/td&gt;  &lt;td&gt;4bytes&lt;/td&gt;  &lt;td&gt;signed: -2147483648 to 2147483647&lt;br /&gt;unsigned: 0 to 4294967295&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;long int&lt;/tt&gt; (&lt;tt&gt;long&lt;/tt&gt;)&lt;/td&gt;  &lt;td&gt;Long integer.&lt;/td&gt;  &lt;td&gt;4bytes&lt;/td&gt;  &lt;td&gt;signed: -2147483648 to 2147483647&lt;br /&gt;unsigned: 0 to 4294967295&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;bool&lt;/tt&gt;&lt;/td&gt;  &lt;td&gt;Boolean value. It can take one of two values: true or false.&lt;/td&gt;  &lt;td&gt;1byte&lt;/td&gt;  &lt;td&gt;true or false&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;float&lt;/tt&gt;&lt;/td&gt;  &lt;td&gt;Floating point number.&lt;/td&gt;  &lt;td&gt;4bytes&lt;/td&gt;  &lt;td&gt;+/- 3.4e +/- 38 (~7 digits)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;double&lt;/tt&gt;&lt;/td&gt;  &lt;td&gt;Double precision floating point number.&lt;/td&gt;  &lt;td&gt;8bytes&lt;/td&gt;  &lt;td&gt;+/- 1.7e +/- 308 (~15 digits)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;long double&lt;/tt&gt;&lt;/td&gt;  &lt;td&gt;Long double precision floating point number.&lt;/td&gt;  &lt;td&gt;8bytes&lt;/td&gt;  &lt;td&gt;+/- 1.7e +/- 308 (~15 digits)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;tt&gt;wchar_t&lt;/tt&gt;&lt;/td&gt;  &lt;td&gt;Wide character.&lt;/td&gt;  &lt;td&gt;2 &lt;i&gt;or&lt;/i&gt; 4 bytes&lt;/td&gt;  &lt;td&gt;1 wide character&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;* The values of the columns &lt;b&gt;Size&lt;/b&gt; and &lt;b&gt;Range&lt;/b&gt; depend on the system the program is compiled for. The values shown above are those found on most 32-bit systems. But for other systems, the general specification is that &lt;tt&gt;int&lt;/tt&gt; has the natural size suggested by the system architecture (one "&lt;i&gt;word&lt;/i&gt;") and the four integer types &lt;tt&gt;char&lt;/tt&gt;, &lt;tt&gt;short&lt;/tt&gt;, &lt;tt&gt;int&lt;/tt&gt; and &lt;tt&gt;long&lt;/tt&gt; must each one be at least as large as the one preceding it, with &lt;tt&gt;char&lt;/tt&gt; being always 1 byte in size. The same applies to the floating point types &lt;tt&gt;float&lt;/tt&gt;, &lt;tt&gt;double&lt;/tt&gt; and &lt;tt&gt;long double&lt;/tt&gt;, where each one must provide at least as much precision as the preceding one.&lt;/p&gt;&lt;h3&gt;Declaration of variables&lt;/h3&gt; In order to use a variable in C++, we must first declare it specifying which data type we want it to be. The syntax to declare a new variable is to write the specifier of the desired data type (like int, bool, float...) followed by a valid variable identifier. For example:&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="kw"&gt;int&lt;/span&gt; a;&lt;br /&gt;&lt;span class="kw"&gt;float&lt;/span&gt; mynumber;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;These are two valid declarations of variables. The first one declares a variable of type &lt;tt&gt;int&lt;/tt&gt; with the identifier &lt;tt&gt;a&lt;/tt&gt;. The second one declares a variable of type &lt;tt&gt;float&lt;/tt&gt; with the identifier &lt;tt&gt;mynumber&lt;/tt&gt;. Once declared, the variables &lt;tt&gt;a&lt;/tt&gt; and &lt;tt&gt;mynumber&lt;/tt&gt; can be used within the rest of their scope in the program.&lt;/p&gt;&lt;p&gt;If you are going to declare more than one variable of the same type, you can declare all of them in a single statement by separating their identifiers with commas. For example:&lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="kw"&gt;int&lt;/span&gt; a, b, c;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;This declares three variables (&lt;tt&gt;a&lt;/tt&gt;, &lt;tt&gt;b&lt;/tt&gt; and &lt;tt&gt;c&lt;/tt&gt;), all of them of type &lt;tt&gt;int&lt;/tt&gt;, and has exactly the same meaning as:&lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="kw"&gt;int&lt;/span&gt; a;&lt;br /&gt;&lt;span class="kw"&gt;int&lt;/span&gt; b;&lt;br /&gt;&lt;span class="kw"&gt;int&lt;/span&gt; c;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;The integer data types &lt;tt&gt;char&lt;/tt&gt;, &lt;tt&gt;short&lt;/tt&gt;, &lt;tt&gt;long&lt;/tt&gt; and &lt;tt&gt;int&lt;/tt&gt; can be either signed or unsigned depending on the range of numbers needed to be represented. Signed types can represent both positive and negative values, whereas unsigned types can only represent positive values (and zero). This can be specified by using either the specifier &lt;tt&gt;signed&lt;/tt&gt; or the specifier &lt;tt&gt;unsigned&lt;/tt&gt; before the type name. For example: &lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="kw"&gt;unsigned&lt;/span&gt; &lt;span class="kw"&gt;short&lt;/span&gt; &lt;span class="kw"&gt;int&lt;/span&gt; NumberOfSisters;&lt;br /&gt;&lt;span class="kw"&gt;signed&lt;/span&gt; &lt;span class="kw"&gt;int&lt;/span&gt; MyAccountBalance;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;By default, if we do not specify either &lt;tt&gt;signed&lt;/tt&gt; or &lt;tt&gt;unsigned&lt;/tt&gt; most compiler settings will assume the type to be signed, therefore instead of the second declaration above we could have written:&lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="kw"&gt;int&lt;/span&gt; MyAccountBalance;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;with exactly the same meaning (with or without the keyword &lt;tt&gt;signed&lt;/tt&gt;)&lt;/p&gt;&lt;p&gt;An exception to this general rule is the &lt;tt&gt;char&lt;/tt&gt; type, which exists by itself and is considered a different fundamental data type from &lt;tt&gt;signed char&lt;/tt&gt; and &lt;tt&gt;unsigned char&lt;/tt&gt;, thought to store characters. You should use either &lt;tt&gt;signed&lt;/tt&gt; or &lt;tt&gt;unsigned&lt;/tt&gt; if you intend to store numerical values in a &lt;tt&gt;char&lt;/tt&gt;-sized variable.&lt;/p&gt;&lt;p&gt;&lt;tt&gt;short&lt;/tt&gt; and &lt;tt&gt;long&lt;/tt&gt; can be used alone as type specifiers. In this case, they refer to their respective integer fundamental types: &lt;tt&gt;short&lt;/tt&gt; is equivalent to &lt;tt&gt;short int&lt;/tt&gt; and &lt;tt&gt;long&lt;/tt&gt; is equivalent to &lt;tt&gt;long int&lt;/tt&gt;. The following two variable declarations are equivalent:&lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="kw"&gt;short&lt;/span&gt; Year;&lt;br /&gt;&lt;span class="kw"&gt;short&lt;/span&gt; &lt;span class="kw"&gt;int&lt;/span&gt; Year;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Finally, &lt;tt&gt;signed&lt;/tt&gt; and &lt;tt&gt;unsigned&lt;/tt&gt; may also be used as standalone type specifiers, meaning the same as &lt;tt&gt;signed int&lt;/tt&gt; and &lt;tt&gt;unsigned int&lt;/tt&gt; respectively. The following two declarations are equivalent: &lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="kw"&gt;unsigned&lt;/span&gt; NextYear;&lt;br /&gt;&lt;span class="kw"&gt;unsigned&lt;/span&gt; &lt;span class="kw"&gt;int&lt;/span&gt; NextYear;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;To see what variable declarations look like in action within a program, we are going to see the C++ code of the example about your mental memory proposed at the beginning of this section:&lt;/p&gt;&lt;table class="codebox"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="comm"&gt;// operating with variables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="prep"&gt;#include &lt;iostream&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw"&gt;using&lt;/span&gt; &lt;span class="kw"&gt;namespace&lt;/span&gt; std;&lt;br /&gt;&lt;br /&gt;&lt;span class="kw"&gt;int&lt;/span&gt; main ()&lt;br /&gt;{&lt;br /&gt; &lt;span class="comm"&gt;// declaring variables:&lt;/span&gt;&lt;br /&gt; &lt;span class="kw"&gt;int&lt;/span&gt; a, b;&lt;br /&gt; &lt;span class="kw"&gt;int&lt;/span&gt; result;&lt;br /&gt;&lt;br /&gt; &lt;span class="comm"&gt;// process:&lt;/span&gt;&lt;br /&gt; a = 5;&lt;br /&gt; b = 2;&lt;br /&gt; a = a + 1;&lt;br /&gt; result = a - b;&lt;br /&gt;&lt;br /&gt; &lt;span class="comm"&gt;// print out the result:&lt;/span&gt;&lt;br /&gt; cout &lt;&lt; result;&lt;br /&gt;&lt;br /&gt; &lt;span class="comm"&gt;// terminate the program:&lt;/span&gt;&lt;br /&gt; &lt;span class="kw"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class="result"&gt;&lt;pre&gt;4&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Do not worry if something else than the variable declarations themselves looks a bit strange to you. You will see the rest in detail in coming sections. &lt;/p&gt;&lt;h3&gt;Scope of variables&lt;/h3&gt; All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous code at the beginning of the body of the function main when we declared that &lt;tt&gt;a&lt;/tt&gt;, &lt;tt&gt;b&lt;/tt&gt;, and &lt;tt&gt;result&lt;/tt&gt; were of type &lt;tt&gt;int&lt;/tt&gt;.&lt;p&gt;A variable can be either of global or local scope. A global variable is a variable declared in the main body of the source code, outside all functions, while a local variable is one declared within the body of a function or a block.&lt;/p&gt;&lt;p&gt;&lt;img src="http://www.cplusplus.com/files/2-imgvars1.gif" /&gt;&lt;/p&gt;&lt;p&gt;Global variables can be referred from anywhere in the code, even inside functions, whenever it is after its declaration.&lt;/p&gt;&lt;p&gt;The scope of local variables is limited to the block enclosed in braces ({}) where they are declared. For example, if they are declared at the beginning of the body of a function (like in function &lt;tt&gt;main&lt;/tt&gt;) their scope is between its declaration point and the end of that function. In the example above, this means that if another function existed in addition to &lt;tt&gt;main&lt;/tt&gt;, the local variables declared in &lt;tt&gt;main&lt;/tt&gt; could not be accessed from the other function and vice versa.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3&gt;Initialization of variables&lt;/h3&gt; When declaring a regular local variable, its value is by default undetermined. But you may want a variable to store a concrete value at the same moment that it is declared. In order to do that, you can initialize the variable. There are two ways to do this in C++:&lt;p&gt;The first one, known as c-like, is done by appending an equal sign followed by the value to which the variable will be initialized:&lt;/p&gt;&lt;p&gt;&lt;tt&gt;type identifier = initial_value ;&lt;/tt&gt;&lt;/p&gt;&lt;p&gt;For example, if we want to declare an int variable called a initialized with a value of 0 at the moment in which it is declared, we could write:&lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="kw"&gt;int&lt;/span&gt; a = 0;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;The other way to initialize variables, known as constructor initialization, is done by enclosing the initial value between parentheses (&lt;tt&gt;()&lt;/tt&gt;): &lt;/p&gt;&lt;p&gt;&lt;tt&gt;type identifier (initial_value) ;&lt;/tt&gt;&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="kw"&gt;int&lt;/span&gt; a (0); &lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Both ways of initializing variables are valid and equivalent in C++.&lt;/p&gt;&lt;table class="codebox"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="comm"&gt;// initialization of variables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="prep"&gt;#include &lt;iostream&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw"&gt;using&lt;/span&gt; &lt;span class="kw"&gt;namespace&lt;/span&gt; std;&lt;br /&gt;&lt;br /&gt;&lt;span class="kw"&gt;int&lt;/span&gt; main ()&lt;br /&gt;{&lt;br /&gt; &lt;span class="kw"&gt;int&lt;/span&gt; a=5;               &lt;span class="comm"&gt;// initial value = 5&lt;/span&gt;&lt;br /&gt; &lt;span class="kw"&gt;int&lt;/span&gt; b(2);              &lt;span class="comm"&gt;// initial value = 2&lt;/span&gt;&lt;br /&gt; &lt;span class="kw"&gt;int&lt;/span&gt; result;            &lt;span class="comm"&gt;// initial value undetermined&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; a = a + 3;&lt;br /&gt; result = a - b;&lt;br /&gt; cout &lt;&lt; result;&lt;br /&gt;&lt;br /&gt; &lt;span class="kw"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class="result"&gt;&lt;pre&gt;6&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;h3&gt;Introduction to strings&lt;/h3&gt; Variables that can store non-numerical values that are longer than one single character are known as strings.&lt;p&gt;The C++ language library provides support for strings through the standard &lt;tt&gt;string&lt;/tt&gt; class. This is not a fundamental type, but it behaves in a similar way as fundamental types do in its most basic usage.&lt;br /&gt;&lt;br /&gt;A first difference with fundamental data types is that in order to declare and use objects (variables) of this type we need to include an additional header file in our source code: &lt;tt&gt;&lt;string&gt;&lt;/tt&gt; and have access to the &lt;tt&gt;std&lt;/tt&gt; namespace (which we already had in all our previous programs thanks to the &lt;tt&gt;using namespace&lt;/tt&gt; statement).&lt;/p&gt;&lt;table class="codebox"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="comm"&gt;// my first string&lt;/span&gt;&lt;br /&gt;&lt;span class="prep"&gt;#include &lt;iostream&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="prep"&gt;#include &lt;string&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw"&gt;using&lt;/span&gt; &lt;span class="kw"&gt;namespace&lt;/span&gt; std;&lt;br /&gt;&lt;br /&gt;&lt;span class="kw"&gt;int&lt;/span&gt; main ()&lt;br /&gt;{&lt;br /&gt; string mystring = &lt;span class="str"&gt;"This is a string"&lt;/span&gt;;&lt;br /&gt; cout &lt;&lt; mystring;&lt;br /&gt; &lt;span class="kw"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class="result"&gt;&lt;pre&gt;This is a string&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;As you may see in the previous example, strings can be initialized with any valid string literal just like numerical type variables can be initialized to any valid numerical literal. Both initialization formats are valid with strings:&lt;/p&gt;&lt;table class="snippet"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;string mystring = &lt;span class="str"&gt;"This is a string"&lt;/span&gt;;&lt;br /&gt;string mystring (&lt;span class="str"&gt;"This is a string"&lt;/span&gt;);&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;Strings can also perform all the other basic operations that fundamental data types can, like being declared without an initial value and being assigned values during execution:&lt;/p&gt;&lt;table style="width: 682px; height: 247px;" class="codebox"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="code"&gt;&lt;pre&gt;&lt;span class="comm"&gt;// my first string&lt;/span&gt;&lt;br /&gt;&lt;span class="prep"&gt;#include &lt;iostream&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="prep"&gt;#include &lt;string&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw"&gt;using&lt;/span&gt; &lt;span class="kw"&gt;namespace&lt;/span&gt; std;&lt;br /&gt;&lt;br /&gt;&lt;span class="kw"&gt;int&lt;/span&gt; main ()&lt;br /&gt;{&lt;br /&gt; string mystring;&lt;br /&gt; mystring = &lt;span class="str"&gt;"This is the initial string content"&lt;/span&gt;;&lt;br /&gt; cout &lt;&lt; mystring &lt;&lt; endl;&lt;br /&gt; mystring = &lt;span class="str"&gt;"This is a different string content"&lt;/span&gt;;&lt;br /&gt; cout &lt;&lt; mystring &lt;&lt; endl;&lt;br /&gt; &lt;span class="kw"&gt;return&lt;/span&gt; 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class="result"&gt;&lt;pre&gt;This is the initial string content&lt;br /&gt;This is a different string content&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1165683755437997580-6778154772229848842?l=somelogics.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://somelogics.blogspot.com/feeds/6778154772229848842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://somelogics.blogspot.com/2008/12/data-types.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/6778154772229848842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/6778154772229848842'/><link rel='alternate' type='text/html' href='http://somelogics.blogspot.com/2008/12/data-types.html' title='Data Types'/><author><name>Priyank</name><uri>http://www.blogger.com/profile/16749090935925725720</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='12361015692322800765'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1165683755437997580.post-5956671972236977082</id><published>2008-12-03T23:54:00.000-08:00</published><updated>2008-12-04T00:15:33.384-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++ programming'/><title type='text'>Structure of a program -The First Program</title><content type='html'>Probably the best way to start learning a programming language is by writing a program. Therefore, here is our first program:&lt;br /&gt;&lt;p&gt;The first panel shows the source code for our first program.&lt;/p&gt;&lt;p&gt;--------------------------------------------------------------------------------------------&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt;#include&lt;iostream.h&gt; &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;  &lt;/span&gt;  &lt;span style="color: rgb(51, 51, 255); font-weight: bold;"&gt; //Header file for cout fuction&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="font-weight: bold; color: rgb(51, 51, 255);"&gt;&lt;span style="font-size:100%;"&gt;&lt;tt&gt;// my first program in C++&lt;/tt&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;int main ( )&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;{                                                &lt;span style="color: rgb(51, 51, 255);"&gt;//Start of block&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;      cout&lt;&lt;&lt;span style="color: rgb(204, 0, 0);"&gt;"Hello Everybody, its my first program\n"&lt;/span&gt;;    &lt;span style="color: rgb(51, 51, 255);"&gt;//Printing a statement&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;      &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;      return &lt;span style="font-family: arial; color: rgb(102, 51, 102);font-size:100%;" &gt;0&lt;/span&gt;;                                                                                     &lt;span style="color: rgb(51, 51, 255);"&gt;  //return fuction&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;      &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;      }                                                                                                    &lt;span style="color: rgb(51, 51, 255);"&gt;  //End of block&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;------------------------------------------------------------------------------------------------&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="text-align: center;"&gt;Here is the Test run&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_N6ah0svGQ54/STePfF0kHwI/AAAAAAAAAAU/Q6eA1RiefPw/s1600-h/C%2B%2B+1.1.bmp"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 407px; height: 107px;" src="http://2.bp.blogspot.com/_N6ah0svGQ54/STePfF0kHwI/AAAAAAAAAAU/Q6eA1RiefPw/s320/C%2B%2B+1.1.bmp" alt="" id="BLOGGER_PHOTO_ID_5275843252789190402" border="0" /&gt;&lt;/a&gt; The second one shows the result of the program once compiled and executed. The way to edit and compile a program depends on the compiler you are using. Depending on whether it has a Development Interface or not and on its version. Consult the compilers section and the manual or help included with your compiler if you have doubts on how to compile a C++ console program.&lt;/p&gt;&lt;p&gt;The previous program is the typical program that programmer apprentices write for the first time, and its result is the printing on screen of the "Hello World!" sentence. It is one of the simplest programs that can be written in C++, but it already contains the fundamental components that every C++ program has. We are going to look line by line at the code we have just written:&lt;/p&gt;&lt;dl&gt;&lt;dt style="font-weight: bold; color: rgb(51, 51, 255);"&gt;&lt;span style="font-size:100%;"&gt;&lt;tt&gt;// my first program in C++&lt;/tt&gt;&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt; This is a comment line. All lines beginning with two slash signs (&lt;tt&gt;//&lt;/tt&gt;) are considered comments and do not have any effect on the behavior of the program. The programmer can use them to include short explanations or observations within the source code itself. In this case, the line is a brief description of what our program is.&lt;br /&gt;&lt;/dd&gt;&lt;dt&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt;#include&lt;iostream.h&gt;&lt;br /&gt;&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt; Lines beginning with a hash sign (&lt;tt&gt;#&lt;/tt&gt;) are directives for the preprocessor. They are not regular code lines with expressions but indications for the compiler's preprocessor. In this case the directive &lt;tt&gt;#include &lt;iostream&gt;&lt;/tt&gt; tells the preprocessor to include the iostream standard file. This specific file (iostream) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program.&lt;br /&gt;&lt;/dd&gt;&lt;dt&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;int main ( )&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt; This line corresponds to the beginning of the definition of the main function. The main function is the point by where all C++ programs start their execution, independently of its location within the source code. It does not matter whether there are other functions with other names defined before or after it - the instructions contained within this function's definition will always be the first ones to be executed in any C++ program. For that same reason, it is essential that all C++ programs have a &lt;tt&gt;main&lt;/tt&gt; function.&lt;p&gt;The word &lt;tt&gt;main&lt;/tt&gt; is followed in the code by a pair of parentheses (&lt;tt&gt;()&lt;/tt&gt;). That is because it is a function declaration: In C++, what differentiates a function declaration from other types of expressions are these parentheses that follow its name. Optionally, these parentheses may enclose a list of parameters within them.&lt;/p&gt;&lt;p&gt;Right after these parentheses we can find the body of the main function enclosed in braces (&lt;tt&gt;{}&lt;/tt&gt;). What is contained within these braces is what the function does when it is executed.&lt;br /&gt;&lt;/p&gt;&lt;/dd&gt;&lt;dt&gt;&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;cout&lt;&lt;&lt;span style="color: rgb(204, 0, 0);"&gt;"Hello Everybody, its my first program\n"&lt;/span&gt;;&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt; This line is a C++ statement. A statement is a simple or compound expression that can actually produce some effect. In fact, this statement performs the only action that generates a visible effect in our first program.&lt;p&gt;&lt;tt&gt;cout&lt;/tt&gt; represents the standard output stream in C++, and the meaning of the entire statement is to insert a sequence of characters (in this case the &lt;tt&gt;Hello.... &lt;/tt&gt; sequence of characters) into the standard output stream (which usually is the screen).&lt;/p&gt;&lt;p&gt;&lt;tt&gt;cout&lt;/tt&gt; is declared in the &lt;tt&gt;iostream&lt;/tt&gt; standard file within the &lt;tt&gt;std&lt;/tt&gt; namespace, so that's why we needed to include that specific file and to declare that we were going to use this specific namespace earlier in our code.&lt;/p&gt;&lt;p&gt;Notice that the statement ends with a semicolon character (&lt;tt&gt;;&lt;/tt&gt;). This character is used to mark the end of the statement and in fact it must be included at the end of all expression statements in all C++ programs (one of the most common syntax errors is indeed to forget to include some semicolon after a statement).&lt;/p&gt;&lt;/dd&gt;&lt;dt&gt;          &lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;\n&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;It is a newline operator&lt;br /&gt;&lt;/dd&gt;&lt;dt&gt;&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;  return &lt;span style="font-family: arial; color: rgb(102, 51, 102);font-size:100%;" &gt;0&lt;/span&gt;;&lt;br /&gt;&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt; The return statement causes the main function to finish. return may be followed by a return code (in our example is followed by the return code &lt;tt&gt;0&lt;/tt&gt;). A return code of 0 for the main function is generally interpreted as the program worked as expected without any errors during its execution. This is the most usual way to end a C++ console program.&lt;/dd&gt;&lt;/dl&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1165683755437997580-5956671972236977082?l=somelogics.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://somelogics.blogspot.com/feeds/5956671972236977082/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://somelogics.blogspot.com/2008/12/structure-of-program-first-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/5956671972236977082'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/5956671972236977082'/><link rel='alternate' type='text/html' href='http://somelogics.blogspot.com/2008/12/structure-of-program-first-program.html' title='Structure of a program -The First Program'/><author><name>Priyank</name><uri>http://www.blogger.com/profile/16749090935925725720</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='12361015692322800765'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_N6ah0svGQ54/STePfF0kHwI/AAAAAAAAAAU/Q6eA1RiefPw/s72-c/C%2B%2B+1.1.bmp' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1165683755437997580.post-6006912088492984577</id><published>2008-12-03T23:52:00.000-08:00</published><updated>2008-12-03T23:54:39.024-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++ programming'/><title type='text'>An Introduction to C++</title><content type='html'>( by &lt;em&gt;Saveen             Reddy&lt;/em&gt; and &lt;em&gt;G. Bowden             Wise )&lt;/em&gt;         &lt;p&gt;             Welcome to the inaugural edition of the             ObjectiveViewPoint column! Here we will touch on many             aspects of object-orientation. The word object has             surfaced in more ways than you can count. There are             OOPLs (Object-Oriented Programming Languages) and OODBs             (Object-Oriented Databases), OOA (object-oriented             analysis), and OOD (object-oriented design). We are             sure you can come up with some OOisms of your own.         &lt;/p&gt;         &lt;p&gt;             Our goal in this column is to explore             object-orientation through practical object-oriented             programming. This time, we look at C++, but in the             future we will explore other areas of             object-orientation. Learning an object-oriented             language-a whole new way of programming-will pave the             way for many exciting topics down the road.         &lt;/p&gt;         &lt;p&gt;             Our intended audience consists of humble beginners to             seasoned hackers. We assume that you have programmed in             at least one procedural language, such as C or Pascal.             Even if you are familiar with C++, please stay with us,             you may learn some interesting new language features.             Also, we will illustrate our points with many             self-contained examples that you may later wish to             incorporate into your own programs.         &lt;/p&gt;         &lt;h2&gt;             C++: A Historical Perspective         &lt;/h2&gt;         &lt;p&gt;             We begin our journey of C++ with a little history. C,             the predecessor to C++, has become one of the most             popular programming languages. Originally designed for             systems programming, C enables programmers to write             efficient code and provided close access to the             machine. C compilers, found on practically every Unix             system, are now available with most operating systems.         &lt;/p&gt;         &lt;p&gt;             During the 1980s and into the 1990s, an explosive             growth in object-oriented technology began with the             introduction of the Smalltalk language. Object-Oriented             Programming (OOP) began to replace the more traditional             structured programming techniques. This explosion led             to the development of languages which support             programming with objects. Many new object-oriented             programming languages appeared: Object-Pascal,             Modula-2, Mesa, Cedar, Neon, Objective-C, LISP with the             Common List Object System (CLOS), and, of course, C++.             Although many of these languages appeared in the 1980s,             many ideas of OOP were taken from Simula-67. Yes! OOP             has been around since 1967.         &lt;/p&gt;         &lt;p&gt;             C++ originated with Bjarne Stroustrop. In the simplest             sense, if not the most accurate, we can consider it to             be a better C. Although it is not an entirely new             language, C++ represents a significant extension of C             abilities. We might then consider C to be a subset of             C++. C++ supports essentially every desirable behavior             and most of the undesirable ones of its predecessor,             but provides general language improvements as well as             adding OOP capability. Note that using C++ does not             imply that your are doing OOP. C++ does not force you             to use its OOP features. You can simply create             structured code that uses only C++'s non-OOP             features.         &lt;/p&gt;         &lt;h2&gt;             C++: A Better C         &lt;/h2&gt;         &lt;p&gt;             The designers of C++ wanted to add object-oriented             mechanisms without compromising the efficiency and             simplicity that made C so popular. One of the driving             principles for the language designers was to hide             complexity from the programmer, allowing her to             concentrate on the problem at hand.         &lt;/p&gt;         &lt;p&gt;             Because C++ retains C as a subset, it gains many of the             attractive features of the C language, such as             efficiency, closeness to the machine, and a variety of             built-in types. A number of new features were added to             C++ to make the language even more robust, many of             which are not used by novice programmers. By             introducing these new features here, we hope that you             will begin to use them in your own programs early on             and gain their benefits. Some of the features we will             look at are the role of constants, inline expansion,             references, declaration statements, user defined types,             overloading, and the free store.         &lt;/p&gt;         &lt;p&gt;             Most of these features can be summarized by two             important design goals: strong compiler type checking             and a user-extensible language.         &lt;/p&gt;         &lt;p&gt;             By enforcing stricter type-checking, the C++ compiler             makes us acutely aware of data types in our             expressions. Stronger type checking is provided through             several mechanisms, including: function argument type             checking, conversions, and a few other features we will             examine below.         &lt;/p&gt;         &lt;p&gt;             C++ also enables programmers to incorporate new types             into the language, through the use of classes. A class             is a user-defined type. The compiler can treat new             types as if they are one of the built-in types. This is             a very powerful feature. In addition, the class             provides the mechanism for data abstraction and             encapsulation, which are key to object-oriented             programming. As we examine some of the new features of             C++ we will see these two goals resurface again and             again.         &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1165683755437997580-6006912088492984577?l=somelogics.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://somelogics.blogspot.com/feeds/6006912088492984577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://somelogics.blogspot.com/2008/12/introduction-to-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/6006912088492984577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1165683755437997580/posts/default/6006912088492984577'/><link rel='alternate' type='text/html' href='http://somelogics.blogspot.com/2008/12/introduction-to-c.html' title='An Introduction to C++'/><author><name>Priyank</name><uri>http://www.blogger.com/profile/16749090935925725720</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='12361015692322800765'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>