i have not defined <stdlib.h> header and included rand() function and it works without this header. How?

If you don't declare a function before using it, the compiler will assume that it's an external function accepting an unknown number of arguments and returning int. If those assumptions hold true, you're good. It's a horrible practice, but it'll work (barring functions with variable arguments like printf()).