By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,081 Members | 861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,081 IT Pros & Developers. It's quick & easy.

Function return value automatically

P: n/a
hi
this program return value automatically ... how it is possible ..i am
not return any value... but i return correct values
i am using Linux -gcc complier
please tell me what is this
main()
{
int a,b,c,sum;
printf("ENTER ANY THREE NUMBERS :\n");
scanf("%d%d%d",&a,&b,&c);
sum=rAJAsum(a,b,c);
printf("sum = %d\n", sum);
}
calsum(x,y,z)
int x,y,z;
{
int d;
dSD=x+y+z;
}

Output:
--=====
ENTER ANY THREE NUMBERS :
23
23
23
sum = 69

Thanks All
by
Chellappa

Nov 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On 23 Nov 2005 07:26:06 -0800, in comp.lang.c , "chellappa"
<N.*********@gmail.com> wrote:
hi
this program return value automatically ... how it is possible ..i am
not return any value... but i return correct values
By complete chance. You're declaring a function calsum which
implicitly returns an int, and the last value on the stack happens to
be the sum of x,y, and z, so that gets returned. This is random
nonsense.

This is a horrible, horrible programme. It uses a style of C that was
obsoleted more than 15 years ago. Stop doing that, learn proper modern
C.
main()
main should be declared
int main(void) or int main(int, char**)
calsum(x,y,z)
int x,y,z;


This style of declaration is obsolete and possibly even illegl. Please
learn proper C.

int calsum(int x, int y, int z)
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 24 '05 #2

P: n/a
Mark McIntyre <ma**********@spamcop.net> writes:
On 23 Nov 2005 07:26:06 -0800, in comp.lang.c , "chellappa"
<N.*********@gmail.com> wrote:
hi
this program return value automatically ... how it is possible ..i am
not return any value... but i return correct values


By complete chance. You're declaring a function calsum which
implicitly returns an int, and the last value on the stack happens to
be the sum of x,y, and z, so that gets returned. This is random
nonsense.


It's at least equally likely that the value was in a register rather
than on the stack.

As far as the language is concerned, it could as easily have been left
scrawled on a piece of paper shoved into a dictionary next to the
entry for "gullible", which just happens to be where function return
values are stored. Or it could be an amazing coincidence. (Neither
of these is likely, of course.)

But those demons certainly do clear your sinuses on the way out.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 24 '05 #3

P: n/a
chellappa wrote:
hi
this program return value automatically ... how it is possible ..i am
not return any value... but i return correct values
i am using Linux -gcc complier
please tell me what is this


Start to fucking think on your own.

Igmar
Nov 28 '05 #4

P: n/a
On Mon, 28 Nov 2005 10:55:34 +0100, in comp.lang.c , Igmar Palsenberg
<ig***@jdimedia.local> wrote:
chellappa wrote:
hi
this program return value automatically ... how it is possible ..i am
not return any value... but i return correct values
i am using Linux -gcc complier
please tell me what is this


Start to f..king think on your own.


and people complained about me saying bu...
:-)
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 28 '05 #5

P: n/a
Igmar Palsenberg <ig***@jdimedia.local> writes:
chellappa wrote:
hi
this program return value automatically ... how it is possible ..i am
not return any value... but i return correct values
i am using Linux -gcc complier
please tell me what is this


Start to f***ing think on your own.


[edited for content]

First, chellappa's question has already been addressed at length.
Since Usenet is asynchronous, it's possible you haven't been able to
see the other replies, but if you can, please check for other
followups before posting.

Second, 4-letter words don't bother me personally very much, but they
do bother some people, and they're really not necessary. If you feel
the need to dispense some verbal abuse, try to be a bit more creative
about it; it's possible to be insulting without using any words you
wouldn't hear on Sesame Street.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 28 '05 #6

P: n/a
Mark McIntyre said:
On Mon, 28 Nov 2005 10:55:34 +0100, in comp.lang.c , Igmar Palsenberg
<ig***@jdimedia.local> wrote:
Start to [expletive deleted] think on your own.


and people complained about me saying [partial exp. del.!]...


And some people have noticed that you've stopped doing so, and are not
unappreciative.

It was worthwhile to complain to you, since I know you are bright enough to
understand the point. (Foul-mouthed non-regs simply get plonked without
notice; it's a cost-benefit trade-off!)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 28 '05 #7

P: n/a
Mark McIntyre wrote:
On Mon, 28 Nov 2005 10:55:34 +0100, in comp.lang.c , Igmar Palsenberg
<ig***@jdimedia.local> wrote:

Start to f..king think on your own.


and people complained about me saying bu...


"Butter"?

Brian

Nov 29 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.