Advertisements
Advertisements
Question
Why strlen is called pure function?
Solution
strlen (s) is called each time and strlen needs to iterate over the whole of ‘s’. If the compiler is smart enough to work out that strlen is a pure function and that ‘s’ is not updated in the lbop, then it can remove the redundant extra calls to strlen and make the loop execute only one time. This function reads external memory but does not change it, and the value returned derives from the external memory accessed.
APPEARS IN
RELATED QUESTIONS
The functions which will give exact result when same arguments are passed are called ______
The functions which cause side effects to the arguments passed are called ______
What is the side effect of the impure function? Give example.
Differentiate pure and impure functions.
Explain with example Pure and impure functions.