Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part II. Pointers and Arrays 4. Pointers and arrays: Now, starting from the (original) basic program create a pointer, initialize it to the beginning of

Part II. Pointers and Arrays

4. Pointers and arrays: Now, starting from the (original) basic program

create a pointer, initialize it to the beginning of the array data

output the elements of data by indexing the array data[ ] using a loop (and the indexing operator []).

output the elements of data by indexing your pointer using a loop, with the pointer pointed at the beginning of the array and using [ ]

output the elements of data by incrementing the pointer each time through the loop. your loop control could look like this for (i=0; i < 5; i++) { p++; } or like this (why does this work?): for (p=data; p < data+5; p++)

reset your pointer to point at the beginning of the array again, then output the elements of data by adding i, a loop counter, to the pointer and dereferencing the summed address. Use something like: cout << *(p+i) (Be sure to point back at the beginning of the array before the loop!)

Q: how is cout << *(p+i) different from cout << *p+i ? If you're not sure, try both and see what happens. To verify your answer, look at the operator precedence table in the textbook and find the precedence of * (for dereferencing) and +. Which is higher precedence?

Name your program pointers_arrays.cpp

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

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

Define marketing concepts.

Answered: 1 week ago

Question

1 what does yellow colour on the map represent?

Answered: 1 week ago

Question

5. Develop the succession planning review.

Answered: 1 week ago