The difference of void and float when creating a function

Hi there,

I’m quite curious about the difference between void and float
I notice that when it is written return fahr;, the function starts with float. but when it doesn’t show return anything, it starts with void
how exactly these two things are different?

The bit at the beginning of the line declares the type of thing that the function is going to return.

The return statement is the line in the function that actually causes the function to spit out its output to the code that called the function.

The function that converts degrees celsius to degrees fahrenheit is declared as returning a float, and so there must be a return statement in the function that gives a float back to the function’s caller:

float fahrenheitFromCelsius(float degreesCelsius) { float degreesFahrenheit = degreesCelsius * 1.8 + 32.0; return degreesFahrenheit; }

A function that doesn’t actually have any output (doesn’t give anything back) accordingly doesn’t have a return statement at all. The function is declared as returning void as a way to tell the compiler that the function doesn’t return anything:

void sayTheNumber(int someNumber) { printf("the number is %d", someNumber); }

void isn’t actually a type like float or int. You can’t declare a variable of type void. void is a placeholder that’s used to indicate the absence of an argument or return type to the compiler in cases like the function above.