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/C/CONCEPT/constants.html | 143 +++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 reference/C/CONCEPT/constants.html (limited to 'reference/C/CONCEPT/constants.html') diff --git a/reference/C/CONCEPT/constants.html b/reference/C/CONCEPT/constants.html new file mode 100644 index 0000000..e2a7778 --- /dev/null +++ b/reference/C/CONCEPT/constants.html @@ -0,0 +1,143 @@ +Constants + +
+

Constants

+
+Be sure you understand the difference between a 'constant' and a +declaration. +A constant has a value that cannot be changed. For example: +
+
+	1234
+	'x'
+	9.89
+	"String"
+
+
+Constants are used to assign a value to a variable. E.G +
+	int i;		/* declare a variable called 'i'	*/
+	i=1234;		/* assign the constant value 1234 to 
+			 * the variable 'i'			*/
+        i++;		/* Change the value of the variable.	*/
+
+ +
+

Integer constants.

+Interger constants can be expressed in the following ways. +
+	1234	(decimal)
+	0xff	(Hexidecimal)
+	0100	(Octal)
+	'\xf'	(Hex character)
+
+Examples of their use are: +
+	int i=255;	/* i assigned the decimal value of 255	*/
+
+	i-=0xff		/* subtract 255 from i			*/
+
+	i+=010		/* Add Octal 10 (decimal 8)		*/
+
+			/* Print 15 - there are easier ways...	*/
+	printf ("%i \n", '\xf'); 
+
+
+Integer constants are assumed to have a datatype of +
int, if it will not fit into an 'int' +the compiler will assume the constant is a +long. You may also force the +compiler to use 'long' by putting an 'L' on the end of the +integer constant. +
+        1234L           /* Long int constant (4 bytes)          */
+
+The other modifier is 'U' for Unsigned. +
+        1234U           /* Unsigned int                         */
+
+and to complete the picture you can specify 'UL' +
+        1234UL          /* Unsigned long int                    */
+
+ +
+

Floating point constants.

+Floating point constants contain a decimal point or exponent. By default +they are double. +
+	123.4
+	1e-2
+
+	
+
+
+

Chararacter constants.

+Are actually integers. +
+	'x'
+	'\000'
+	'\xhh'
+
+	escape sequences
+
+
+ +
+ +

String constants.

+ +Strings do not have a datatype of their own. +They are actually a sequence of char items terminated with a +\0. A string can be accessed with a +char pointer. +

+An example of a string would be: +

+
+	char *Str = "String Constant";
+
+
+ +See the discussion on +strings for more information. +

+ +


+

Also see:

+ +
+

+

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

+ +


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