473,498 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what is the differrence b/w the usage or return and the exit in the C programming..

hi all,
what is the differrence b/w the usage or return and the exit in the C
programming..

thanks,
jay

Nov 2 '07 #1
16 1626
jayapal wrote:
hi all,
what is the differrence b/w the usage or return and the exit in the C
programming..
Within main(), not a lot.

Within any other function, return ends the execution of the function
immediately and returns to the caller, possibly also returning a value.
exit() terminates the program.

--
Philip Potter pgp <atdoc.ic.ac.uk
Nov 2 '07 #2
On Nov 2, 1:48 pm, jayapal <jayapal...@gmail.comwrote:
hi all,
what is the differrence b/w the usage or return and the exit in the C
programming..

thanks,
jay
exit is a function call return is a language keyword apart from many
other differences.

Nov 2 '07 #3
jayapal wrote:
hi all,
what is the differrence b/w the usage or return and the exit in the C
programming..
In C return is a keyword while exit() is a Standard library function.
exit() accepts as argument a value of type int while return can
supplied an expression yielding a value of any legal type. exit()
causes termination of the program while return merely returns control
to the function's caller. A special case is a return in main() which is
roughly equivalent to an exit() call. exit() calls the functions
registered with atexit() while for return this is only true when in
main().

Use exit() when you want to terminate normally from anywhere in the
program. Use return for returning control to the function's caller.

<http://www.c-faq.com/>
<http://www.eskimo.com/~scs/cclass/>
<http://clc-wiki.net/>
<http://cprog.tomsweb.net/>

Nov 2 '07 #4
Philip Potter wrote, On 02/11/07 09:09:
jayapal wrote:
>hi all,
what is the differrence b/w the usage or return and the exit in the C
programming..

Within main(), not a lot.
Why do people always forget about recursive calls to main? ;-)
Within any other function, return ends the execution of the function
immediately and returns to the caller, possibly also returning a value.
exit() terminates the program.
exit() does not always terminate the program...

#include <stdlib.h>

void foo(void)
{
for (;;) continue;
}

int main(void)
{
atexit(foo);
exit(0);
}
--
Flash Gordon
A revolting pedant.
Nov 2 '07 #5
In article <fg**********@aioe.org>, santosh <sa*********@gmail.comwrote:
>jayapal wrote:
>hi all,
what is the differrence b/w the usage or return and the exit in the C
programming..

In C return is a keyword while exit() is a Standard library function.
exit() accepts as argument a value of type int while return can
supplied an expression yielding a value of any legal type. exit()
causes termination of the program while return merely returns control
to the function's caller. A special case is a return in main() which is
roughly equivalent to an exit() call. exit() calls the functions
registered with atexit() while for return this is only true when in
main().

Use exit() when you want to terminate normally from anywhere in the
program. Use return for returning control to the function's caller.

<http://www.c-faq.com/>
<http://www.eskimo.com/~scs/cclass/>
<http://clc-wiki.net/>
<http://cprog.tomsweb.net/>
Next question:
what is the differrence b/w the usage of [the] printf and the gets in the C
programming..?

Nov 2 '07 #6
Kenny McCormack wrote:
Next question:
what is the differrence b/w the usage of [the] printf and the gets in the C
programming..?
What is b/w? Black and white?

What is the difference b/w a deposit and a withdrawal?

Printf prints a formatted string to a standard output, gets reads a
string from a standard input. Do not use gets, as it provides absolutely
no control against buffer overflow. Use fgets instead.
Nov 2 '07 #7
Peter Pichler <us****@pichler.co.ukwrites:
Kenny McCormack wrote:
[...]
What is b/w? Black and white?

What is the difference b/w a deposit and a withdrawal?

Printf prints a formatted string to a standard output, gets reads a
string from a standard input. Do not use gets, as it provides
absolutely no control against buffer overflow. Use fgets instead.
Please don't feed the troll.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 3 '07 #8
Flash Gordon wrote:
Philip Potter wrote, On 02/11/07 09:09:
>jayapal wrote:
>>hi all,
what is the differrence b/w the usage or return and the exit in the C
programming..

Within main(), not a lot.

Why do people always forget about recursive calls to main? ;-)
Because they're usually a bad idea?

(Er, nice catch.)
>Within any other function, return ends the execution of the function
immediately and returns to the caller, possibly also returning a
value. exit() terminates the program.

exit() does not always terminate the program...

