Void and bool are simple types that you can use with very little explanation. There are a few details that you should be aware of though.

Think of void as an absence of a type and not really a type itself. There are specific places where void can be used and this will depend on your language.

Most languages allow you to declare a method that returns nothing by declaring the method returns void. When you do this, then it’s a compile error to try returning an actual value.

You cannot use void to declare a variable or a reference but if your language supports pointers like in C++, then you can have a pointer to void.

You also cannot use void as a template type in C++ or as a generic type in C#. That’s all for C#. But C++ has one additional twist to using void with templates. In C++, you can specialize a template. Let’s say you have a template that takes two type parameters. You could instantiate an instance of this template with an int and another int. Or a short and a char. Or any two types. But you can’t use void. There is a way to get around this by specializing the template so that the new specialized template only needs one parameter type and the other one is written to use void. So even though you can’t pass void directly through the type arguments to a template, you can use void in a special version of the template.

You might expect that a data type that can only hold true or false values requires no further explanation. But there wasn’t always a bool data type available so developers sometimes created their own. And these creations didn’t always match.

Most of the time, code that needed to define its own bool data type would define true to be the value 1 and false to be the value 0. A notable exception to this was Visual Basic which defined a type called a VARIANT_BOOL and it used -1 to mean true and 0 to mean false. You can’t just assign true or false to your variable but will need to use special VARIANT_TRUE and VARIANT_FALSE values that have been defined to be -1 and 0.


What's on your mind?
On a scale of 0 to 10, how likely are you to refer us to friends?