Usually languages need a starting point. In java
, c
, c++
, ada
, pascal
, assembly
, etc, a method or a block (in the case of pascal) is used to know where the application will start.
In Assembly the code starts in the method _start
(if it is Linux), the C, decides that the program should start on main
and the pascal has a cloc of begin
and end.
to tell where the application will start.
The return of the method serves to know if everything happened well during the execution of your progamma.
Example of use of return:
$ gcc main.c -o compiled
$ echo $?
If the file is compiled successfully it will return 0, the other values are for different types of error.
Another method of use is:
$ gcc -fPIC -shared -O2 mylib.c -o libmy.so &&
$ gcc main.c -o compiled ./libmy.so &&
$ echo "compilado com sucesso!" ||
$ echo "Erro ao compilar!"
The symbol &&
refers to a condition e
, if the 2 files have been compiled successfully, the first will be called echo
, because it is part of the condition e
, otherwise, will be called the second echo
, for the condition or
is only called if the e
be false.
I have heard that this is a return to the operating system. "0" means that the program has run successfully ...
– mau humor