7
I have noticed that some programs always have a code snippet, which is always executed last, which takes as a parameter a number, usually 0
or 1
.
For better understanding, I put this example of a Pyqt application:
#-*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
win = QtGui.QWidget()
win.show()
ret = app.exec_()
#quando eu fecho a aplicação, retorna 0
print ret
# todos os tutoriais que li, ensinam a colocar essa linha
# com esse retorno
sys.exit(ret)
My curiosities
In C, I’ve figured out the method int main
one usually returns a int
. Usually they return 0
(I don’t know if it’s related either).
In some PHP scripts, I’ve seen being returned 0
or 1
also at the end of the implementation of a programme.
For example
exit(0);
Anyway, I’d like to know what those numbers mean that are usually set in the "last line" of a program’s code.
Questions
What are the meanings of finishing a program with
0
or1
?Only
0
and1
should be used? Or are there other numbers, with specific meanings?What is the name given for this type of application exit? I read in any reply related here on the site that the term state code, but I’m not sure that’s it.
I think it’s dup.
– Maniero
I think it is, too, but I have no idea how to research this.
– Wallace Maxters
Vixe, but this one doesn’t explain why it has to return 0 or 1 and what is the meaning of them.
– Wallace Maxters
Note: I previously pointed out two possible duplicates, but when analyzing the questions and answers I saw that in fact the focus of the explanations was not the same as this and so I (personal opinion) I have removed my closing vote in favor of leaving the question open because I consider that there is not yet an appropriate answer and it is a great opportunity for someone to answer, anyway if you have a link to indicate I am grateful.
– Guilherme Nascimento
Related: PHP - What is the whole argument for in the Exit function
– Wallace Maxters