Skip to main content
0 online
O
orbitzOG 2001

First of all:

void main is incorrect.

It should be int main(). And because it's int main() it should have a return statment. Although in C++ that is not required.


Secondly, you should read the section of your book on pointers. Your problem is at:


void PopulateArray(int r, int size)


Just because you are using pointers does not mean the laws of the language have changed. In this, r is a local variable containing one value which is an integer.


This means that:
*(q+i)


Is out of bounds, since int r only holds one location for an integer.


Also, your conditional makes very little sense.


for (int i=0; i> *(q+i);
(I assume you mean to finish that as i++)


You want to interate while i is greater than the value at q[i]? What? This means your code is quickly going to go out of bounds of q..


You should seriously reread the section of yoru book on pointers. If your book is no good, Thinking In C++ by Bruce Eckel is available freely online, just google for it.

ok4now ok4nowOG 2002

please take another look...the paste didn't work right because i left a < sign which turned everything else into an html tag. question: how do i pass a pointer to a function? or, how do i pass a dynamically created array to a function (without using indices)?

Welcome Back to eZabel

It's been a while. Here's what's new.

eZabel Lore

A complete history of our community — stats, Hall of Fame, legendary threads, and more.

View the Lore →

Everything Preserved

All 225,969 pieces of content from 2000–2014 are here — forums, messages, journals, photos, polls, and events.

💎

Gems

Spot something you love — a legendary comment, a classic thread, a great photo? Log in and click the diamond icon to mark it as a Gem. Add a note about why it's special. The best stuff surfaces on the Gems page.