最佳答案
Today i was reading about pure function, got confused with its use:
A function is said to be pure if it returns same set of values for same set of inputs and does not have any observable side effects.
e.g. strlen()
is a pure function while rand()
is an impure one.
__attribute__ ((pure)) int fun(int i)
{
return i*i;
}
int main()
{
int i=10;
printf("%d",fun(i));//outputs 100
return 0;
}
The above program behaves in the same way as in the absence of pure
declaration.
What are the benefits of declaring a function as pure
[if there is no change in output]?