, ++ Variable Length Arrays (VLAs). , VLA, ++.
,
int main() {
int n = 10;
int list[n];
int main() {
const int n = 10;
int list[n];
, , .
pos, , . C memmove.
#include <iostream>
#include <algorithm>
#include <iterator>
int main()
{
const size_t N = 10;
for ( size_t i = 0; i < N; i++ )
{
int a[N] = { 0 };
auto pos = std::next( std::begin( a ), i );
std::copy_backward( pos, std::prev( std::end( a ) ), std::end( a ) );
*pos = i + 1;
for ( int x : a ) std::cout << x << ' ';
std::cout << std::endl;
}
return 0;
}
1 0 0 0 0 0 0 0 0 0
0 2 0 0 0 0 0 0 0 0
0 0 3 0 0 0 0 0 0 0
0 0 0 4 0 0 0 0 0 0
0 0 0 0 5 0 0 0 0 0
0 0 0 0 0 6 0 0 0 0
0 0 0 0 0 0 7 0 0 0
0 0 0 0 0 0 0 8 0 0
0 0 0 0 0 0 0 0 9 0
0 0 0 0 0 0 0 0 0 10
std::vector, , . .
std::vector, .
iterator insert(const_iterator position, const T& x);
iterator insert(const_iterator position, T&& x);
, , , .