how to swap elements of vector in different functions code example Example: swap two elements of a vector std::iter_swap(arr.begin()+pos1,arr.begin()+pos2);