473,756 Members | 6,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

where does /return value/ go?

1.) we usually say /return 0/ indicates success e.g

#include <iostream>

int main() {
int i=3;

std::cout << i << std::endl;

return 0;
}
i ran the programme & i see only /3/ as output. i dont see any /0/ on
my terminal. where does it go? & who reads /0/ to indicate success?

Oct 31 '06 #1
4 2766
arnuld <ar*****@gmail. comwrote:
>1.) we usually say /return 0/ indicates success e.g

#include <iostream>

int main() {
int i=3;

std::cout << i << std::endl;

return 0;
}
i ran the programme & i see only /3/ as output. i dont see any /0/ on
my terminal. where does it go? & who reads /0/ to indicate success?
Programs such as shells and make utilities can see and use the return
value of a program. A user executing the program from the command
line does not usually see it.

You'll have to look at your operating system documentation to
learn more.

Steve
Oct 31 '06 #2
arnuld wrote:
1.) we usually say /return 0/ indicates success e.g

#include <iostream>

int main() {
int i=3;

std::cout << i << std::endl;

return 0;
}
i ran the programme & i see only /3/ as output. i dont see any /0/ on
my terminal. where does it go? & who reads /0/ to indicate success?
If you executed your program from the std::system function call then the
value is partly returned by the system call. If the return value from
system() is negative then there was an error, otherwise the lower 8 bits
are the lower 8 bits returned from main often termed the "status".

Other facilities like "pclose", createprocess, waitpid, etc also enable
getting at the "status" in the same way.

The convention is to return 0 if the program was "successful " and non
zero otherwise. I a compiler finds an error, it is expected that the
return status is "1". For example, in the "sendmail" the mail system,
if the program has a "temporary" error, the return status should be "75"
or sometimes termed EX_TEMPFAIL.

see:
http://www.google.com/codesearch?q=+...ude/exits.h#a0

You almost never have to worry about anything other than "0" - success,
or "1" failure.
Oct 31 '06 #3
arnuld wrote:
1.) we usually say /return 0/ indicates success e.g

#include <iostream>

int main() {
int i=3;

std::cout << i << std::endl;

return 0;
}
i ran the programme & i see only /3/ as output. i dont see any /0/ on
my terminal. where does it go? & who reads /0/ to indicate success?
<OT>
Your command shell took it. Usually you'll have an OS-specific
means to check the return value, e.g. in a bash shell under
linux you may try, assuming your program executable is named a.out

#!/bin/bash
../a.out
echo "The return value is $?"

</OT>

HTH,
- J.
Oct 31 '06 #4
Gianni Mariani wrote:

If you executed your program from the std::system function call then
the value is partly returned by the system call. If the return value
from system() is negative then there was an error, otherwise the
lower 8 bits are the lower 8 bits returned from main often termed the
"status".
There is no such requirement for the system() function. From the C99
draft standard:

7.20.4.5 The system function

Synopsis

[#1]

#include <stdlib.h>
int system(const char *string);

Description

[#2] If string is a null pointer, the system function
determines whether the host environment has a command
processor. If string is not a null pointer, the system
function passes the string pointed to by string to that
command processor to be executed in a manner which the
implementation shall document; this might then cause the
program calling system to behave in a non-conforming manner
or to terminate.

Returns

[#3] If the argument is a null pointer, the system function
returns nonzero only if a command processor is available.
If the argument is not a null pointer, and the system
function does return, it returns an implementation-defined
value.

Brian
Oct 31 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1978
by: Nat | last post by:
Hi there, I have code as following but it returns error Error Type: Microsoft VBScript compilation (0x800A03F6) Expected 'End' /urbisjhdintranet/metadata/resultList.asp, line 324 which is the second last line at the end of the code. I have no idea where to put 'end'. It would be great if anyone could help. Thanks heaps! Nat
4
1974
by: Barry Edmund Wright | last post by:
I would really appreciate your assistance. I am using Access 2000 to create a form that Lists Names and Addresses based on a number of selection criteria one of which is a combo box cboPCZip. All the selection criteria are used to build a Where clause (strWhere1). If optBeginsContains = 1 Then 'Return records Beginning with the value in cboPCZip strWhere1 = strWhere1 & " And ((tblAddress.strPCZip) like """ & cboPCZip & "*"")"
25
1528
by: Nikola | last post by:
compiler says: function undeclared how come??? help! #include<stdio.h> #include<stdlib.h> #include<time.h> struct lista{ int element; struct lista *next; }*pocetak;
14
2332
by: Stegano | last post by:
I am learning C Programming after working with Java for 5 years. I want to know where can I find the source files for C language itself. For example strcat is a function, which concatenates two strings. I want to read how this function is implemented in its native form, where can I find its corresponding .c file. I am using gcc version 3.3.1 (Thread model POSIX) on cygwin with Eclipse IDE. A grep on a function name lists many .h and .c...
0
4632
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object class (Object.cs in rotor). What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What I don't understand is:
4
3804
by: Brian Shannon | last post by:
I have 3 combo boxes and two date text boxes on a .aspx page. The user can fill in any of the 5 controls or none to filter a datagrid. I was hoping someone could explain how to efficiently build the where clause of a sql string to send to SQL 2000 for a data set. Currenly I check each control with an IF statement to determine if something is filled in. If there is I begin building the where clause. Below is what I have done (and it...
10
4266
by: Paul Cheetham | last post by:
Hi, I am developing an application that needs to store some machine-specific settings. The application is going to be published on the network in order to keep the clients on the latest version. Because of this, I am unable to store these settings in the App.Config file, as this gets updated every time the application does, and there doesn't appear to be a way of preventing this. Most of my application settings are kept in the...
40
3654
by: Spiros Bousbouras | last post by:
Do you have an example of an implementation where sizeof(short int) does not divide sizeof(int) or sizeof(int) does not divide sizeof(long int) or sizeof(long int) does not divide sizeof(long long int) ? Same question for the corresponding unsigned types.
9
3720
by: DanielJohnson | last post by:
I am wondering where does the value returned by main goes. Suppoes main returns some number say 42, where is it stored. Supposed a shell script call a C program and the program returns the value 42 where is this value stored in memory ?
0
9303
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9117
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7078
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4955
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3651
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3141
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.