Shreyas’ Notes

Introduction to Computer Systems

COMP 321

spring, sophomore year

Memory Allocation §

malloc returns a void *. If it fails, it will return NULL.

#include <stdlib.h>

// ...

int *i = malloc(sizeof(int));
int *array = malloc(4 * sizeof(int));

*i = 3;
array[3] = 5;

Memory allocated by malloc is not initialized.

Space allocated via varaible declaratin is auto-deallocated when exiting scope.

Explicitly allocated memory must be deallocated explicitly using free. Else, it is freed when the program terminates.

const int *ptr; // pointer to const int
int *const ptr; // const pointer to int

Assignment expression evaluates to RHS.

Assembly Language §

cc -S main.c

Exception Flow §