0

int array [5] = {5}; ? what the element in the array of the following code ?

4/15/2019 11:53:09 PM

Fernando Fergan Yugan

4 Answers

New Answer

+1

this kind of initialization is bad if I would say, because when you decided to access the arrays which you do not assign, then you start getting problem, I read a programming tips sometimes ago it says "initialize your array like you initialize you variables too', it did not make sense at first until I discover it's true, to your question from 1-4 should be which am not sure about because it could vary 0 and 0=5

0

0

so int arr[5] ={5}; is like saying, create array with 5 slots, and then assign that to a new array with only 1 slot of which contains integer 5 so after that line of code arr will equal an array with only one slot and one value orr you made an object array and you replaced it with another object array and yea , that initialization is bad . it looks bad and doesnt make sense and is what i call durty code. a simple fix: int[] array = {5}; with that code, u can enter any amount of values and the array will be the correct size and note: your code works just as good as any other. it just doesnt look correct

0

edit: just iriterate throught array.length rather than 5 and no problems will occur