Function return value automatically

C

chellappa

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
 
M

Mark McIntyre

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 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)
 
K

Keith Thompson

Mark McIntyre said:
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.
 
I

Igmar Palsenberg

chellappa said:
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
 
K

Keith Thompson

Igmar Palsenberg said:
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.
 
R

Richard Heathfield

Mark McIntyre said:
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!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top