in above code i am trying to overwrite each element of array by 0 First i overwrite each element of forArr[] array by 0 using for loop it gives out 0 0 0 0 so it is ok. But when i try to overwrite each element of enhancedForArr[] by 0 using enhanced for loop it gives output 0 0 3 0
The explanation by wise owen is clear. Because you overwrite the data "2" before you get it. If you use "int []enhancedForArr = {0,1,2,3};", you will get what you want. Hope I help you partly.
This really is interesting! I am just now trying to understand this very issue (the 'deep' differences between for and enhanced for - if there are any) and this exercise brought out something interesting that would have escaped my attention and understanding. Thanks for the exercise and for Wise's explanation!