Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- // before now, the memory your program was allowed to use was limited by the variables it declared
- // what if we need more space that our variables reserved?
- // what if we don't know how many "employees" we are going to need in our array
- // this creates an integer pointer, points to first item in heap
- int * points;
- // malloc gets memory from the heap, need to tell it how many bytes
- // we don't know how many bytes an int is, but we know we need 10
- // (int *) is an int typecast pointer, we will be using this memory to store ints
- // can now just use point[0], points[1], etc...
- points = (int *) malloc(5 * sizeof(int));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement