C


Types

int

Integer

64

short

64

long

64

long long

64

float

Floating point decimal

64.0

double

Double precision floating point decimal

64.0

char

Character

"a"

Arithmetic operators

+

Addition

1 + 2

Unary positive, makes number positive

+2

-

Subtraction

2 - 1

Unary negative, makes number negative

*

Multiplication

2 * 3

/

Division

4 / 2

%

Modulo (remainder of division)

4 % 2

++

Increment

x++;

--

Decrement

x--;

Assignment operators

=

Equals

x = 2

+=

a+=b is a=a+b

x += 2

-=

a-=b is a=a-b

x -= 2

*=

a*=b is a=a*b

x *= 2

/=

a/=b is a=a/b

x /= 2

%=

a%=b is a=a%b

x %= 2

Comparison operators

==

Is equal to

1 == 2

!=

Is not equal to

1 != 2

>

Greater than

1 > 2

<

Less than

1 < 2

>=

Greater than or equal to

1 >= 2

<=

Less than or equal to

1 <= 2

Bitwise operators

&

Bitwise AND

0b11001010 & 0b00100011

|

Bitwise OR

0b11001010 | 0b00100011

^

Bitwise XOR

0b11001010 ^ 0b00100011

<<

Arithmetic shift left (shifts all the bits one space to the left, essentially multiplying it by 2)

0b11001010 << 2

>>

Logical shift right (shifts all the bits one space to the right, essentially dividing it by 2)

0b11001010 >> 2

~

Bitwise NOT

~0b00100011

Logical operators

&&

AND operator

1 && 0

||

OR operator

1 || 0

!

NOT operator

!1

Miscellaneous operators

,

Links related expressions together

sizeof()

Unary operator that returns how many variables in RAM a variable holds

.

Denotes relation of an object to a struct

math.1

[]

Denotes an object is an array during declaration, also holds the array's size, unless being initialised

int numbers[4];

References a array's index

numbers[3]

()

Denotes parameters of a function

printf("Hello world!");

Denotes a function

{}

Defines a block

void foo() {
}

Initialises an array

int numbers[] = {0, 1, 2, 3};

:

Used for switch cases

case 1:

Used for separating true and false returns in conditional expressions

retval = exp ? trueret : falseret

?

Used for separating condition and return values in conditional expressions

retval = exp ? trueret : falseret

->

Denotes relation of a pointer to a struct instance variable

px->a;

*

Unary delcaration of a pointer variable or function; that reads the value in the assigned memory address)

int *px = &x;

int *pf)(int) = &f;

Unary dereferencing (associating a pointer to an address)

*p

Typecasting; enforcing a type

(object *) malloc(int);

&

Unary memory address of a variable

&x

<>

Denotes imported module file

#include <stdio.h>

""

Declares a string

"Hello world!"

''

Declares a string

'Hello world!'

;

Declares end of a line of code

break;

...

Declares multiple arguments

double average(int number, ...) {

sizeof

Finds the size of a datatype

(int *) malloc(sizeof(int));

Finds the size of a variable in bits

int y = sizeof(5+2);

Key word

double

Declares doubles (also known as floats, or numbers with decimal place)

struct

Declares a structure; which defines public custom datatypes similar to a class, but without methods

struct Foo {
 code;
};

typedef struct {
 code;
} Foo;

int

Declares integers

goto

Goes to a label

if

Executes code if condition is true

if (condition) {
 code;
}

void

Used for declaring that a method does not return a specific value

extern

Used for declaring a variable, but not defining it

static

Declares a static variable; a variable that retains its value outside of its scope

while

Loops code while a condition is true

while (condition) {
 code;
}

do {
 code;
}
while (condition);

for

Loops code for a set amount iterations or for every object in list

for (initialization; condition; update) {
 code;
}

register

Used for storing value in a CPU register (I think this is deprecated, but wow)

do

for declaring loop in a while loop

else

Executes code when if or else if isn't executed

import

Imports classes and modules

return

Terminates a function, returning a value

continue

Used to tell compiler to complete the next iteration of a loop

switch

Switches logic flow based on an output

switch (expression) {
case x:
  code;
break;
case y:
  code;
break;
}

break

Breaks from

typedef

Used for creating name or an alias for a type (particularly used for aliases and for nominating structs)

union

Declares a union; a structure containing one object that can interpret a datarange as the types specified in the union

union Foo {
 code;
};

else if

Executes code on true condition if the last if statement was false

<stdio.h>

printf

Prints a message

printf(char *);

<stdlib.h>

malloc

Memory Allocation; Allocates block of RAM in heap for an object

(type *) malloc(size);

calloc

Continuous Allocation; Allocates blocks of RAM for a variable contiguously, setting the variables space to all 0s

(type *) calloc(nitems, size);

free

Deallocates RAM for a variable

free(*p);

Argument specifiers

%s

String

%d

Integer

%f

Float

%.1f

Float with 1 decimal place, the 1 can be modified to imply more decimal places

%x

Integer in hexadecimal (lowercase a b c d e f)

%X

Integer in hexadecimal (uppercase A B C D E F)

Escape sequences

\n

New line

\t

Horizontal tab

\v

Vertical tab

\?

Question mark

\'

Single quote

\"

Double quote

\\

Backslash

\b

Backspace

Directives

#include

Includes foreign file's methods

#include <header>

#define

Defines a constant

#define PI 3.14159265315

Defines a lambda expression

#define max(A, B) ((A) > (B) ? (A) : (B))

Commenting

//

Used to tell compiler the rest of this line is not to be compiled

/*

Opens a multi line comment

*/

Closes a multi line comment