473,513 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hi i am a computer science graduate.....

17 New Member
hi i wana know about the return type of main( ) in c.
where is it returned ... and can we print the value anyhow.,
Feb 20 '07 #1
15 1900
Frinavale
9,735 Recognized Expert Moderator Expert
hi i wana know about the return type of main( ) in c.
where is it returned ... and can we print the value anyhow.,
Hi there,

The return value is returned to the Operating System when your program finishes.
It is used to indicate if something went wrong.

This return value is very useful for stuff like Bash Scripting in Linux/Unix where you call on a program to do something and depending on whether or not it fails do something.

Welcome to the scripts!

-Frinny
Feb 20 '07 #2
MuraliCoder
4 New Member
To print the value which was returned to Operating System, After u execution of the program u need to give "$?" command at shell.. it will show the value returned to OS.
Feb 21 '07 #3
RedSon
5,000 Recognized Expert Expert
hi i wana know about the return type of main( ) in c.
where is it returned ... and can we print the value anyhow.,
When did you graduate?
Feb 21 '07 #4
debisupi2007
1 New Member
hi i wana know about the return type of main( ) in c.
where is it returned ... and can we print the value anyhow.,
Hi,
The main() can return any type of value you want like. It returns it value to the command prompt from where generally u execute the .exe file. The main() generally carry two types of argument one of which is numeric and otherone is character type.
Feb 21 '07 #5
Motoma
3,237 Recognized Expert Specialist
hi i wana know about the return type of main( ) in c.
where is it returned ... and can we print the value anyhow.,
The return value is given to whatever program started the executable. In shell scripting it would be the script, if you called it from inside another program, the program would recieve the returned value at the end of execution.
You can use this in scripting and programming to determin the execution flow of the program without having to do STDOUT redirection and analysis, as well as determing the final condition of the program.
Feb 21 '07 #6
majidmajid
17 New Member
plz guide me ...
i am coding in turbo c.
i wrote command "$?" at dos prompt...
but it doesnt recognize the command.. and plz send the details.
i hve to print the return type of main anyhow..
thnks
Feb 23 '07 #7
Motoma
3,237 Recognized Expert Specialist
In Windows, the variable is errorlevel, not $?.
You can use it on the command line as %errorlevel%, and in batch scripts as errorlevel.
Feb 23 '07 #8
uppili
26 New Member
can you compar the main and the function
Feb 23 '07 #9
uppili
26 New Member
mr. majidmajid



if you are very new to program then take tot and type one program and try to understand the statment and try to impliment it by your own. then you get nice kwl.
Feb 23 '07 #10
uppili
26 New Member
mr.majidmajid
display your code

it will be easy to guid you
Feb 23 '07 #11
bitong
40 New Member
question: what's the difference between return(0) and return value?
Feb 23 '07 #12
Motoma
3,237 Recognized Expert Specialist
question: what's the difference between return(0) and return value?
Example:
Program A runs. It does a return 0 for success, a return 1 for "invalid filename", and returns 2 for "invalid username"
Program B launches Program A:
Expand|Select|Wrap|Line Numbers
  1. int returnValue = exec("progA");
  2. switch(returnValue)
  3. {
  4.   case 2:
  5.      // invalid username
  6.   case 1:
  7.      // invalid filename
  8.   case 0:
  9.      // returns correctly
  10. }
  11.  
Does this make sense to you?
Feb 23 '07 #13
uppili
26 New Member
y we want to return the value for function
Feb 25 '07 #14
Frinavale
9,735 Recognized Expert Moderator Expert
y we want to return the value for function
The main()'s return value is used by the calling program to determine how the program ended. This could be your operating system or it could be another script or program.

Example:

Program 1
Say we create a program which returns "1" in the case where it encountered an internal error and couldn't complete its processing...and in the case where it doesn't encounter an error and it's able to complete, we return "0".

Program 2
Say we create another program that calls our first program and displays an error message if our first program crashed and displays a "thank you" message if our first program didn't crash.

This program would use the value returned by your main() to determine which message to display.

Does this make sense?

-Frinny
Feb 26 '07 #15
RedSon
5,000 Recognized Expert Expert
Example:
Program A runs. It does a return 0 for success, a return 1 for "invalid filename", and returns 2 for "invalid username"
Program B launches Program A:
Expand|Select|Wrap|Line Numbers
  1. int returnValue = exec("progA");
  2. switch(returnValue)
  3. {
  4.   case 2:
  5.      // invalid username
  6.   case 1:
  7.      // invalid filename
  8.   case 0:
  9.      // returns correctly
  10. }
  11.  
Does this make sense to you?
Don't forget your break; s or you will be returning correctly every time.
Feb 26 '07 #16

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

Similar topics

0
1756
by: Markis Landis Gardner | last post by:
I am wanting to take a research class in Graduate School. My professor said he would be willing to work with me, but I had to come up with the idea. Since I know VERY little about Java, I was...
25
3018
by: tnrABC | last post by:
The approximately 100 books below are for sale. Mostly a selection of mathematics (numerical analysis mostly), computing science (graphics, ai, programming techniques, theory, compilers, operating...
24
1820
by: tnrABC | last post by:
The approximately 100 books below are for sale. Mostly a selection of mathematics (numerical analysis mostly), computing science (graphics, ai, programming techniques, theory, compilers, operating...
0
1960
by: kirby.urner | last post by:
Cyber-curricula have a leveling aspect, as kids nearer Katrina's epicenter tune in and bliss out on 'Warriors of the Net' (why wait for stupid big dummy textbooks to catch up?). They feel more...
0
281
by: kirby.urner | last post by:
Cyber-curricula have a leveling aspect, as kids nearer Katrina's epicenter tune in and bliss out on 'Warriors of the Net' (why wait for stupid big dummy textbooks to catch up?). They feel more...
0
7175
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
7391
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7542
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...
0
5697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5100
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...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1609
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 ...
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.