Week 2 Arrays
Week 2 - Arrays
Arrays
Fundamentally 3 different parameters:
- One Type ( Int, String, etc) - can be named too
- Name - Variable Name
- Size - How many boxes
- Is also 0-Indexed. Meaning it starts counting from Zero
Can also make them dynamically increase and dcerease the size of arrays.
int hours[5];
How to populate each cell?
int hours[5];
hours[0] = 7;
hours[1] = 1;
Computer knows i will allocate 5 cells into the bubble. You can modify and change the variable names with this one
Alternatively
int hours[5] = {1, 2, 3, 4, 5};
This will immediately assign all 5 hours/numbers into a specific sequence if you already know the values.
Strings are actually Arrays?!
A string is similar to an array. It stores a value of letters and assigns each letter from A-Z in a specific box
Strings are an array of characters…
string word = "Hello"
H = 0 E = 1 L = 2 L = 3 O = 4 /0 = 5 (Null)
Every string has a null character to specify where the string ends
string word = "Hello";
// If i use
word[0];
// It would store the letter "H"
Compilers
4 Steps Abstracted
- Preprocessing -> Calls the compiler and tells it that something will exist
#include <stdio.h>
The # is formally called a Preprocessor Directive. Anything with a ’#’ gets preprocessed
-
Compiling ->Gets translated from C/another language to Assembly
-
Assembly -> Converts again to binary.
-
Linking -> Links all the
#includefiles, finds the other header files and links the binaries that are linked together.
Decompiling
-> Converts binaries to code -> You can only reverse some processes -> When it comes to protecting your IP, its very difficult to decompile, -> Therefore, the people who are good enough to decompile can prolly make urs from scratch
Debugging
Debugging techniques
- The Rubber Duck! “Rubber ducking”
- Talk to an inanimate object and sounding out what your problems are.
-
Using
printf-> Can reference memory. Most powerful debugging tool -
Spend a few minutes playing with a debugger. Debug50
Garbage Values
-> Value stored without being initialized/Leftover data
Types
bool int long float double char string
Data Structure
- Array
- A continuous data type stored in memory that is a single type.
Command Line Arguments
Encryption
Contains three things:
- A Value - What you want to encrypt
- A Key - An algorithm to mathematically jumble the values. A simple one is Rot13 -> Rotating letters 13 times eg: A -> N
- Encrypted Value
All encrypted values must be able to be decrypted else it doesnt make sense.