Function in C: Function with No Inputs but an output

So let’s assume we are going to write a function which takes no input, but when it is called it generates a random value and returns it to where it was called. Just take a look at this code

Here we call get_random() function at line 11. So when called, the program execution jumps to the function body from line 3 to 7.

At line 5, it generate a random number by using the built-in rand() function. 

At line 6, it returns the random number it has just generated. But who receives the returned number? The answer is simple: the variable random on the left hand side of = operator at line 11 is receiving the random number returned from get_random() at line 6 (You can assume random as receiving variable). 

NB: If we did not assign any variable and just wrote get_random() at line 11, then still the function would return a value, but unfortunately the value would be lost as there is no receiving variable in the receiving end i.e. in main().

Just one more thing: why int at line3? That’s because we are announcing the compiler that the get_random() function is going to return an integer value (r is an integer) at the end. (Remember we wrote void in previous two cases? That’s because we had nothing to return in those scenarios.)

Just a off topic: Want to have a vertical monitor for programming? Take a look at ASUS ProArt Display PA278CV. This is so cool! 

I hope I have explained it well. Thank you!