| Physics and Astronomy |
Back to top
Dynamic memory allocation exampleThe example of two-dimensional dynamic allocation in the lecture did everything inside of main(). But the process of allocating and freeing these arrays had more than one step and these steps had to be done in the right order. This makes them classic candidates for a function. We demonstrate a suitable code here, and for variety use ints rather than floats Note that we do not actually need call free() in this case as the program is finishing anyway, but we do as a demonstration. |