Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started