Category:C: Difference between revisions

Content added Content deleted
(→‎Versions: Updated info re C2x.)
Line 117: Line 117:


===Types===
===Types===
C has the following types built in by default, but you can create your own based on these using the <code>typedef</code> directive. This is not an exhaustive list.
C has the following types built in by default, but you can create your own based on these using the <code>typedef</code> directive. This is not an exhaustive list. Some of these names will have different meanings depending on the hardware you're programming for.
* <code>char</code>: an 8 bit value, typically used to represent ASCII characters.
* <code>char</code>: an 8 bit value, typically used to represent ASCII characters.
* <code>short</code>: a 16 bit value.
* <code>short</code>: a 16 bit value.
Line 123: Line 123:
* <code>struct</code>: a collection of several other values, stored consecutively in memory. Each can be a different type.
* <code>struct</code>: a collection of several other values, stored consecutively in memory. Each can be a different type.
* <code>union</code>: a variable that can hold several different types of data, but only one at a time.
* <code>union</code>: a variable that can hold several different types of data, but only one at a time.
* <code>float</code>: a floating-point decimal value.
* <code>float</code>: a single-precision (32-bit) floating-point decimal value.


You can also add a few modifiers in front of the variable type to be more specific:
You can also add a few modifiers in front of the variable type to be more specific:
Line 133: Line 133:
volatile int HorizontalScroll;</lang>
volatile int HorizontalScroll;</lang>


Functions work the same way. You can declare a function without defining what it does.
Functions are declared in a similar fashion to variables, except a function's "type" is the type of the value it returns.
<lang C>int foo(int bar);
<lang C>int foo(int bar);
// The function foo was declared. It takes an integer as an argument and returns an integer.
// The function foo was declared. It takes an integer as an argument and returns an integer.