0
Why size of array declaration is not require?
Is it possible without size of array declaration we can use it. It may occur like memory leak problem. int arr[] = {11, 35, 62, 555, 989}; int sum = 0; for (int x = 0; x < 5; x++) { sum += arr[x]; } cout << sum << endl; //Outputs 1652
2 odpowiedzi
+ 3
Array can be of any size, that's not the problem. For loop might be the issue if you loop it more times than there are elements.
You will need to determine the length of the array somehow dynamically. Check out the std::array and range for, for example.
https://stackoverflow.com/questions/20234898/correct-way-of-loop-through-the-c-arrays
0
I didn't understand it, can u elaborate your answer please.