Tamil Nadu Board of Secondary EducationHSC Science Class 12th

Why strlen is called pure function? - Computer Science

Advertisement Remove all ads
Advertisement Remove all ads
Advertisement Remove all ads
Short Note

Why strlen is called pure function?

Advertisement Remove all ads

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.

Concept: Pure Functions
  Is there an error in this question or solution?

APPEARS IN

Share
Notifications

View all notifications


      Forgot password?
View in app×