summaryrefslogtreecommitdiff
path: root/4-28-notes.txt
blob: 137dceb7e161705378abbacf35c8ac46a8af78c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
Variables
"They're something in a program that stores values, this can be a number, a\
character, a pointer a float or arrays of those things."

Variable Type
"the type of a variable is what sort of thing the variable is, what kind of\
value it stores, what operators work on it and the size of it"

Examples
int integer = 34;
char character = 'a';
char * string = "1234";
float floating-point = 12.0;
double doubleFloatingPoint = 111112.0;
int * pointer = &integer;
int array[4] = {0,2,3,4};

Special types of integers

unsigned int unsignedInteger = 4;
short shortInteger = 5;
long longInteger = 1212121212122121212;
uint8_t unsigned8bitInteger = 255;
uint32_t unsigned32bitInteger = 323232323233223232323;

printf("Hello World! %d %c %s\n\a",122,'A',"A String");

"printf is a function a part of stdio(Standard I/O) that allows a program to\
print to serial out(the terminal) it takes a format string and values after that"

Format String
"The format string is what you want printf to print out with, with stuff like\
%d that are placeholders that let you also print out the value of variables you\
supply to printf as arguments"

so in printf("hello world!\n"); "hello world!\n" is the format string

'\n' and '\a' are special characters, '\n' stands for new line and is like
pressing enter. '\a' is the alarm bell and makes a beeping sound

%d is a placeholder for an integer, printed out in decimal(base 10)
%c is a placeholder for a character
%s is a placeholder for a string

for more information look at 'man printf'

What is a function?
"A math function is a when a domain is paired to a co-domain, in programming,\
piece of code that you can run multiple times and does an action"

Function return
"the value a function outputs"

Function argument
"the input to a function"

//How do you run a function
foobar(foo, bar);
also known as a function call;
a function is also an expression
printf("hello world"); is a function call, you're running printf with the
argument "hello world."
"where foobar(int, int) is a function and foo and bar are arguments
that whole piece of code would then evaluate to the output of foobar"
eg.
"if foobar(foo, bar) outputs jia
then foobar(foo, bar); == jia"

Function Definition
"defining a function is when you write down what a function takes as arguments,
what the function returns and what code the function runs"

unsigned int foobar(int foo, int bar) {
	int lar = 0;
	lar = (foo - bar) * 82 + bar;
	return lar;
}

"the above is a function that returns a variable of type 'unsigned int' and
takes two arguments foo and bar that are of type 'int'. it runs the code inside
of the squiggly brackets {}."

Code blocks

"any code inside of an {} are a code block, you can put code blocks inside of
code blocks, that's called nesting code blocks. When you make a new code block
you should indent the code inside of the block"
printf("foobar\n");
i++;
if( i == 0) {
	printf("barfoo\n");
	j++;
}
"you indent, by putting a tab in front of every line, a tab is a big space"
"When you have a nested code block, you indent another level, or have an extra
tab in front of every line"
foobar 
while (barfoo){
	foobar
	if (baz) {
		qux
		bazqux
	}
	foobarbaz
}

Foo Bar Baz Qux
"Foo Bar Baz Qux are placeholder names , they don't mean anything and you can
put your own stuff in place of them."
https://www.ietf.org/rfc/rfc3092.txt for more information

Variable Declarations and Assignments
//When you declaring a variable, you tell the compiler that there is a variable
//named foo of type bar that now exists. You can only use a variable after
//declaring/defining it.
int foo;
//however, right now foo is "uninitialized", meaning there is no value being
//stored in foo, which means you can't use it. Initializing a function is just
//giving it a value.
foo = 0;
//a function that is defined and initialized
bar = 12;
//assigning a value to a variable just changes the value stored by a variable.
foo = 10;
foo = bar;
foo = foobar(12);

foobar(34);

Statements and Expressions
"Expressions evaluate to a value, where as statements do a thing. In c all \
statements are also expressions but you can ignore that"
a + b //is a statement
foobar(34); is a statement because function calls are statements
if (a + b) {} is an if statement
i++; increments i or adds 1 to it.

PRACTICE/REVIEW:
"identify the parts of the below code"

int main(int argc, char * argv[] ) {
	if(argc > 1) {
		printf("you gave me %d arguments\n",argc);
	} else {
		printf("you didn't give me any arguments\n");
	}
	return argc - 1;
}