Z
Z
zus2015-10-11 15:07:33
Programming
zus, 2015-10-11 15:07:33

How to output the data of the returned array?

Hi all!
Filled an array of type int and returned the array to main using a function.
How to display all elements of an array in main through cout so that the address in memory is not displayed.?
the point is that in a standard way like: cout << objectname->getMassiv(); as I said, it displays the address and I understand why. But I can not figure out how to display the elements in this case.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Martyanov, 2015-10-11
@zus

array[index] already tried?

M
Maxim Moseychuk, 2015-10-11
@fshp

Display each element of the array element by element.

for(size_t i = 0; i < array.size(); ++i) {
    cout << array[i];
}

But if you return an array from a function (namely, an array, not a container), then you cannot calculate its length. It is necessary to return the length separately. Moreover, if your array is local and you return its address from a function, you can shoot yourself in the foot on the spot. Otherwise, C++ will do it for you. 2 times.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question