Answered step by step
Verified Expert Solution
Link Copied!

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.

  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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Integrate: sin(5x)dx

Answered: 1 week ago

Question

Design a health and safety policy.

Answered: 1 week ago