Category:C: Difference between revisions

no edit summary
No edit summary
Line 115:
* Before a variable can be used, it must be defined.
 
===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.
* char: an 8 bit value, typically used to represent ASCII characters.
* short: a 16 bit value.
* int: a 32 bit value.
 
You can also add a few modifiers in front of the variable type to be more specific:
* <code>unsigned</code> tells the compiler that this variable is always treated as positive. Computers use two's complement to represent negative numbers, meaning that if the leftmost bit of a number's binary equivalent is set, the value is considered negative. The resulting assembly code will use unsigned comparisons to check this variable against other variables.
* <code>volatile</code> tells the compiler that this variable's value can changed by the hardware. This is commonly used for hardware registers such as those that track the mouse cursor's location, a scanline counter, etc. The value will always be read from its original memory location, ensuring that its value is always up-to-date.
 
Examples:
<lang C>unsigned int x;
volatile int HorizontalScroll;</lang>
 
Functions work the same way. You can declare a function without defining what it does.
1,489

edits