#include <stdlib.h>

void foo(void)
{
for (;;) continue;
}

int main(void)
{
atexit(foo);
exit(0);
}
Perhaps, but I'm quite glad I missed this special case out of my
original answer :)

--
Philip Potter pgp <atdoc.ic.ac.uk
Nov 3 '07 #9
Philip Potter wrote, On 03/11/07 09:54:
Flash Gordon wrote:
>Philip Potter wrote, On 02/11/07 09:09:
>>jayapal wrote:
hi all,
what is the differrence b/w the usage or return and the exit in the C
programming..

Within main(), not a lot.

Why do people always forget about recursive calls to main? ;-)

Because they're usually a bad idea?
I agree that they are a bad idea.
(Er, nice catch.)
>>Within any other function, return ends the execution of the function
immediately and returns to the caller, possibly also returning a
value. exit() terminates the program.

exit() does not always terminate the program...
<snip example>
Perhaps, but I'm quite glad I missed this special case out of my
original answer :)
Whenever anything is stated as an absolute truth someone, sometime, will
find an exception that proves that it is not absolute.
--
Flash Gordon
Making absolute statements that someone will now have to find exceptions to.
Nov 3 '07 #10
jayapal wrote:
hi all,
what is the differrence b/w the usage or return and the exit in the C
programming..
After the initial call to the main function, those two are equivalent
(assuming same value), except for one little detail, the exit(N) call
doesn't end lifetime of objects with automatic storage duration declared
in main.

To illustrate, TC2 gives this example as UB:

#include <stdio.h>
#include <stdlib.h>

void goodbye(void)
{
printf("Hello, World!\n");
}

int main(void)
{
char buf[20];
setvbuf(stdout, buf, _IOFBF, sizeof(buf));
atexit(goodbye);
return 0;
}

while replacing "return 0" with exit(0) above, gives a strictly
conforming program.
--
Tor <bw****@wvtqvm.vw | tr i-za-h a-z>
Nov 3 '07 #11
Flash Gordon wrote:
Philip Potter wrote, On 03/11/07 09:54:
>Flash Gordon wrote:
>>Philip Potter wrote, On 02/11/07 09:09:
jayapal wrote:
hi all,
what is the differrence b/w the usage or return and the exit in the C
programming..

Within main(), not a lot.

Why do people always forget about recursive calls to main? ;-)

Because they're usually a bad idea?

I agree that they are a bad idea.
>(Er, nice catch.)
>>>Within any other function, return ends the execution of the function
immediately and returns to the caller, possibly also returning a
value. exit() terminates the program.

exit() does not always terminate the program...

<snip example>
>Perhaps, but I'm quite glad I missed this special case out of my
original answer :)

Whenever anything is stated as an absolute truth someone, sometime, will
find an exception that proves that it is not absolute.
But it is more educationally sound to start with simple truths and only
mention the exceptions to those truths later on, than to find one cannot
define exit() without also defining atexit().

--
Philip Potter pgp <atdoc.ic.ac.uk
Nov 4 '07 #12
Philip Potter wrote, On 04/11/07 08:44:
Flash Gordon wrote:
>Philip Potter wrote, On 03/11/07 09:54:
>>Flash Gordon wrote:
Philip Potter wrote, On 02/11/07 09:09:
jayapal wrote:
<snip>
>>Perhaps, but I'm quite glad I missed this special case out of my
original answer :)

Whenever anything is stated as an absolute truth someone, sometime,
will find an exception that proves that it is not absolute.

But it is more educationally sound to start with simple truths and only
mention the exceptions to those truths later on, than to find one cannot
define exit() without also defining atexit().
Which is what we did.
--
Flash Gordon
Nov 4 '07 #13
Flash Gordon wrote:
Philip Potter wrote, On 04/11/07 08:44:
>But it is more educationally sound to start with simple truths and
only mention the exceptions to those truths later on, than to find one
cannot define exit() without also defining atexit().

Which is what we did.
Er.. I was working from the assumption that you were saying that I
should have mentioned atexit() from the beginning, but looking back on
the thread, it seems this is not the case.

--
Philip Potter pgp <atdoc.ic.ac.uk
Nov 4 '07 #14
Philip Potter wrote, On 04/11/07 16:26:
Flash Gordon wrote:
>Philip Potter wrote, On 04/11/07 08:44:
>>But it is more educationally sound to start with simple truths and
only mention the exceptions to those truths later on, than to find
one cannot define exit() without also defining atexit().

