name: main
<style> .aim { font-size: .75em; border-bottom: 1px solid lightgray; margin: 1px; } .remark-inline-code { background-color: lightgray; border-radius: 3px; padding-left: 2px; padding-right: 2px; } h4 { font-size: 1.5em; margin: 1px; } </style>template: main
- You can run the rules for a specific target with
$ make TARGET
--
- rules do not need to always involve compilation. Common non-compiling targets include:
--
run
: run the created program.
--
clean
: remove unnecessary files (.o, ~, etc)
??? show euler
add euler.h to euler.c, get into #ifndef thing.
template: main
- Even though all pointers are the same size, we declare them using the type of the value pointed to.
--
*
is used to declare a pointer variable.int *p = &x;
p
is a pointer variable that stores the address of the variablex
.
--
- In Java, object variables, or references, are essentially pointers, called references instead.
--
- The exception you get when you try to use an uninitialized object variable in Java is null pointer, meaning the reference stored is 0 (null), which is an invlaid memory address.
template: main
- Consider the following C snippet:
unsigned int i = 2151686160;
int *ip = &i;
char *cp = &i;
ip
andcp
will store the address of the first byte used to storei
. Depending on the endianness of the system, that byte will either be10000000
(big) or00010000
(little).
--
- Let's just say that the first byte is located at memory address
3000
(using small number for ease of discussion)
--
- If you perform
ip++
andcp++
, each pointer will be incremented by 1, but due to pointer arithmetic,ip
will increase to3004
andcp
will increase to3001
. In essence,ip
would move oneint
forward in memory, whilecp
only moves one byte forward.
template: main
*
is also used as the de-reference operator. This will return the value stored at the memory address pointed to by the pointer.
--
- Given the definitions of
x
andp
above:
--
int y = *p + 10;
would sety
to the value15
.
--
*p = y;
would set the value at the memory address stored inp
(in the example is 2000), to whatever the value stored iny
is.