Why my program did unexpected works ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why my program did unexpected works ?

Fifrstly, by initialization one-dimensional vector? And then, by inserting ? https://code.sololearn.com/cty7k5CmiB4W/?ref=app Why nulls ?

6th May 2020, 5:02 AM
stamb
stamb - avatar
6 Answers
6th May 2020, 7:27 AM
Moses Odhiambo
Moses Odhiambo - avatar
0
stamb I'm not really sure what you're trying to do, but here's code that 'works' https://code.sololearn.com/cIfg4MFsKQ9C/?ref=app Anyway, you should not use the end() iterator to access the last element, as it points past the end of the vector. Instead, use front() and back() to access the first and last elements. I also noticed that in line 12, you initialized the vector with brackets rather than curly braces. Doing so initializes the size but not the elements.
6th May 2020, 6:17 AM
Moses Odhiambo
Moses Odhiambo - avatar
0
Moses, Your variant is understanding, but it's not correct too.
6th May 2020, 6:35 AM
stamb
stamb - avatar
0
stamb What is the program supposed to do?
6th May 2020, 6:36 AM
Moses Odhiambo
Moses Odhiambo - avatar
0
I want to receive all array(i.e. four elements). Thus front() and back() not that. And so by initialized with {} (as you variant) will be first and last elements only, rather all array !
6th May 2020, 6:49 AM
stamb
stamb - avatar
0
Correct, Moses. I know, it's simply. But my question was about unexpected works my program! And solution must be the ONE command (by initializes or Insert/Copy/Assign... or other).
6th May 2020, 8:12 AM
stamb
stamb - avatar