Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
it is said that in return if we put 'return 0' this means that code is alright and if we put any other integer that means there is some problem.

What I have tried:

C++
#include <iostream>
int main() 
{ std::cout<<"Hello World!";
	return 4556;
}
Posted
Updated 18-Jul-18 22:26pm
v2

Quote:
it is said that in return if we put 'return 0' this means that code is alright and if we put any other integer that means there is some problem.
That is true, but is just a convention. On process termination, you have to explicitely request the OS for the return code, in order to check it. See, for instance How do I get the application exit code from a Windows command line? - Stack Overflow[^]. On most cases, expecially on Windows, the program return value is plainly ignored. It is good practice, anyway, to follow the convention.
 
Share this answer
 
Quote:
Why this code works in visual studio 2017 even when I used return statement with digit something different than zero?

the return value is your program telling the caller if anything was correct or not.
When you run a program in a batch command file, it is the mean your program use to tell the batch file there was a problem or not.
This allow the batch file to make decision depending on that return value.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900