Exercise on Pointers

Test your knowledge on pointers and dynamic memory!

We'll cover the following

In an earlier exercise (in the Complex Data Types section), we saw how to print a matrix and how to multiply two matrices. But the size of the matrix was a fixed constant. Now, we want to accomplish the same using a matrix that’s created using dynamic memory allocation, so that the number of rows and columns of the matrix are passed as variables to a function createMatrix.

Question

Complete the definitions of the functions createMatrix, destroyMatrix, printMatrix, and matrixMult provided below.

First, your function will be called with two matrices. After that, the function will be applied to these matrices, and the output will be printed. Here is an example of what the output from your finished program might look like:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy