<?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>C ++ &#187; Memory Address</title>
	<atom:link href="http://www.bizzymicbizness.com/cplusplus/tag/memory-address/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bizzymicbizness.com/cplusplus</link>
	<description>All about C++</description>
	<lastBuildDate>Mon, 19 Oct 2009 12:38:17 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>C++ Inline Functions</title>
		<link>http://www.bizzymicbizness.com/cplusplus/c-inline-functions</link>
		<comments>http://www.bizzymicbizness.com/cplusplus/c-inline-functions#comments</comments>
		<pubDate>Sat, 10 Oct 2009 00:47:41 +0000</pubDate>
		<dc:creator>BMB</dc:creator>
				<category><![CDATA[C++ Glossary]]></category>
		<category><![CDATA[#define]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Compiler]]></category>
		<category><![CDATA[Function Call]]></category>
		<category><![CDATA[Inline Functions]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[Memory Address]]></category>
		<category><![CDATA[Stack]]></category>

		<guid isPermaLink="false">http://www.bizzymicbizness.com/cplusplus/?p=640</guid>
		<description><![CDATA[Inline functions

Are a C++ enhancement designed to speed up programs


The primary distinction between normal functions and inline functions

Is not in how you code them

But in how the C++ compiler incorporates them into a program




To understand the distinction between inline functions and normal functions

You need to peer more deeply into a program’s innards than we have [...]]]></description>
			<content:encoded><![CDATA[<p><em>Inline functions</em></p>
<ul>
<li>Are a C++ enhancement designed to speed up programs</li>
</ul>
<p><br class="blank" /><br />
The primary distinction between normal functions and inline functions</p>
<ul>
<li>Is not in how you code them
<ul>
<li>But in how the C++ compiler incorporates them into a program</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
To understand the distinction between inline functions and normal functions</p>
<ul>
<li>You need to peer more deeply into a program’s innards than we have so far
<ul>
<li>Let’s do that now</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
The final product of the compilation process</p>
<ul>
<li>Is an executable program, which consists of a set of machine language instructions
<ul>
<li>When you start a program, the operating system loads these instructions into the computer’s memory so that each instruction has a particular memory address
<ul>
<li>The computer then goes through these instructions step-by-step</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
Sometimes, as when you have a loop or a branching statement</p>
<ul>
<li>Program execution skips over instructions, jumping backward or forward to a particular address</li>
</ul>
<p><br class="blank" /><br />
Normal function calls</p>
<ul>
<li>Also involve having a program jump to another address (the function’s address)
<ul>
<li>And then jump back when the function terminates</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
Let’s look at a typical implementation of that process in a little more detail</p>
<ul>
<li>When a program reaches the function call instruction
<ul>
<li>The program stores the memory address of the instruction immediately following the function call
<ul>
<li>Copies function arguments to the stack (a block of memory reserved for that purpose)
<ul>
<li>Jumps to the memory location that marks the beginning of the function
<ul>
<li>Executes the function code (perhaps placing a return value in a register)
<ul>
<li>And then jumps back to the instruction whose address it saved</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
Jumping back and forth and keeping track of where to jump</p>
<ul>
<li>Means that there is an overhead in elapsed time to using functions</li>
</ul>
<p><br class="blank" /><br />
C++ inline functions</p>
<ul>
<li>Provide an alternative</li>
</ul>
<p><br class="blank" /><br />
In an inline function</p>
<ul>
<li>The compiled code is “in line” with the other code in the program
<ul>
<li>That is, the compiler replaces the function call with the corresponding function code</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
With inline code</p>
<ul>
<li>The program doesn’t have to jump to another location to execute the code and then jump back
<ul>
<li>Inline functions thus run a little faster than regular functions
<ul>
<li>But they come with a memory penalty</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
If a program calls an inline function at 10 separate locations</p>
<ul>
<li>Then the program winds up with 10 copies of the function inserted into the code
<ul>
<li>See (Image-1)</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
(Image-1)  Inline functions versus regular functions</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-641" title="Inline functions versus regular functions" src="http://www.bizzymicbizness.com/cplusplus/wp-content/uploads/2009/10/Inline-functions-versus-regular-functions.jpg" alt="Inline functions versus regular functions" width="551" height="418" /></p>
<p><br class="blank" /><br />
You should be selective about using inline functions</p>
<ul>
<li>If the time needed to execute the function code is long compared to the time needed to handle the function call mechanism</li>
<ul>
<li>Then the time saved is a relatively small portion of the entire process</li>
</ul>
<li>If the code execution time is short</li>
<ul>
<li>Then an inline call can save a large portion of the time used by the non-inline call</li>
<ul>
<li>On the other hand, you are now saving a large portion of a relatively quick process, so the absolute time savings may not be that great unless the function is called frequently</li>
</ul>
</ul>
</ul>
<p><br class="blank" /><br />
To use this feature, you must take at least one of two actions:</p>
<ul>
<li>Preface the function declaration with the keyword <strong>inline</strong></li>
<li>Preface the function definition with the keyword <strong>inline</strong></li>
</ul>
<p><br class="blank" /><br />
A common practice is</p>
<ul>
<li>To omit the prototype
<ul>
<li>And to place the entire definition (meaning the function header and all the function code) where the prototype would normally go</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
The compiler does not have to honor your request to make a function inline</p>
<ul>
<li>It might decide the function is too large
<ul>
<li>Or notice that it calls itself (recursion is not allowed or indeed possible for inline functions)
<ul>
<li>Or the feature might not be turned on or implemented for your particular compiler</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
(A-1) illustrates the inline technique with an inline <strong>square()</strong> function that squares its argument</p>
<ul>
<li>Note that placed the entire definition is on one line
<ul>
<li>That’s not required, but if the definition doesn’t fit on one line, the function is probably a poor candidate for an inline function</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
Example of (A-1)</p>

<div class="syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// inline.cpp -- using an inline function</span>
<span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
<span style="color: #666666;">// an inline function definition</span>
<span style="color: #0000ff;">inline</span> <span style="color: #0000ff;">double</span> square<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">double</span> x<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> x <span style="color: #000040;">*</span> x<span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">double</span> a, b<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">double</span> c <span style="color: #000080;">=</span> <span style="color:#800080;">13.0</span><span style="color: #008080;">;</span>
&nbsp;
	a <span style="color: #000080;">=</span> square<span style="color: #008000;">&#40;</span><span style="color:#800080;">5.0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	b <span style="color: #000080;">=</span> square<span style="color: #008000;">&#40;</span><span style="color:#800080;">4.5</span> <span style="color: #000040;">+</span> <span style="color:#800080;">7.5</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// can pass expressions</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;a = &quot;</span> <span style="color: #000080;">&lt;&lt;</span> a <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;, b = &quot;</span> <span style="color: #000080;">&lt;&lt;</span> b <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;c = &quot;</span> <span style="color: #000080;">&lt;&lt;</span> c<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;, c squared = &quot;</span> <span style="color: #000080;">&lt;&lt;</span> square<span style="color: #008000;">&#40;</span>c<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Now c = &quot;</span> <span style="color: #000080;">&lt;&lt;</span> c <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><br class="blank" /><br />
Here’s the output of the program in (A-1):</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-642" title="Output" src="http://www.bizzymicbizness.com/cplusplus/wp-content/uploads/2009/10/Output2.jpg" alt="Output" width="536" height="247" /></p>
<p><br class="blank" /><br />
This output illustrates that inline functions pass arguments by value just like regular functions do</p>
<ul>
<li>If the argument is an expression, such as <strong>4.5 + 7.5</strong>, the function passes the value of the expression—<strong>12</strong> in this case
<ul>
<li>This makes C++’s inline facility far superior to C’s macro definitions
<ul>
<li>See the “Inline Versus Macros”</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
Even though the program doesn’t provide a separate prototype, C++’s prototyping features are still in play</p>
<ul>
<li>That’s because the entire definition, which comes before the function’s first use, serves as a prototype
<ul>
<li>This means you can use <strong>square()</strong> with an <strong>int</strong> argument or a <strong>long</strong> argument
<ul>
<li>And the program automatically type casts the value to type <strong>double</strong> before passing it to the function</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
<br class="blank" /></p>
<h2>Inline Versus Macros</h2>
<p><br class="blank" /><br />
The <strong>inline</strong> facility is an addition to C++</p>
<ul>
<li>C uses the preprocessor <strong>#define</strong> statement to provide <em>macros</em>
<ul>
<li>Which are crude implementations of inline code
<ul>
<li>For example, here’s a macro for squaring a number (A-2):</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
Example of (A-2)</p>

<div class="syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#define SQUARE(X) X*X</span></pre></div></div>

<p><br class="blank" /><br />
(A-2) this works not by passing arguments but through text substitution</p>
<ul>
<li>With the <strong>X</strong> acting as a symbolic label for the “argument” (A-3):</li>
</ul>
<p><br class="blank" /><br />
Example of (A-3)</p>

<div class="syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">a <span style="color: #000080;">=</span> SQUARE<span style="color: #008000;">&#40;</span><span style="color:#800080;">5.0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// is replaced by a = 5.0*5.0;</span>
b <span style="color: #000080;">=</span> SQUARE<span style="color: #008000;">&#40;</span><span style="color:#800080;">4.5</span> <span style="color: #000040;">+</span> <span style="color:#800080;">7.5</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// is replaced by b = 4.5 + 7.5 * 4.5 + 7.5;</span>
d <span style="color: #000080;">=</span> SQUARE<span style="color: #008000;">&#40;</span>c<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// is replaced by d = c++*c++;</span></pre></div></div>

<p><br class="blank" /><br />
(A-3) only the first example here works properly</p>
<ul>
<li>You can improve matters with a liberal application of parentheses (A-4):</li>
</ul>
<p><br class="blank" /><br />
Example of (A-4)</p>

<div class="syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#define SQUARE(X) ((X)*(X))</span></pre></div></div>

<p><br class="blank" /><br />
Still, the problem remains that macros don’t pass by value</p>
<ul>
<li>Even with this new definition, <strong>SQUARE(c++)</strong> increments <strong>c</strong> twice
<ul>
<li>But the inline <strong>square()</strong> function in (A-1) evaluates <strong>c</strong>, passes that value to be squared, and then increments <strong>c</strong> once</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
The intent here is not to show you how to write C macros</p>
<ul>
<li>Rather, it is to suggest that if you have been using C macros to perform function-like services
<ul>
<li>You should consider converting them to C++ inline functions</li>
</ul>
</li>
</ul>
<p><br class="blank" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bizzymicbizness.com/cplusplus/c-inline-functions/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Strings</title>
		<link>http://www.bizzymicbizness.com/cplusplus/strings</link>
		<comments>http://www.bizzymicbizness.com/cplusplus/strings#comments</comments>
		<pubDate>Thu, 01 Oct 2009 00:16:25 +0000</pubDate>
		<dc:creator>BMB</dc:creator>
				<category><![CDATA[C++ Glossary]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[ASCII]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[C-style string]]></category>
		<category><![CDATA[Memory Address]]></category>
		<category><![CDATA[Null Character]]></category>
		<category><![CDATA[Quoted String]]></category>
		<category><![CDATA[String Constant]]></category>
		<category><![CDATA[String Literal]]></category>
		<category><![CDATA[Strings]]></category>

		<guid isPermaLink="false">http://www.bizzymicbizness.com/cplusplus/?p=573</guid>
		<description><![CDATA[A string

Is a series of characters stored in consecutive bytes of memory


C++ has two ways of dealing with strings

The first, taken from C and often called a C-style string, is the first one this page examines
Later, we will discuss an alternative method based on a string class library


The idea of a series of characters stored [...]]]></description>
			<content:encoded><![CDATA[<p>A <em>string</em></p>
<ul>
<li>Is a series of characters stored in consecutive bytes of memory</li>
</ul>
<p><br class="blank" /><br />
C++ has two ways of dealing with strings</p>
<ul>
<li>The first, taken from C and often called a <em>C-style string</em>, is the first one this page examines</li>
<li>Later, we will discuss an alternative method based on a <strong>string</strong> class library</li>
</ul>
<p><br class="blank" /><br />
The idea of a series of characters stored in consecutive bytes</p>
<ul>
<li>Implies that you can store a string in an array of <strong>char</strong>
<ul>
<li>With each character kept in its own array element</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
Strings provide a convenient way to store text information</p>
<ul>
<li>Such as messages to the user (“<em>Please tell me your secret Swiss bank account number</em>”)
<ul>
<li> Or responses from the user (“<em>You must be joking</em>”)</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
C-style strings have a special feature:</p>
<ul>
<li>The last character of every string is the <em>null character</em>
<ul>
<li>This character, written <strong>\0</strong>, is the character with ASCII code 0, and it serves to mark the string’s end
<ul>
<li>For example, consider the following two declarations (A-1):</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
Example of (A-1)</p>

<div class="syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">char</span> dog <span style="color: #008000;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span> <span style="color: #FF0000;">'h'</span>, <span style="color: #FF0000;">'u'</span>, <span style="color: #FF0000;">'s'</span>, <span style="color: #FF0000;">'k'</span>, <span style="color: #FF0000;">'y'</span><span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// not a string!</span>
<span style="color: #0000ff;">char</span> cat<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span><span style="color: #FF0000;">'f'</span>, <span style="color: #FF0000;">'a'</span>, <span style="color: #FF0000;">'t'</span>, <span style="color: #FF0000;">'s'</span>, <span style="color: #FF0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// a string!</span></pre></div></div>

<p><br class="blank" /><br />
(A-1) both of these arrays are arrays of <strong>char</strong></p>
<ul>
<li>But only the second is a string</li>
</ul>
<p><br class="blank" /><br />
The null character plays a fundamental role in C-style strings</p>
<ul>
<li>For example, C++ has many functions that handle strings, including those used by <strong>cout</strong></li>
<ul>
<li>They all work by processing a string character-by-character until they reach the null character</li>
<ul>
<li>If you ask <strong>cout</strong> to display a nice string like <strong>cat</strong> in the preceding example</li>
<ul>
<li>It displays the first four characters, detects the null character, and stops</li>
</ul>
<li>But if you are ungracious enough to tell <strong>cout</strong> to display the <strong>dog</strong> array from the preceding example, which is not a string</li>
<ul>
<li><strong>cout</strong> prints the five letters in the array and then keeps marching through memory byte-by-byte, interpreting each byte as a character to print, until it reached a null character</li>
</ul>
</ul>
<li>Because null characters, which really are bytes set to zero</li>
<ul>
<li>Tend to be common in memory, the damage is usually contained quickly; nonetheless, you should not treat nonstring character arrays as strings</li>
</ul>
</ul>
</ul>
<p><br class="blank" /><br />
The <strong>cat</strong> array example makes initializing an array to a string look tedious</p>
<ul>
<li>All those single quotes and then having to remember the null character
<ul>
<li>Don’t worry. There is a better way to initialize a character array to a string
<ul>
<li>Just use a quoted string, called a <em>string constant</em> or <em>string literal</em>, as in the following (A-2):</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
Example of (A-2)</p>

<div class="syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">char</span> bird<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">10</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;Mr. Cheeps&quot;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// the \0 is understood</span>
<span style="color: #0000ff;">char</span> fish<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;Bubbles&quot;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// let the compiler count</span></pre></div></div>

<p><br class="blank" /><br />
Quoted strings always include the terminating null character implicitly</p>
<ul>
<li>So you don’t have to spell it out
<ul>
<li>See (Image-1)</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
(Image-1) Initializing an array to a string<br />
 </p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-574" title="Initializing an array to a string" src="http://www.bizzymicbizness.com/cplusplus/wp-content/uploads/2009/09/Initializing-an-array-to-a-string.jpg" alt="Initializing an array to a string" width="452" height="239" /></p>
<p><br class="blank" /><br />
Also, the various C++ input facilities for reading a string from keyboard input into a <strong>char</strong> array</p>
<ul>
<li>Automatically add the terminating null character for you</li>
</ul>
<p><br class="blank" /><br />
Of course, you should make sure the array</p>
<ul>
<li>Is large enough to hold all the characters of the string
<ul>
<li>Including the null character</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
Initializing a character array with a string constant</p>
<ul>
<li>Is one case where it may be safer
<ul>
<li>To let the compiler count the number of elements for you</li>
</ul>
</li>
</ul>
<p> <br />
<br class="blank" /><br />
There is no harm, other than wasted space, in making an array larger than the string</p>
<ul>
<li>That’s because functions that work with strings are guided by the location of the null character
<ul>
<li>Not by the size of the array</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
C++ imposes</p>
<ul>
<li>No limits on the length of a string</li>
</ul>
<p><br class="blank" /><br />
Remember</p>
<ul>
<li>When determining the minimum array size necessary to hold a string
<ul>
<li>Remember to include the terminating null character in your count</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
Note that a string constant (with double quotes)</p>
<ul>
<li>Is not interchangeable with a character constant (with single quotes)</li>
</ul>
<p><br class="blank" /><br />
A character constant</p>
<ul>
<li>Such as <strong>‘S’</strong>, is a shorthand notation for the code for a character
<ul>
<li>On an ASCII system, <strong>‘S’</strong> is just another way of writing 83
<ul>
<li>Thus, the following statement assigns the value 83 to <strong>shirt_size</strong> (A-3):</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
Example of (A-3)</p>

<div class="syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">char</span> shirt_size <span style="color: #000080;">=</span> <span style="color: #FF0000;">'S'</span><span style="color: #008080;">;</span> <span style="color: #666666;">// this is fine</span></pre></div></div>

<p><br class="blank" /><br />
But <strong>“S”</strong> represents the string consisting of two characters</p>
<ul>
<li>The <strong>S</strong> and the <strong>\0</strong> characters
<ul>
<li>Even worse, <strong>“S”</strong> actually represents the memory address at which the string is stored
<ul>
<li>So the following statement attempts to assign a memory address to <strong>shirt_size</strong> (A-4):</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><br class="blank" /><br />
Example of (A-4)</p>

<div class="syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">char</span> shirt_size <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;S&quot;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// illegal type mismatch</span></pre></div></div>

<p><br class="blank" /><br />
Because an address is a separate type in C++</p>
<ul>
<li>A C++ compiler won’t allow this sort of nonsense
<ul>
<li>(We’ll return to this point later, after we’ve discussed pointers.)</li>
</ul>
</li>
</ul>
<p><br class="blank" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bizzymicbizness.com/cplusplus/strings/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

