Re^2: QuickC
Leif Andrew Rump
leif at ambone.UUCP
Sun Aug 28 01:45:22 AEST 1988
TURGUT at TREARN.BITNET (Turgut Kalfaoglu) writes:
>square(num)
>int num;
>{
> num = num*num;
>}
>OK? There is no 'return' statement in the function. However, it works!
>I get '4' as an answer. So I thought maybe it was keeping the result
>of the last operation, so I added some dummy lines,
>square(num)
>int num;
>{
> int dummy;
> num = num*num;
> dummy=222;
>}
>but the call STILL works... Can anyone shed some light onto this?
>WHY does it work?
My answer has not been tested but I'm quite sure that this is the
right answer to your question:
When you call a function i C the parameters is put on the stack. You
function uses the stack to keep the variable num and when the function
return the result is popped from the stack - which (unfortunately(!)
is the temporary variable num!
Leif Andrew Rump, Ambrasoft A/S, Roejelskaer 15, DK-2840 Holte (Denmark)
UUCP: leif at ambone.dk, phone: +45 2424 111; ABC BBS: +45 68 00 544 (2:505/38)
Please note the node-change: Ambone, Italian for a pulpit
(The following interpretations emerged Am_bone, Ambrasoft A/S bone
when Ambone was put down on paper and Amb_one, Ambrasoft A/S #one
accepted - they are solely mine!!!!!) ...
More information about the Comp.lang.c
mailing list