+ 1

What is the difference between return 0; return 1; return -1; in C programming Language ?

24th Sep 2018, 3:08 PM
Kumar Atul Jaiswal
Kumar Atul Jaiswal - avatar
2 Answers
+ 4
0 means program worked succesful 1 means general error -1 means 255 beacuse main cannot return negative exit status
24th Sep 2018, 3:51 PM
Aleksander Szczepura
Aleksander Szczepura - avatar
+ 2
Assuming these are exit codes, it's kindof up to you what they mean (it's why documentation is nice), but lots of programs use these numeric codes for interprocess communication / logging: Microsoft: https://docs.microsoft.com/en-us/windows/desktop/debug/system-error-codes Linuxes (just an example; there are other lists): https://github.com/torvalds/linux/blob/master/tools/arch/parisc/include/uapi/asm/errno.h [meta, for readers] Note that negative return codes will wrap around as Olek Szczepura indicates; Microsoft errors like (-2147217865 ) are often more easily found converted to hexadecimal: 0x80040e37
24th Sep 2018, 4:39 PM
Kirk Schafer
Kirk Schafer - avatar