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

<channel>
	<title>Zero Intellect &#187; data types</title>
	<atom:link href="http://www.zerointellect.com/tag/data-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zerointellect.com</link>
	<description>Technology Blog requiring Zero Intellect to follow !!!</description>
	<lastBuildDate>Mon, 28 Jun 2010 14:09:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Exceeding the range of data types in C++</title>
		<link>http://www.zerointellect.com/programming/exceeding-the-range-of-data-types-in-c/</link>
		<comments>http://www.zerointellect.com/programming/exceeding-the-range-of-data-types-in-c/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 10:20:37 +0000</pubDate>
		<dc:creator>zrydento</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[borland]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[data types]]></category>
		<category><![CDATA[exceed]]></category>
		<category><![CDATA[int]]></category>
		<category><![CDATA[integer]]></category>
		<category><![CDATA[range]]></category>
		<category><![CDATA[Turbo C++]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://www.zerointellect.com/?p=33</guid>
		<description><![CDATA[<p> </p>
<p>My friend recently gave his C++ oral examination and one of the questions asked by the invigilators was regarding incrementing a variable after it has been set to the maximum value in its range</p>
<p>To be specific, in his case the invigilator asked him the output of a variable of type int if initialized to 32765 and <p>Continue reading <a href="http://www.zerointellect.com/programming/exceeding-the-range-of-data-types-in-c/">Exceeding the range of data types in C++</a></p>]]></description>
			<content:encoded><![CDATA[<p> </p>
<p>My friend recently gave his C++ oral examination and one of the questions asked by the invigilators was regarding incrementing a variable after it has been set to the maximum value in its range</p>
<p>To be specific, in his case the invigilator asked him the output of a variable of type int if initialized to 32765 and then incremented by 1</p>
<p> </p>
<p><strong>Sample Code</strong></p>
<p> </p>
<blockquote><p><strong>int i = 32765;</strong></p>
<p><strong>i++;</strong></p>
<p><strong>cout&lt;&lt;i;</strong></p></blockquote>
<p> </p>
<p><strong>Question:</strong> What is the output value of i ?</p>
<p> </p>
<p>Now as we know the range for an integer in C++ is from -32,768 to 32,767 or from 0 to 65535</p>
<p> </p>
<p>As per the official documentation in the Turbo C++ compiler</p>
<p> </p>
<blockquote><p><strong>Integer data type</strong></p>
<p><strong>Variables of type int are one word in length. They can be signed (default) or unsigned, which means they have a range of -32,768 to 32,767 and 0 to 65,535, respectively</strong></p></blockquote>
<p> </p>
<p>To demonstrate and verify the actual output, I quickly coded the program below</p>
<p> </p>
<blockquote><p><strong># include &lt;iostream.h&gt;</strong></p>
<p><strong># include &lt;conio.h&gt;</strong></p>
<p><strong> </strong></p>
<p><strong>void main()</strong></p>
<p><strong>{</strong></p>
<p><strong>   clrscr();</strong></p>
<p><strong> </strong></p>
<p><strong>   int i = 32765;</strong></p>
<p><strong> </strong></p>
<p><strong>   for(int j=5;j&lt;10;i++)</strong></p>
<p><strong>   {</strong></p>
<p><strong>         j++;</strong></p>
<p><strong>         cout&lt;&lt;i&lt;&lt;&#8221;\n&#8221;;</strong></p>
<p><strong>   }</strong></p>
<p><strong>   getch();</strong></p>
<p><strong>}</strong></p></blockquote>
<p> </p>
<p>A screenshot of the output of the sample above is as under</p>
<p> </p>
<p style="text-align: center"> <img class="aligncenter" src="http://www.zerointellect.com/uploads/0000001-output.png" alt="" width="500" height="258" /> </p>
<p> </p>
<p>This brings us to the conclusion that the variable is incremented until the maximum value of its range (32,767) and is then reinitialized back (-32,768) to the beginning of the range automatically in a circular fashion</p>
<p> </p>
<p style="text-align: center"><img class=" aligncenter" src="http://www.zerointellect.com/uploads/0000001-diagram.png" alt="Incrementing Integer Flow" width="450" height="150" /></p>
<p> </p>
<p>The diagram above gives a graphical representation of what happens when an integer is incremented after being set to the maximum value in its range</p>
<p> </p>
<p>Happy Coding</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zerointellect.com/programming/exceeding-the-range-of-data-types-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

