While answering my question in codereview.stackexchange, it was suggested to use,
template <class T, size_t size>
T peak(const T (&arr)[size]) {
Instead of,
int peak(int * arr, size_t size)
{
Now I have two questions here,
- How compiler can calculate size, while C++ compiler cannot bound check
- What if I use arr[size] instead of (&arr)[size]. I mean is there anything like (arr&)[size]. If yes, what is the difference.