Question: Below is the homework question I am struggling with. Specifically number 3. I have never used an array without a subscript operator and am uncertain

Below is the homework question I am struggling with. Specifically number 3. I have never used an array without a "subscript operator" and am uncertain how to get my pointers to direct to an array not using the subscript operator. I just can't seem to get it to work and could use an example or advice. How do I display the contents of an array without a subscript operator using pointers.

  1. "Write a function that uses pointers to display the contents of an array.
    1. The function should have the following prototype:
    1. displayArray(int *arr, int size);
    1. Write the function definition so that it displays all of the elements of array arr on the same line with spaces in between each element, and a newline at the end.
    2. You may not use the array subscript operator for this function. Instead use pointer arithmetic, pointer comparison, and the indirection operator *.
    3. You may find it easier to implement the function first using the subscript operator, make sure it works, then replace it with the appropriate pointer operations.
    4. In your main function, create and initialize an array of ints, then call displayArray to display the contents."

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 Databases Questions!