A value returned to a function without a `return' statement?

L

lovecreatesbeauty

I ever missed a `return' statement when write a function `int
HighDigit(Num)' to get the highest digit of an integer.

But even if the `return' statement is ignored the function still can
obtain an `correct' return value when the argument `Num' is larger than
or equal to the Macro `NUM_SYS'.

If the argument is less than the Macro, the function without a `return'
get an undefined value. I've made a test on Ms Windows 2000 and VC 6.


Thank you in advance for explaining why.

And would you please comment on this algorithm? Thank you.




i.e.

Num HighDigit(Num)
============================
123 | 1
321 | 3
2 | 2
10 | 1
____________________________





The code I write is:


//highdigit.h

#ifndef _HIGH_DIGIT_H_
#define _HIGH_DIGIT_H_

#define NUM_SYS 10 //number system, decimal assumed as default

int HighDigit(int Num);

#endif //_HIGH_DIGIT_H_


//highdigit.c

#include "highdigit.h"

int HighDigit(int Num){
while (Num >= NUM_SYS){
Num /= NUM_SYS;
}

//return Num; /*This statement be missed by me at first*/
}
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top