I am keeping the numbers in a vector called testVec. I'm sharing code here. What I am confused about is testVec returns true values in called function but after I call the vector outside of the function it returns first two element only. Why is that?
All of your functions are passing the vector parameter by value. What that means is a copy of the entire vector is made and passed to the function. What you need is to pass the parameter by reference. In that case no copying is done (therefore it is more efficient and uses less resources) as the vector inside the function is the actual vector which was passed.
However, there is a danger. When you pass the actual vector like this, it may accidentally be changed when you don't want it to be. For example when you print out the contents of the vector, you don't want any changes to occur. To guard against this, use the keyword const which tells both the reader and the compiler of your intentions. The compiler will then give an error message if your code in some way tries to make unwanted changes.
1 2
// vec passed by value, copy is made
void showVec(std::vector<int> vec)
1 2
// vec passed by reference, it may be changed
void resFin(int start, int stop, std::vector<int>& vec)
1 2
// vec passed by const reference, it may not be changed
void showVec(const std::vector<int>& vec)