To avoid things quietly breaking if you change the array size, I suggest
std::copy(a, a + sizeof(a)/sizeof(a[0]), b);
. Even better, wrap thesizeof()
junk in a macro -- or even betterer, use a function template instead:template <typename T, size_t N> size_t size((T&)[N]) { return N; }
– j_random_hacker Sep 8 '12 at 7:29
When i I was looking into Q&A this morning I found this comment(with 4 upvotes). I'm quite new at C++. What does a+sizeof(a[0])
means here, I thought sizeof(a[0])
will return 4 which stands for a int memory byte? Many thanks in advance!!.