1.

What happens if you modify a variable outside the function? Give an example?

Answer»

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 get 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’.



Discussion

No Comment Found