Question: What side effect does the following function have? How could it be rewritten to avoid side effects? // Doubles the values of all elements in
What side effect does the following function have? How could it be rewritten to avoid side effects?
![// Doubles the values of all elements in an array. public static void doubleAll (int[] a) { for (int i 0; i < a.length; i++) { %3D a[i] = 2 * a[i];](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1607/4/2/3/8675fcf577bdf2f51607423867145.jpg)
// Doubles the values of all elements in an array. public static void doubleAll (int[] a) { for (int i 0; i < a.length; i++) { %3D a[i] = 2 * a[i];
Step by Step Solution
3.41 Rating (154 Votes )
There are 3 Steps involved in it
The functions side effect is that it modifies the array that was passed in It could ... View full answer
Get step-by-step solutions from verified subject matter experts
