Computer Science, asked by voney7552, 6 months ago

Difference between pure and impure function

Answers

Answered by Kausmitachakrabarti
2

Answer:

In pure function it doesn't modify the external variable/data outside the scope and results the same output given in the same input. In impure function it mutates data/variable outside it's lexical scope

Explanation:

Hope this may helpful to you !.....

Answered by 16MIS3472
4

A pure function will always return the same value when given the same arguments and its execution cannot change anything by any means other than returning a value.

An impure function violates one or both of these rules. For example, printing to the console is impure because it changes something (the console) by a means other than returning a value (it actually returns no value). Another impure function would be getTime() (or the equivalent in a given language) because it accepts no arguments but returns a different value (the current time) every time you call it (gives different return values for the same set of arguments, which happens to be no arguments, in this case).

Pure functions are useful because you can rely on them not changing anything when you call them and the value they return depending only on the arguments you pass to the function (can’t be changed by external code or factors such as how many times you’ve called the function).

Hope it helped you

Similar questions