Computer Science, asked by kumarisugithasoman, 1 month ago

Why strlen is called pure function?​

Answers

Answered by XxitsmrseenuxX
32

Answer:

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 to execute only one time.

Answered by cjha33976
1

Answer:

pure function is one without any side-effects. ... strlen is a good example of a pure function in C. If you call strlen with the same string, it always returns the same length. The output of strlen (the length) only depends on the inputs (the string) and nothing else. Many functions in C are, unfortunately, impure

Similar questions