That error occurs in this function too:
1 2 3 4
|
int foo() {
int * bar;
return bar;
}
| |
The 'bar' is a pointer, but the return type of the function (on line 1) is an integer.
In your case you probably do not want to return an integer, but a pointer. Therefore, your function should return a pointer.
The rest of your code is worse than before. You do create a pointer 'iptr'. Then you set it to point to dynamically allocated integer, whose value you do not initialize.
The only thing that you do with the pointer is to dereference it during each iteration to get the same uninitialized value that you use as index to an array. That can be an out-of-range error. Anyway, the entire line 13 should not exists. The magic must exist on line 12.
Finally, you don't deallocate the single int that you allocate on line 4.
You could make the newArraySize a reference argument rather than a pointer.
Try the program that I did post. Look at the values that it does print. Do you spot any pattern?