Question: In C arrays can be accessed using pointers. As an exercise, write a function that reverses the polarity of every element in a 2 D

In C arrays can be accessed using pointers. As an exercise, write a function that reverses the polarity of every element in a 2D int array (i.e.,-1 becomes 1,46 becomes -46,...etc.) using only pointers. That is, your code must not use any [], which is the non-pointer version of array access. Use this function header:
void reversePolarity(unsigned int row, unsigned int col, int** array)
For example, suppose we have a 2-by-3 array my2DIntArray with the content [[0,1,-2],[-999,2345,678]]. Then the function will be called as (the array needs to be created differently, see the test file):
reversePolarity(2,3, my2DIntArray)
And when the function returns, the content of my2DIntArray becomes [[0,-1,2],[999,-2345,-678]].
You can assume that the row & col parameters always correctly indicate the number of rows & columns of the array. Do not use [] anywhere in your answer (if you do you get 0 for this question).
Only include the a1_question3.h header file and the function definition (and your helper functions, if any) in the source file and name it as a1_question3.c.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!