Advertisements
Advertisements
Question
What happens if you modify a variable outside the function? Give an example.
Short/Brief Note
Advertisements
Solution
When a function depends on variables or functions outside of its definition block, you can never be sure that the function will behave the same every time it’s called.
For example let y: = 0
(int) inc (int) x
y: = y + x;
return (y)
In the above example, the value of y gets changed inside the function definition due to which the result will change each time. The side effect of the inc ( ) function is it is changing the data ‘ of the external visible variable ‘y’.
shaalaa.com
Is there an error in this question or solution?
