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.
- "Write a function that uses pointers to display the contents of an array.
- The function should have the following prototype:
- displayArray(int *arr, int size);
-
- 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.
- You may not use the array subscript operator for this function. Instead use pointer arithmetic, pointer comparison, and the indirection operator *.
- 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.
- 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
