Beruflich Dokumente
Kultur Dokumente
Allocation
Dynamic Data
Suppose we write a program to keep
track of a list of students
How many student records should we
create?
What if we create too few?
What if we create too many?
ptr = &y;
x = *ptr;
Pointers to Structures
Declare a pointer to a structure of type
inventory_item
Pointers to Structures
Declare a pointer to a structure of type
inventory_item
inventory_item *shirts;
free(var_name)
free up the memory pointed to by var_name
Examples
int *int_ptr;
int_ptr = (int*)malloc(sizeof(int));
inventory_item *shirts;
Examples
int *int_ptr;
int_ptr = (int*)malloc(sizeof(int));
inventory_item *shirts;
shirts = (inventory_item*)malloc(sizeof(inventory_item);
(*shirts).id = 1234;
shirts->cost = 20.00;
Examples
int *int_ptr;
int_ptr = (int*)malloc(sizeof(int));
inventory_item *shirts;
shirts = (inventory_item*)malloc(sizeof(inventory_item);
(*shirts).id = 1234;
shirts->cost = 20.00;
free(int_ptr);
free(shirts);