When I create a method of type int the compiler reserves X number of bits in memory. So how does the see a void type? How many bits/bytes does a void type take up?
the void type does not take any bits. you cannot declare a variable of type void. this:
void a;
causes a compilation error.
void is just a place holder that means "nothing" a function that returns void returns nothing and a function that takes void as an argument, takes no arguments.
You can however declare a variable of type void*:
void* a;
This simply declares a pointer that can point to anything what so ever. as any pointer, it takes the size of a pointer type, i.e. sizeof(void*) which typically equals 4 in 32 bit systems.
I think the assumption you made about how a compiler stores return values might be too generic. What happens with return values is determined by the language, the type, and the hardware.
There might be a 'return register' that could hold the value of the return, so no memory would be taken up. The 'return register' could also just point to some allocated in memory based on the type being returned.
I don't see why a function returning void would ever have allocated memory for the return value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With