<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: 2.3 &#8212; Variable sizes and the sizeof operator</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/23-variable-sizes-and-the-sizeof-operator/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/23-variable-sizes-and-the-sizeof-operator/</link>
	<description></description>
	<lastBuildDate>Wed, 08 Sep 2010 10:51:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: JD</title>
		<link>http://www.learncpp.com/cpp-tutorial/23-variable-sizes-and-the-sizeof-operator/comment-page-1/#comment-91124</link>
		<dc:creator>JD</dc:creator>
		<pubDate>Mon, 30 Aug 2010 21:25:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=43#comment-91124</guid>
		<description>So, if I understand this correctly, the computer moves data around in 32-bit chunks (4 bytes), but in my C++ program I can assign variables to a single byte of memory.  This seems contradictory to me.

I guess my question boils down to:  Say I have a program that uses a large number of variables, so space matters.  One byte will suffice for the data I need to carry so to save space I assign them as chars (1 byte).  But, if the smallest &quot;chunk&quot; that the computer passes around is 4 bytes, does this actually save any space?  Or would this effectively use the same amount of memory as if I made my variables ints (4 bytes, or one full word)?

This is a somewhat subtle question, so let me know if I&#039;m not being clear.

PS - Thanks for a clear, organized, and well-written tutorial!  I&#039;ve really enjoyed it so far.</description>
		<content:encoded><![CDATA[<p>So, if I understand this correctly, the computer moves data around in 32-bit chunks (4 bytes), but in my C++ program I can assign variables to a single byte of memory.  This seems contradictory to me.</p>
<p>I guess my question boils down to:  Say I have a program that uses a large number of variables, so space matters.  One byte will suffice for the data I need to carry so to save space I assign them as chars (1 byte).  But, if the smallest &#8220;chunk&#8221; that the computer passes around is 4 bytes, does this actually save any space?  Or would this effectively use the same amount of memory as if I made my variables ints (4 bytes, or one full word)?</p>
<p>This is a somewhat subtle question, so let me know if I&#8217;m not being clear.</p>
<p>PS &#8211; Thanks for a clear, organized, and well-written tutorial!  I&#8217;ve really enjoyed it so far.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gerald Parsons</title>
		<link>http://www.learncpp.com/cpp-tutorial/23-variable-sizes-and-the-sizeof-operator/comment-page-1/#comment-88651</link>
		<dc:creator>Gerald Parsons</dc:creator>
		<pubDate>Sun, 18 Jul 2010 20:41:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=43#comment-88651</guid>
		<description>This tutorial is so easy. It makes learning
 programing so easy. The problem comes once 
you get out of C++ and try to understand 
msdn help. These guys from Microsoft are from
 outer space. Just try looking up some of the 
things you learn here and see if you can get 
anything that explains it in common english. 
I could sure use a tutorial on how to use
 Microsoft help, once you get to the help 
you need. Some times they just go round and 
round.</description>
		<content:encoded><![CDATA[<p>This tutorial is so easy. It makes learning<br />
 programing so easy. The problem comes once<br />
you get out of C++ and try to understand<br />
msdn help. These guys from Microsoft are from<br />
 outer space. Just try looking up some of the<br />
things you learn here and see if you can get<br />
anything that explains it in common english.<br />
I could sure use a tutorial on how to use<br />
 Microsoft help, once you get to the help<br />
you need. Some times they just go round and<br />
round.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anon</title>
		<link>http://www.learncpp.com/cpp-tutorial/23-variable-sizes-and-the-sizeof-operator/comment-page-1/#comment-77795</link>
		<dc:creator>Anon</dc:creator>
		<pubDate>Wed, 03 Feb 2010 17:23:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=43#comment-77795</guid>
		<description>So does it really matter what variable type you use? Dont get me wrong i want to use the right one, but it seems a task to remember all of the maximum values etc.

is there a trick to it?

There&#039;s an awful lot to choose from.</description>
		<content:encoded><![CDATA[<p>So does it really matter what variable type you use? Dont get me wrong i want to use the right one, but it seems a task to remember all of the maximum values etc.</p>
<p>is there a trick to it?</p>
<p>There&#8217;s an awful lot to choose from.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mulky</title>
		<link>http://www.learncpp.com/cpp-tutorial/23-variable-sizes-and-the-sizeof-operator/comment-page-1/#comment-75879</link>
		<dc:creator>Mulky</dc:creator>
		<pubDate>Wed, 06 Jan 2010 21:05:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=43#comment-75879</guid>
		<description>I bet you say that to all the ladies.</description>
		<content:encoded><![CDATA[<p>I bet you say that to all the ladies.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anonymous</title>
		<link>http://www.learncpp.com/cpp-tutorial/23-variable-sizes-and-the-sizeof-operator/comment-page-1/#comment-65382</link>
		<dc:creator>anonymous</dc:creator>
		<pubDate>Sat, 01 Aug 2009 00:50:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=43#comment-65382</guid>
		<description>Greg,  means you display the symbol of &#039;\&#039;, like ? or ! if ? or ! don&#039;t work already.  t shows , then the letter t.  The reason is because &#039;\&#039; isn&#039;t a valid symbol for a string; the compiler seems to ignore it.

And also, a makes a beating sound. :) /

Sorry, can&#039;t figure out why the backslash isn&#039;t showing....</description>
		<content:encoded><![CDATA[<p>Greg,  means you display the symbol of &#8216;\&#8217;, like ? or ! if ? or ! don&#8217;t work already.  t shows , then the letter t.  The reason is because &#8216;\&#8217; isn&#8217;t a valid symbol for a string; the compiler seems to ignore it.</p>
<p>And also, a makes a beating sound. :) /</p>
<p>Sorry, can&#8217;t figure out why the backslash isn&#8217;t showing&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/23-variable-sizes-and-the-sizeof-operator/comment-page-1/#comment-59763</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sat, 02 May 2009 05:34:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=43#comment-59763</guid>
		<description>I present a better solution to this problem in &lt;a href=&quot;http://www.learncpp.com/cpp-tutorial/07-a-few-common-cpp-problems/&quot; rel=&quot;nofollow&quot;&gt;lesson 0.7 -- a few common cpp problems&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>I present a better solution to this problem in <a href="http://www.learncpp.com/cpp-tutorial/07-a-few-common-cpp-problems/" rel="nofollow">lesson 0.7 &#8212; a few common cpp problems</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/23-variable-sizes-and-the-sizeof-operator/comment-page-1/#comment-59744</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sat, 02 May 2009 04:34:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=43#comment-59744</guid>
		<description>Why would you want to? :)

Stroustrup says &lt;a href=&quot;http://www.research.att.com/~bs/bs_faq2.html#overload-dot&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;:

&lt;blockquote&gt;
Sizeof cannot be overloaded because built-in operations, such as incrementing a pointer into an array implicitly depends on it. Consider:

	X a[10];
	X* p = &amp;a[3];
	X* q = &amp;a[3];
	p++;	// p points to a[4]
		// thus the integer value of p must be
		// sizeof(X) larger than the integer value of q

Thus, sizeof(X) could not be given a new and different meaning by the programmer without violating basic language rules. 
&lt;/blockquote&gt;</description>
		<content:encoded><![CDATA[<p>Why would you want to? :)</p>
<p>Stroustrup says <a href="http://www.research.att.com/~bs/bs_faq2.html#overload-dot" rel="nofollow">here</a>:</p>
<blockquote><p>
Sizeof cannot be overloaded because built-in operations, such as incrementing a pointer into an array implicitly depends on it. Consider:</p>
<p>	X a[10];<br />
	X* p = &amp;a[3];<br />
	X* q = &amp;a[3];<br />
	p++;	// p points to a[4]<br />
		// thus the integer value of p must be<br />
		// sizeof(X) larger than the integer value of q</p>
<p>Thus, sizeof(X) could not be given a new and different meaning by the programmer without violating basic language rules.
</p></blockquote>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emmet</title>
		<link>http://www.learncpp.com/cpp-tutorial/23-variable-sizes-and-the-sizeof-operator/comment-page-1/#comment-58376</link>
		<dc:creator>Emmet</dc:creator>
		<pubDate>Sat, 18 Apr 2009 17:01:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=43#comment-58376</guid>
		<description>&lt;pre&gt;int y = 30, x = y * 1000;
	Sleep(x);&lt;/pre&gt;

Why couldn&#039;t you say;
&lt;pre&gt;int y = 30000&lt;/pre&gt;

Or better yet, just;
&lt;pre&gt;system(&quot;pause&quot;);
return 0;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>int y = 30, x = y * 1000;
	Sleep(x);</pre>
<p>Why couldn&#8217;t you say;</p>
<pre>int y = 30000</pre>
<p>Or better yet, just;</p>
<pre>system(&quot;pause&quot;);
return 0;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ranjan</title>
		<link>http://www.learncpp.com/cpp-tutorial/23-variable-sizes-and-the-sizeof-operator/comment-page-1/#comment-55129</link>
		<dc:creator>Ranjan</dc:creator>
		<pubDate>Wed, 01 Apr 2009 16:02:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=43#comment-55129</guid>
		<description>what the resone behind it, why you can&#039;t overload the size of operator ?

REgards,
Ranjan</description>
		<content:encoded><![CDATA[<p>what the resone behind it, why you can&#8217;t overload the size of operator ?</p>
<p>REgards,<br />
Ranjan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://www.learncpp.com/cpp-tutorial/23-variable-sizes-and-the-sizeof-operator/comment-page-1/#comment-51804</link>
		<dc:creator>James</dc:creator>
		<pubDate>Fri, 20 Mar 2009 07:08:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=43#comment-51804</guid>
		<description>Copy this code and use it on windows to keep the console screen up long enough for you to see the size of the data types...  Also, I removed one \t from &quot;wchar_t:\t\t&quot; cuz a second tab caused that line to be out of alignment with the rest.  y is the number of seconds you want the progam to wait before it ends. 

&lt;pre&gt;
#include &lt;iostream&gt;
#include &lt;windows.h&gt;
int main()
{
	using namespace std;
	cout &lt;&lt; &quot;bool:\t\t&quot; &lt;&lt; sizeof(bool) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;char:\t\t&quot; &lt;&lt; sizeof(char) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;wchar_t:\t&quot; &lt;&lt; sizeof(wchar_t) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;short:\t\t&quot; &lt;&lt; sizeof(short) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;   
    cout &lt;&lt; &quot;int:\t\t&quot; &lt;&lt; sizeof(int) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;   
    cout &lt;&lt; &quot;long:\t\t&quot; &lt;&lt; sizeof(long) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;   
    cout &lt;&lt; &quot;float:\t\t&quot; &lt;&lt; sizeof(float) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;   
    cout &lt;&lt; &quot;double:\t\t&quot; &lt;&lt; sizeof(double) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;   
    cout &lt;&lt; &quot;long double:\t&quot; &lt;&lt; sizeof(long double) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
	int y = 30, x = y * 1000; //assign y value of sleep time in seconds convert x to seconds 
	Sleep(x);
	return 0;
}
&lt;/pre&gt;

Oh, and alex, thanks for this tutorial.  It&#039;s the most complete, comprehensive, explanatory, and easy to follow tut on c++ I&#039;ve ever ran across.  Thanks for the time u spent in creating it, making it public, and taking time to answer people&#039;s comments.  You rock!</description>
		<content:encoded><![CDATA[<p>Copy this code and use it on windows to keep the console screen up long enough for you to see the size of the data types&#8230;  Also, I removed one \t from &#8220;wchar_t:\t\t&#8221; cuz a second tab caused that line to be out of alignment with the rest.  y is the number of seconds you want the progam to wait before it ends. </p>
<pre>
#include &lt;iostream&gt;
#include &lt;windows.h&gt;
int main()
{
	using namespace std;
	cout &lt;&lt; &quot;bool:\t\t&quot; &lt;&lt; sizeof(bool) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;char:\t\t&quot; &lt;&lt; sizeof(char) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;wchar_t:\t&quot; &lt;&lt; sizeof(wchar_t) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;short:\t\t&quot; &lt;&lt; sizeof(short) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;int:\t\t&quot; &lt;&lt; sizeof(int) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;long:\t\t&quot; &lt;&lt; sizeof(long) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;float:\t\t&quot; &lt;&lt; sizeof(float) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;double:\t\t&quot; &lt;&lt; sizeof(double) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;long double:\t&quot; &lt;&lt; sizeof(long double) &lt;&lt; &quot; bytes&quot; &lt;&lt; endl;
	int y = 30, x = y * 1000; //assign y value of sleep time in seconds convert x to seconds
	Sleep(x);
	return 0;
}
</pre>
<p>Oh, and alex, thanks for this tutorial.  It&#8217;s the most complete, comprehensive, explanatory, and easy to follow tut on c++ I&#8217;ve ever ran across.  Thanks for the time u spent in creating it, making it public, and taking time to answer people&#8217;s comments.  You rock!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
