473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

difference between return 0 and retuen -1

difference between return 0 and return -1 .and exit(0) and exit(1)
Oct 17 '13 #1
1 3926
weaknessforcats
9,208 Expert Mod 8TB
Return values are just made up. many programmers return 0 to indicate the function completed successfully. This leaves all the other integer values to mean what kind of failure occurred.

Functions doing compares between two arguments A and B might return:

0 means A == B
1 means A > B
-1 means A < B

Functions returning pointers usually return 0 if the function fails since a 0 pointer is always invalid. A non-zero return is assumed to be a valid address.

In the case of main() and exit() the 0 means a successful end of the program and -1 means the program terminated in error. There is no access to this value outside the program so it's just there for the programmer to see in the code.
Oct 17 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: sugaray | last post by:
hi, this question just came up my mind that what's the difference between a 'return' with no expression and a 'break' or 'exit()' ? thanx in advance for your direction.
4
by: zealot | last post by:
Let us say I have a function void foo() { cout<<"Inside foo"; return; } A function with a return type as void should not return any value. Here if I retuen any integer it will bombard...
5
by: Angry C sharp user | last post by:
I am currently working on a Windows Forms Application and I need to create a few methods in another class and then call the methods back into my form1.cs but every time I set my global variables...
1
by: ilyaw77 | last post by:
Hi guys, I have a problem to calculate difference in date using difftime. Two strings are passed to the function day1="05/01/2007" and day2="04/30/2007" the difference I got is 2 days which is wrong...
2
by: moonlite4daylite | last post by:
May I know the difference between member and method...I understand that methods are routines or functons which return values.... and members are those which stores values... Apart from ths all, is...
1
by: m konstantakis | last post by:
#include <stdio.h> int main(void) { int currentprice,upcomingprice; int currentprice1,currentprice2,currentprice3; int upcomingprice1,upcomingprice2,upcomingprice3; int difference; float...
2
by: Parul Vinod | last post by:
My code is showing an error that not all code paths return a value. public bool ValidSession(string sessionid,string username) { SqConnection con=new Sqlconnection(str); string...
0
by: Keith F | last post by:
Right, so I am trying to find the answer to the above question and then return it as type IntSet. For this question, I need to use arrayList. I have tried tweaking the code a number of times,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.