English

Why strlen is called pure function?

Advertisements

Question

Why strlen is called pure function?

Short/Brief Note
Advertisements

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.

shaalaa.com
Pure Functions
  Is there an error in this question or solution?
Chapter 1: Function - Evaluation [Page 9]
Advertisements
Share
Notifications



      Forgot password?
Use app×