Please note that I am running a Linux machine, although I do not think that the result is different from a Windows (or other) machine.
This is a simple question - C ++ programs usually return a 32-bit int. If I return -1, and then print the result from the terminal, the result will be 255.
return -1
255
Why is this? I feel connected, this is what I should have known or should have noticed many years ago. I have never used return codes before, or thought about it before.
C ++ Testing Program:
int main() { return -1; }
Compile:
g++ main.cpp -o a.out
Run:
./a.out
Check the result:
echo $?
Result:
I would expect to see 2 ^ 32 - 1.
Why the result is 255not -1or even 4294967295. ( 2^32 - 1)
-1
4294967295
2^32 - 1
( ) . 8 . ( , ), "" "" , , " ", , C ++ , [ ] - C int - C , , , 432, C ++.
int
C , 0 EXIT_SUCCESS ( 0, ) EXIT_FAILURE ( ) . "" , , /, .
0
EXIT_SUCCESS
EXIT_FAILURE
, ( - ), main, , , main. main /, , . , , :
main
C ++ , , / C / ++, C ++ - " " - , , .., .
int, 0-255.
, (unsigned char) main() .
:
exit
exit(your_return_value)
Source: https://habr.com/ru/post/1599643/More articles:How to execute Docker node command from container? - pythonarray_filter convert indexed array to associative array - arraysGit Перемещенные файлы перемещаются из одной ветки в другую, прежде чем нажать - githubHow do I know when a new contact is added to the Android phonebook? - androidЖирный тег `` и тег Italic `` не применяются для пользовательских семейств шрифтов - htmlAre private parameter type applications possible in Java? - javaПеренесите начальный Angular ng-view на стороне сервера и возьмите его оттуда - angularjsУстановите уровень изоляции в eclipselink - jpahow to push json to an array in mongodb - mongodbWhat does “Index parameter outdated and will be removed (supposedly True) at 0.17” mean? - pythonAll Articles