summaryrefslogtreecommitdiff
path: root/reference/CPLUSPLUS/CONCEPT/local_var.html
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2008-01-27 11:37:44 +0100
committerTobias Klauser <tklauser@xenon.tklauser.home>2008-01-27 11:37:44 +0100
commit7e0f021a9aec35fd8e6725e87e3313b101d26f5e (patch)
treeb1cacc4b24393f517aeb4610e9e1021f954307a8 /reference/CPLUSPLUS/CONCEPT/local_var.html
Initial import (2.0.2-6)2.0.2-6
Diffstat (limited to 'reference/CPLUSPLUS/CONCEPT/local_var.html')
-rw-r--r--reference/CPLUSPLUS/CONCEPT/local_var.html144
1 files changed, 144 insertions, 0 deletions
diff --git a/reference/CPLUSPLUS/CONCEPT/local_var.html b/reference/CPLUSPLUS/CONCEPT/local_var.html
new file mode 100644
index 0000000..f6cb994
--- /dev/null
+++ b/reference/CPLUSPLUS/CONCEPT/local_var.html
@@ -0,0 +1,144 @@
+<html>
+<head>
+<title>C++ Local Variables.</title>
+</head>
+<body bgcolor="#dddddd">
+<font color=brown>
+<hr>
+<center><h1>C++ Local Variables.</h1></center>
+<hr>
+<p>
+
+There is not much difference between
+<a href=../../C/SYNTAX/glo_int_vars.html> C local variables</a> but there
+is one important feature that should be noted.
+<ul>
+<li>Variable definitions are now considered to be executable statements.
+</ul>
+This means that you can now put variable definitions anywhere in the code
+and not jut at the start of a
+<a href=../../C/glossary.html#block>block.</a>
+Here is an example.
+
+<p>
+<center>
+<table bgcolor=ivory width="80%" border=1>
+<tr><td>
+<pre>
+
+ main()
+ {
+ float pi = 3.142; // Usual location for variable definitions
+
+ cout << "PI is " << pi << endl;
+
+ int Count = 1; // C++ allows us to place a definition here.
+
+ while (Count < 10)
+ {
+ cout << Count << endl;
+ }
+ }
+</pre>
+</td></tr>
+</table>
+</center>
+<p>
+
+It should be noted that <b>Count</b> is only in scope (usable) from the
+point of definition and to the end of the block.
+It can not be used in the previous <b>cout</b> statement.
+<p>
+
+The idea of this feature is to allow you to put variable declarations
+near to the place
+you wish to use them. Personnaly, I feel this should not be neccasary
+if you write small concise functions....
+
+There is one natty feature of this facility though. Check this
+example out.
+<p>
+<center>
+<table bgcolor=ivory width="80%" border=1>
+<tr><td>
+<pre>
+
+ main()
+ {
+ int Last = 10;
+
+ while (int Count; Count < Last; Count++)
+ {
+ cout << Count << endl;
+ }
+ }
+</pre>
+</td></tr>
+</table>
+</center>
+<p>
+In this example, <b>Count</b> is defined inside the <b>for</b>
+statement and only exists while the for block is being executed.
+
+
+<p>
+<hr>
+<h2>Examples:</h2>
+<!--
+<img src="../../GRAPHICS/computer.gif" alt="o">
+<a href="../EXAMPLES/refvar.cc">Example program.</a>
+<p>
+
+<font color=brown>
+<img src="../../GRAPHICS/computer.gif" alt="o">
+<a href="../../C/EXAMPLES/pointer_func.c">Example C program.</a>
+</font>
+-->
+
+<hr>
+<h2>See Also:</h2>
+
+</font>
+<hr>
+<font color=black>
+<h2>C References</h2>
+<p>
+
+<img src="../../GRAPHICS/whiteball.gif" alt="o">
+<a href=../../C/SYNTAX/glo_int_vars.html> C local variables</a>
+<p>
+<img src="../../GRAPHICS/whiteball.gif" alt="o">
+<a href="../../C/CONCEPT/data_types.html">data types</a>.
+
+</font>
+
+<hr>
+<p>
+<center>
+<table border=2 width="80%" bgcolor="ivory">
+<tr align=center>
+<td width="25%">
+<a href="../cref.html">Top</a>
+</td><td width="25%">
+<a href="../../C/master_index.html">Master Index</a>
+</td><td width="25%">
+<a href="../SYNTAX/keywords.html">Keywords</a>
+</td><td width="25%">
+<a href="../../C/FUNCTIONS/funcref.htm">Functions</a>
+</td>
+</tr>
+</table>
+</center>
+<p>
+<hr>
+<font color=brown>
+<address>Martin Leslie
+<script language="JavaScript">
+<!-- //
+document.write(document.lastModified);
+// -->
+</script>
+</address><p>
+</font>
+</body>
+</html>