While using "array" as an identifier Codeblocks highlighted it like the other keywords. I searched it up in <a href="https://stackoverflow.com/questions/372580/why-is-array-a-reserved-word-in-c-c?answertab=votes#tab-top" rel="nofollow">Why is "array" marked as a reserved word in Visual-C++?</a>
But the answers were outdated. If yes, how is it used ?Answer1:
No, array is not a keyword.
Still, there is a C++11 standard-library type: <a href="http://en.cppreference.com/w/cpp/container/array" rel="nofollow">
std::array</a>, a fixed-length array container.
Here a list of the keywords from the C++1y draft:
alignas continue friend register true alignof decltype goto reinterpret_cast try asm default if return typedef auto delete inline short typeid bool do int signed typename break double long sizeof union case dynamic_cast mutable static unsigned catch else namespace static_assert using char enum new static_cast virtual char16_t explicit noexcept struct void char32_t export nullptr switch volatile class extern operator template wchar_t const false private this while constexpr float protected thread_local const_cast for public throw
These alternative representations (whose very existence I dislike, but that's just me) are not keywords though still reserved:
and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq
Contextual keywords (override control, put at the end of the function declaration in a class (
new not listed because already a keyword))
array is not a keyword, but the C++11 standard defines its STL with a <a href="http://en.cppreference.com/w/cpp/container/array" rel="nofollow">
std::array template container</a>. You should prefer
int tab; because
std::array have interesting functions and works better with other parts of the STL library.
Since it is a standard container, I would advise you to avoid using the
vector, because of
std::vector, etc...) identifier in your own code (especially in reusable headers), to avoid future potential conflicts with
<array> header, and also for readability reasons. But in principle you could define your own
array but I don't recommend that.
array is a standard container, as you can see <a href="http://www.cplusplus.com/reference/array/" rel="nofollow">here</a>.
It doesn't belong to the keywords, but it's part of the standard library.Answer4:
C++ Keywords are listed in the <strong>C++ standard, section § 2.13</strong>.
array is not listed there, so it isn't.
<strong>Note:</strong><ul><li><a href="http://en.cppreference.com/w/cpp/container/array" rel="nofollow">
std::array</a> is a standard type, but not a keyword.</li> <li>
arrayis a valid identifier, but it certainly is discouraged because of the previous point.</li> </ul>