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/SYNTAX/sizeof.html | 130 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 reference/C/SYNTAX/sizeof.html (limited to 'reference/C/SYNTAX/sizeof.html') diff --git a/reference/C/SYNTAX/sizeof.html b/reference/C/SYNTAX/sizeof.html new file mode 100644 index 0000000..34dc287 --- /dev/null +++ b/reference/C/SYNTAX/sizeof.html @@ -0,0 +1,130 @@ +The sizeof operator + + + + +
+
+

The sizeof operator

+
+
+

+sizeof will return the number of bytes reserved for a variable or +data type. +

+The following code shows sizeof returning the length of a data type. +

+ + + + +
+
+
+        /* How big is an int? expect an answer of 4. */
+	
+	main()
+ 	{
+	   printf("%d \n", sizeof(int));
+        }
+
+
+

+ +sizeof will also return the number of bytes reserved for a +structure. +

+ + + + +
+
+
+        /* Will print 8 on most machines. */
+	
+        main()
+	{
+	  struct 
+	  {
+	    int a;
+	    int b;
+	  } TwoInts;
+	
+	printf("%d \n", sizeof(TwoInts));
+	}
+	
+
+
+

+Finally, sizeof will return the length of a variable. + +

+ + + + +
+
+
+	main()
+	{
+	  char String[20];
+	  
+	  printf ("%d \n", sizeof String);
+ 	  printf ("%d \n", sizeof (String));
+        }
+
+
+
+

+In the example above I have printed the size of 'String' twice. This is to +show that when dealing with variables, the brackets are optional. + +I recommend that you always place the brackets around the sizeof argument. +

+


+

Examples:

+Example 1 Data types. +

+Example 2 Data objects. + +

+


+

See also:

+ +The strlen function. +

+ +Other operators +

+ +malloc function. + + +

+ +


+

+

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

+


+
Martin Leslie +

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