We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C++
- Introduction
- Arrays Introduction
- Discussions
Arrays Introduction
Arrays Introduction
Sort by
recency
|
1365 Discussions
|
Please Login in order to post a comment
The “C++ Introduction: Arrays” section on HackerRank is a great starting point for beginners learning how arrays work in C++. Radhe Exch Login xyz
Arrays allow you to store multiple values of the same type in a single variable, making it easier to manage collections of data! Funinmatch360 com mobile
Easy solution
Reading input and writing output can honestly be done either with cin / cout or scanf / printf. Coming from a MATLAB / Python / C background, I personally prefer using printf than cout. Regardless, this two-pass solution is relatively easy
Although it really bothers me that it throws this warning :
Variable length arrays in C++ are a Clang extensionclang(-Wvla-cxx-extension) Solution.cpp(14, 13): Read of non-const variable 'n' is not allowed in a constant expression.
It still compiles and works, but I think that exercises shouldn't throw warnings when a correct solution is written....
}
The code asks for an array, but you can't initialise and array with a non-const integer. The exercise should either explicitly state you can use a vector object (as you would), or if an array is required that it should be created on the heap so it's possible.