From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/CPLUSPLUS/CONCEPT/local_var.html | 144 +++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 reference/CPLUSPLUS/CONCEPT/local_var.html (limited to 'reference/CPLUSPLUS/CONCEPT/local_var.html') 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 @@ + + +C++ Local Variables. + + + +
+

C++ Local Variables.

+
+

+ +There is not much difference between + C local variables but there +is one important feature that should be noted. +

+This means that you can now put variable definitions anywhere in the code +and not jut at the start of a +block. +Here is an example. + +

+

+ + +
+
+
+    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;
+        }
+    }
+
+
+
+

+ +It should be noted that Count 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 cout statement. +

+ +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. +

+

+ + +
+
+
+    main()
+    {
+        int Last = 10;      
+        
+        while (int Count; Count < Last; Count++)
+        {
+            cout << Count << endl;
+        }
+    }
+
+
+
+

+In this example, Count is defined inside the for +statement and only exists while the for block is being executed. + + +

+


+

Examples:

+ + +
+

See Also:

+ +
+
+ +

C References

+

+ +o + C local variables +

+o +data types. + + + +


+

+

+ + + + +
+Top + +Master Index + +Keywords + +Functions +
+
+

+


+ +
Martin Leslie + +

+ + + -- cgit v1.2.3-54-g00ecf