Section 2 - Arrays
Section 2 - Arrays
Think.
Pair.
Share.
● What are the steps involved in compilation?
● What are arrays?
● What are strings?
● What's the point of command-line arguments?
● What are the steps involved in compilation?
● What are arrays?
● What are strings?
● What's the point of command-line arguments?
● What makes for good design?
int main(void)
{
printf("Hello, world");
}
...
main:
# @main
.cfi_startproc
# BB#0:
push %rbp
.Ltmp0:
.cfi_def_cfa_offset 16
.Ltmp1:
.cfi_offset %rbp, -16
movq %rsp, %rbp
.Ltmp2:
.cfi_def_cfa_register %rbp
01111111010001010100110001000110
00000010000000010000000100000000
00000000000000000000000000000000
00000000000000000000000000000000
00000001000000000011111000000000
00000001000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
10100000000000100000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
01000000000000000000000000000000
00000000000000000100000000000000
00001010000000000000000100000000
01010101010010001000100111100101
01001000100000111110110000010000
00110001110000001000100111000111
01001000101111100000000000000000
00000000000000000000000000000000
00000000000000001011000000000000
11101000000000000000000000000000
00000000010010001011111100000000
00000000000000000000000000000000
00000000000000000000000001001000
$ clang
$ clang hello.c
$ clang -o hello hello.c
$ make hello
Arrays
int hours_1 = 7;
int hours_2 = 9;
int hours_3 = 8;
int hours_4 = 7;
int hours_5 = 8;
hours
7 9 8 7 8
name
hours
7 9 8 7 8
hours
7 9 8 7 8
size
hours type (int)
7 9 8 7 8
int hours[5];
hours
? ? ? ? ?
name
int hours[5];
hours
? ? ? ? ?
size
int hours[5];
hours
? ? ? ? ?
type
int hours[5];
hours
? ? ? ? ?
int hours[5];
hours
? ? ? ? ?
int hours[5];
hours
? ? ? ? ?
hours
7 ? ? ? ?
hours
7 9 ? ? ?
7 9 8 7 8
7 9 8 7 8
E m m a \0
name
E m m a \0
7 9 8 7 8
E m m a \0
E m m a \0
65 66 67 … 90
a b c … z
97 98 99 … 122
string name = "Emma";
name
69 109 109 97 \0
asciichart.com
Command-line
Arguments
$ clang
$ clang mario.c
$ clang -o mario mario.c
$ make mario
int calculate_quarters(int cents)
{
...
}
Function argument(s)