Recommended Posts

Hi,
I''ve got a function that returns an array of 2 ints. When I check the array in the function it displays the values correctly. When I call the function and display the 2 values then, I get wrong data. The first value is correct, but the seconds seems to resemble an address. Maybe I did something wrong?

Share this post

Link to post

Share on other sites

quote:Original post by jkeppens I''ve got a function that returns an array of 2 ints.

You can''t have. It''s not possible!

quote:Maybe I did something wrong?

Yes, you''re returning a pointer to a local variable. When the function returns, the pointer is left dangling, and dereferencing it leads to undefined behaviour. This is just one of the ways in which C++ arrays are evil.