int main - where program starts, returns 0
declare function void myFunction; // declare at top of page, define it further anywhere
Switch switch (category) { case 40: break; case 42: break; default: break; }
Ternary Works on 3 operations condition ? true : false
User Input scanf("%d", &stuff);
Enumeration define a tight range of input enum seatPreference {window, aisle, middle}; enum seatPreference bobsPreference = aisle; or just use define
TypeDef typedef int sethsInt; typedef enum {window, aisle, middle} seatPreference seatPreference bobsPreference = aisle;
Preprocessor directives things run before compilation #import <Foundation/Foundation.h> // for example, this pastes code into this spot #define HIGHSCORE 1000000 // runs through and replaces all HIGHSCORE will 1000000 #if DEBUG // if compiling in DEBUG mode do this #endif
Built in Defines INTMAX - maximum of int FLOATMAX
Operators += -= *= /=
Placeholders %c - character %i - integer (or BOOL) %f - float or double %d - digit %p
For for (int x = 0; x < 10; x ++) { if (y == 6) continue; // done with iteration, back to top if (y == 5) break; // jumps out of loop }
Cast Operator integers divided will yield integers unless you cast one of them as float! int a = 25; int x = 2; float result = (float) a / b;
Bitwise Operators
Datatypes
int - 4 bytes (32 bits) (2,147,483,648 signed decimal (positive and negative))
unsigned int - 4 bytes (32 bits) 4,294,967,296 positive only)
long int - you must compile as 64 bit to take advantage of this
long long int - 8 bytes (64 bits) regardless of no matter how you build (you can also call it long long)
short int - 2 byte (16 bits) 32,000 positive and negative (64,000 unsigned)
float - float myFloat = 7.2f; (4 bytes, explicitly declared float)
double - 8 bytes (64 bits) (double the size of a float! default of any decimal with . is double)
char - 1 byte - 0 to 255
BOOL - basically a char
Arrays No bounds checking fixed size can't mix types (an array of int, or string, but not both)
Pointers
Pointers store an address, but they also have their own address
Pointers
& - one level down (to address)
* - one level up (dereference)(to value in address stored by pointer)
ptr++ // moves address by one
*ptr = *ptr + 1 // adds one to value of the address in pointer
Strings char string[50] = "some string" while (*ptr != '\0') { }
const used in a function means this pointer will not be changed by the function.
segmentation fault means that the program accessed a memory location that was not assigned
where does gcc get header files
gcc -print-prog-name=cc1 -v
gcc -print-prog-name=cc1plus -v
malloc - dynamically allocate memory to a variable