C

Write the first paragraph of your page here.

Data Types
char - 1 byte, 8 bits, 1 character

int - 2 bytes, 16 bits, 1 whole number

float - 4 bytes, 32 bits, 1 floating point number

double - 8 bytes, 64 bits, 1 floating point number with greater precision

short

long

signed

unsigned

See VTC for table of ranges

Arithmetic Operators
*

/

+

-

% Modulus return the remainder of an integer division. It does not work on float or double.

int a = 5;

int b = 2;

int c = a % b; // the result is 1

Relational Operators
<

>

<=

>=

Equality Operators
==

!=

Logical Operators
&&



Unary Negation
!

Increment and Decrement Operators
++

++x pre-increment

x++ post-increment

--

--x pre-decrement

x-- post-decrement

Bitwise Operators
These operators can only be used in integers and not floats.

& AND


 * OR

^ XOR

<< LEFT SHIFT

>>RIGHT SHIFT

~ ONE'S COMPLEMENT

Assignment Operators
They can be used with all binary operators.

+=

-=

/=



%=

>>=

<<=

&=



^=

Variable Names
First character must be a letter.

Names are case-sensitive.

First 63 characters are significant.

First 31 characters are for external names like function names.

Constants
Constants are created with #define and are usually all uppercase

There are special constants like '\0' that means NULL.

"hello world\n" is a string constant.

'A' is not the same as "A". 'A' is the integer value for the letter A and "A" is a string constant plus the NULL.

Escape Sequences
\a - alert

\b - backspace

\f - formfeed

\n - newline

\r - carriage return

\t - tab

\v - vertical tab

\\ - backslash

\? - question mark

\' - single quotes

\" - double quotes

\ooo - octal number

\xhh - hexadecimal number

Declarations
Declaring all in one line is good.

Declaring all in separate lines is better.

Type Conversions
Both operands need to be with the same type for the math to be performed.

Smaller types are promoted.

Signed conversions are handled by machine implementation.

If either operand is long double, convert the other to long double.

If either is double, convert the other to double.

If either is float, convert the other to float.

Convert char and short to int.

If either is long, convert the other to long.

You can force a type conversion with a "cast".

y = sqrt((double)x); // convert x to a double before calculating the square root

Precedence and Order of Operation
Operators --- Associativity

Statements and Blocks
An expression with a ; is a statement.

Braces group statements into a Compound Statement or Block.

Braces surround the statements of a function definition and can surround multiple statements of loop constructs too.

else if
source code

break and continue
break exits the loop immediatly.

continue causes the loop to jump to the test section.

goto and labels
Use goto as a last option only.

Functions Returning Non-Integers
void functions don't return anything.

undefined functions return int.

For a function to return something other than an int it must be declared as such.

External Variables
These are declared only once per program and can be referenced in many source files.

Scope Rules
Variables have scope within the function that defines them.

Variables of the same name may be defined withit code blocks.

Header Files
.c source files contain function declarations.

.h source files contain variable declarations.


 * 1) include 


 * 1) include "/some/other/dir/myheader.h"

Static Variables
Allows an external variable to only be seen by its source file. No other files can see it.

Static local variables mantain their value rather than being reinitialized at every function call.

Register Variables
Notify the compiler that this will be a high use variable.

It's not guaranteed to give you a real register.

Initialization
extern and static variables must be initialized with a constant as they are compile time events.

Recursion
This is when a function calls itself.

C Preprocessor

 * 1) include - File Inclusion


 * 1) define - Macro Substitution


 * 1) if - Conditional Inclusion


 * 1) elseif


 * 1) else


 * 1) endif


 * 1) ifndef