• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer

Mr.CodeHunter

Programming and Code Solutions

  • Home
  • C++
  • About Us
  • Contact Us
  • Privacy Policy

return 0 c++

June 27, 2021 by Admin Leave a Comment

There are two different scenario return statement is used inside c++ programming. We can use return 0 c++ inside main() function or other user defined functions also. But both have different meanings.

  1. return 0 c++ used inside Main function
  2. return 0 c++ used inside other user defined function
return 0 and return 1 c++ meanings
return 0 and return 1 c++ meanings

What is meaning of return 0 and return 1 in c++ ?

There will be two scenario for it. Possible function can be main() function or any other user defined function.

return 0 c++ in main() function.

If c++ program is completed successfully then it will return 0 in main function.

#include <iostream>
using namespace std;

int main() {
	// Successfully completing program
	return 0;
}

return 1 c++ in main() function.

If there is some error in program or exited with error then it will return 1 in main function.

#include <iostream>
using namespace std;

int main() {
	// Errors in completing program (Exited with Error)
	return 1;
}

return 0 c++ in boolean return type function

If there is function in c++ with return type boolean then if it return 0 then it means return false. You can use this return for checking that required condition or logic is satisfied or not.

bool func(int iVal) {
	if (iVal == 2) {
		// Same as return true;
		return 1;
	}
	else {
        // Same as return false;
		return 0;
	}
}

In given function if function return 1 means value is 2 otherwise it will return 0. So we can identify by this function that given value is 2 or not.

return 1 c++ in boolean return type function

If function return 1 means our condition is satisfy and it will return true.

#include <iostream>
using namespace std;

int main() {

	// result1 is true (return 1)
	bool result1 = func(2);

	// result2 is false (return 0)
	bool result2 = func(2);

	// Successfully  completing program
	return 0;
}

bool func(int iVal) {
	if (iVal == 2) {
		return 1;
		// Same as return true;
	}
	else {
		return 0;
		// Same as return false;
	}
}

CONCLUSION:

If we want to exit our program successful then we return 0 inside main function. If there is some error during exiting program then we can return 1 inside main function. In case of other user defined functions which return boolean value. Then we can check conditioning of function using return value of function. Here if function return 1 means condition is TRUE and if function return 0 then conditions is FALSE.

SEE MORE:

What is c++ used for? | Top Uses of C++ programming language
How long does it take to learn c++?

Filed Under: All C++, C++

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Search here

Social Media

  • Facebook
  • YouTube

SEE MORE

Fibonacci sequence c++

Fibonacci Sequence c++ is a number sequence which created by sum of previous two numbers. First two number of series are 0 and 1. And then using these two number Fibonacci series is create like 0, 1, (0+1)=1, (1+1)=2, (2+1)=3, (2+3)=5 …etc Displaying Fibonacci Series in C++ ( without recursion) Output: From given output we […]

map c++

C++ Map [Learn by Example]

C++ map is part of Standard Template Library (STL). It is type of Associative container. Map in c++ is used to store unique key and it’s value in data structure. But if you want to store non-unique key value then you can use Multi Map in c++. Let us first understand in detail what is […]

how to copy paste in turbo c++ ?

There are many different C++ IDE are available but still many students are using Turbo c++ for learning c/c++ programming languages. During using Turbo c++ if you are beginner you will be confuse for how to copy and paste in turbo c++ or if you have already copy some content and you want to paste […]

C++

return 0 c++

There are two different scenario return statement is used inside c++ programming. We can use return 0 c++ inside main() function or other user defined functions also. But both have different meanings. return 0 c++ used inside Main function return 0 c++ used inside other user defined function What is meaning of return 0 and […]

C++

c++ expected a declaration [ SOLVED]

When any function or statement is not in scope or we have used wrong syntax then possibly you will get error for c++ expected a declaration in your code. Main reasons for errors are: Incorrect use/declaration inside namespace Statements are added out of scope Required statement need to add inside main/function Solution-1 | Expected a […]

C++

c++ cannot open source file “errno.h” [SOLVED]

Normally you will face c++ cannot open source file “errno.h” in MS Visual Studio c++ projects. These are some solutions to remove opening errors for “errno.h” file. I got the errors to go away by installing the Windows Universal CRT SDK component, which adds support for legacy Windows SDKs. You can install this using the […]

Footer

DISCLAIMER

The information contained on https://www.mrcodehunter.com is for general information purposes only. We assumes no responsibility for errors or omissions in the contents on the Service.

SITEMAP XML

Sitemap

Recent

  • Fibonacci sequence c++
  • C++ Map [Learn by Example]
  • how to copy paste in turbo c++ ?
  • return 0 c++
  • c++ expected a declaration [ SOLVED]

Search

Copyright © 2025 ยท Mr Code Hunter