Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > A value returned to a function without a `return' statement?

Thread Tools

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

Posts: n/a
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.


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

The code I write is:


#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_


#include "highdigit.h"

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

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

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the function to evaluate code object returned byPyParser _SimpleParseString function? Borse, Ganesh Python 0 11-15-2007 09:15 AM
assigning reference to a returned value from function. C++ 12 08-10-2006 06:33 AM
value returned from a function C Programming 9 08-04-2006 09:15 PM
A value returned to a function without a `return' statement, why? lovecreatesbeauty C Programming 8 03-15-2005 08:00 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM