-j
optionmain: main.c
gcc --std=c99 main.c -Wall -Wextra -Werror -o main
clean:
rm -rf main
# FIXME: The target name must match the outputfile
# to take advantage of the caching system.
# also might help to run make with --debug option
Option Summary - Using the GNU Compiler Collection (GCC)
A pointer is simply a variable that’s value is a memory address to another variable.
// TODO: small discussion on stack, heap, virtual memory, kernel space,
// libc, and endianness
#include <stdio.h>
int main() {
int a = 5;
// while the convention is to write <int *p>
// I find it helpful to think of it as <int* p>
int *pointer_to_a = &a;
printf("%d %p %d",a, pointer_to_a, *pointer_to_a );
}
Structs offer a way to group values of same or different types together where each value can still retain its variable name (contrast this with arrays, where all values are of the same time and they are referred by their index, not name).
#include <stdio.h>
struct demo {
int serial_number;
int quantity;
};
int main() {
struct demo demo1;
demo1.quantity = 5;
demo1.serial_number = 22;
printf("%d", demo1.quantity);
}
demo.quantity
if we have a struct demo* d1
, the values are accessed as demo->quantity
.