Functions are a wonderful feature of C++. They allow you to create code that is more readable and modular. You can declare functions in a very declarative way and, if you need to, you can call a function in a very clear way. This means that you can write the code to the compiler and link it into your application without the need to think about what it does at each turn.
A few years ago I was at a company that developed a large C library. In the process we had to create some functions that didn’t have a return type. The first piece of code that had this was a function that counted down from ten to zero. I’ve always thought that this was like the “douchebag” function that the original Ghostbusters used back in the ‘80s.
This is why you need a return type. The reason is so that the compiler will know at compile time what the point of this function is. A function that returns a value is called a function that has a return type. The compiler will know this at compile time and will know what to do at that point. The compiler will then ask the developer to implement the code that this function actually does.
The compiler is called the “C++ compiler”. It is an amazingly useful piece of software. The C++ compiler will ask you to implement the function that a given compiler will create. (The C++ compiler is called GCC). GCC will then ask you to implement the function that the compiler created. (The C++ compiler is called Microsoft’s Visual C++). The purpose of the compiler is to make your code work on the different compilers it supports.
The compiler’s job is to translate your source code to the machine code for the different compilers it supports. If the compiler can’t do that, then you need to figure out how to make your code do so.
In GCC you will have to do so by defining a prototype.
C++ is the language of computers and computer games, and is so powerful that it is often used to create many different programs for different purposes. It’s just a language that just looks nice and lets you see all that you need to know about how it works.
So here is where the job falls apart.
You can use a bunch of different languages. You can also use a bunch of different compilers. In Java you can’t just use one compiler. You have to use a bunch of them. C# is one, C++ is another. They are all great languages. And yet, despite that fact, the standard doesn’t support returning a value.
Returning a value is absolutely required so that the compiler can actually make a difference. You can do a lot of stuff in C that you cant do in Java and vice-versa. Here is a very simple example if you were to write a program that called a function that returned a variable. You would have to use a return statement. This is the exact same exact code as you would use in Java.