L2 - Arrays Flashcards
clang
Compiler we’re using when we run the program make/ code
How do you link libraries with a command line argument when compiling with clang?
-l
clang -o hello hello.c -lcs50
This links and renames the file
What are the four steps to turn source code into binary?
- pre-processing
- compiling
- assembling
- linking
Pre-Processing
Converts the included libraries (#include <stdio.h>) and adds the prototypes to the top of the file to be able to use all functions in that .h file</stdio.h>
Compiling
Convert source code to assembly code.
Assembling
Takes assembly code and converts to 0/1s
Linking
Pulls all 0/1s in all of the files together.
Debugging
Running through code to figure out issues.
Break point.
Point to pause execution of code, which is by adding a dot in the gutter. It stops at the first line of executable code, on or right after the breakpoint. The highlighted code has not been run yet.
Garbage values
Values that are present before variables are set.
Step over
Execute but don’t get into full detail.
Step in
Walkthrough the function step by step in detail
Step out
Pulls you out of the step by step detailed function to execute without full details.
Arrays
Sequence of values stored in memory without any gaps in between them with a 0 index, so position 1 is 0.
What is this?
int scores [3];
declaration of an integer array called “scores”, with a length of 3
Initialize an array
int scores [3];
Data type. Name. Array size.
assign a value to an int array
score[0]=72;
This cerates an int array and assigns 72 to index 0 (first position) of the array
constant
const Variable
This prevents the variable from being changed during the execution of the program and should start with a capital letter.
What is the prototype for a function that takes in an integer value and an array?
int average(int length , int array[]);
What is special about chars/ints?
chars can return the int numeric value, and ints can return the char letter/symbol values
Length of a string
N+1
(Length+1)
NUL or /0
byte with all zero bits (00000000) which indicates the end of a string, so the length of the string is always it’s length+1
NUL is not the same as NULL
How to use command line arguments to get input from a user with your main function
int main (int argc, string argv[])
Pronounced arg c and arg v
what is argc in main function?
Argument count:
The number of words the user typed in the command line prompt to run the program
ex: ./hello Bianca
argc = 2 since the filename is always the string in argc
what is argv in main function?
Argument vector array:
Takes the data entered when running the program and stores it into an array starting with the filename as index 0
exit status
The value returned when a program finishes running. A zero always means the program ran successfully and exited correctly. Any other value means an error occurred.
return 0;
Can be used to exit a program
echo $?
Can be used as a command line prompt to see the most recently executed program’s exit code.
Cryptography
Scrambling data that needs to be unlocked with a key to figure out the message
initialize an int array with the values 1,3,2,4,2
int numbers[5]={1,3,2,4,2};
data type.name. square brackets. size. =. curly braces. comma separated numbers. semicolon