The title says it all. I see that there is a difference between using vec.begin()
and &vec[0]
as former returns a std::vector<T>::iterator
and latter returns a pointer to an object of type T
. The book I am currently reading (The C++ Primer, 5th Edition) suggests that you use the std::begin()
function in the iterator
header to get the first element of an array. However, since this function also just returns a pointer, wouldn't be using the variable name as a pointer to the first element be quicker / more efficient?
Edit This question is not a duplicate as marked. I am not asking for the difference between the container member methods and the ones from the C-Library. Let me clarify my problem:
int numbers[] = {0, 1, 2};
// is there any major difference between
int first = *numbers;
// and
int first1 = *std::begin(numbers);