Cheatography

# CSC 3600 Cheat Sheet (DRAFT) by Haskell

Function Cheat Sheet For CSC3600

This is a draft cheat sheet. It is a work in progress and is not finished yet.

### Useful Memory Management Functions

 void* malloc( size_t size ); This is just like new only a little bit more complex. You will need to cast the data that malloc returns to the type you need. void free(void *ptr); Same as delete. void memset­(void str, int c, size_t n); Sets the value of the memory you give it to the value specified. Typically used to set a chunk of memory to 0. void memcpy­(void str1, const void *str2, size_t n); Self explan­atory. void memmov­e(void str1, const void *str2, size_t n); Self explan­atory. sizeof­(thing) sizeof will correctly get you the size of any type of data you give it. sizeof DOES NOT give you the size of an array as it only works with types. Fun Fact: sizeof isnt a function, its an operator!

### Bit Bashing

 Defini­tions & – Bitwise AND | – Bitwise OR ~ – Bitwise NOT ^ – XOR << – Left Shift >> – Right Shift Logic Tables: & AND ----0 1 0 | 0 0 1 | 0 1 | OR ----0 1 0 | 0 1 1 | 1 1 ^ XOR ----0 1 0 | 0 1 1 | 1 0 ~ NOT 0 becomes 1 1 becomes 0 << Shift Left Moves ALL bits left n spaces 0001 << 2 = 0100 Shift Right 0101 >> 2 = 0001 NOTE: Bits that are shifted too far (Like the example above) are gone so if you did x = 0101 >> 2 x = x << 2 the answer would be 0100 So for:   x = 00101000 (40)   y = 01010000 (80) x&y = 00000000= 0 (decimal) x|y = 01111000 = 120 (decimal) ~x = 11010111 = -41 (decimal) x^y = 01111000= 120 (decimal) x << 1 = 01010000 = 80 (decimal) x >> 1 = 00010100 = 20 (decimal)

### Useful Linux Comman­ds/­Pro­grams

 grep This is a REALLY useful one to search anything. https:­//w­ww.g­nu.or­g/s­ava­nna­h-c­hec­kou­ts/­gnu­/gr­ep/­man­ual­/gr­ep.html Important to note that you can pipe something into grep to search the output of another program. valgrind The queen of memory leak detection. If you get a segfault then this is your best friend. http:/­/va­lgr­ind.org gdb Your debugger, this is a pretty big topic. https:­//w­ww.g­nu.or­g/s­oft­war­e/gdb/ make Run a makefile. A useful makefile tutorial can be found here: http:/­/ww­w.c­s.c­olb­y.e­du/­max­wel­l/c­our­ses­/tu­tor­ial­s/m­ake­tutor/
Basic commands like ls, pwd, and clear are not included here.