Which is what we did.

Er.. I was working from the assumption that you were saying that I
should have mentioned atexit() from the beginning, but looking back on
the thread, it seems this is not the case.
No, I was just being a pedantic awkward sod as was indicated in my sigs.
--
Flash Gordon
Nov 4 '07 #15
"Flash Gordon" <sp**@flash-gordon.me.uka écrit dans le message de news:
ph************@news.flash-gordon.me.uk...
Philip Potter wrote, On 03/11/07 09:54:
>Flash Gordon wrote:
>>Philip Potter wrote, On 02/11/07 09:09:
jayapal wrote:
hi all,
what is the differrence b/w the usage or return and the exit in the C
programming..

Within main(), not a lot.

Why do people always forget about recursive calls to main? ;-)

Because they're usually a bad idea?

I agree that they are a bad idea.
Not as bad as calling main from a function registered with atexit ;-)
>(Er, nice catch.)
>>>Within any other function, return ends the execution of the function
immediately and returns to the caller, possibly also returning a value.
exit() terminates the program.

exit() does not always terminate the program...

<snip example>
>Perhaps, but I'm quite glad I missed this special case out of my original
answer :)

Whenever anything is stated as an absolute truth someone, sometime, will
find an exception that proves that it is not absolute.
That's typical c.l.c experience, except for qualifiers: here this happens
quickly and usually involves more than one responder.

--
Chqrlie.
Nov 7 '07 #16
Charlie Gordon wrote, On 07/11/07 14:22:
"Flash Gordon" <sp**@flash-gordon.me.uka écrit dans le message de news:
ph************@news.flash-gordon.me.uk...
>Philip Potter wrote, On 03/11/07 09:54:
>>Flash Gordon wrote:
Philip Potter wrote, On 02/11/07 09:09:
jayapal wrote:
>hi all,
>what is the differrence b/w the usage or return and the exit in the C
>programming..
Within main(), not a lot.
Why do people always forget about recursive calls to main? ;-)
Because they're usually a bad idea?
I agree that they are a bad idea.

Not as bad as calling main from a function registered with atexit ;-)
Now you are getting *really* nasty :-)
>>(Er, nice catch.)

Within any other function, return ends the execution of the function
immediately and returns to the caller, possibly also returning a value.
exit() terminates the program.
exit() does not always terminate the program...
<snip example>
>>Perhaps, but I'm quite glad I missed this special case out of my original
answer :)
Whenever anything is stated as an absolute truth someone, sometime, will
find an exception that proves that it is not absolute.

That's typical c.l.c experience, except for qualifiers: here this happens
quickly and usually involves more than one responder.
No, you've made the wrong response, you were meant to provide an
exception my statement! ;-)

Anyway, I think this thread has reached (or passed beyond) the point of
being worth pursuing.
--
Flash Gordon
Nov 7 '07 #17

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

Similar topics

27
2626
by: Maximus | last post by:
Hi, I was just wondering, is it good to use return without arguments in a void function as following: void SetMapLayer() { if( !Map ) return; layer = LAYER_MAP; }
28
3233
by: Madhur | last post by:
Hello what about this nice way to open a file in single line rather than using if and else. #include<stdio.h> void main() { FILE *nd; clrscr();...
2
1367
by: Steven T. Hatton | last post by:
I'm carrying on a discussion in a nother context regarding the value and usefulness of data types. Part of that discussion has to do with how data types might be implemented in the language...
20
3558
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
669
25375
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Languageâ€, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
7
7536
by: Leonel Gayard | last post by:
Hi all, I had to write a small script, and I did it in python instead of shell-script. My script takes some arguments from the command line, like this. import sys args = sys.argv if args ==...
28
3769
by: gnuist006 | last post by:
I have some code like this: (if (test) (exit) (do something)) or (if (test)
7
2890
by: Giancarlo Bassi | last post by:
Please, what are here the 11 include files (found over the internet)? */mozzarella.c /* #include #include #include #include #include #include
14
3372
AmberJain
by: AmberJain | last post by:
HELLO, The title of this thread is my question i.e. What is the differrence between Ubuntu, Kubuntu, Edubuntu, Xubuntu? Plus, Does any other version of ubuntu exist?
0
7208
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...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
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
5464
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
4915
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
4593
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...
0
3095
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...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
292
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.