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

Discussion in 'C Programming' started by lovecreatesbeauty, Mar 14, 2005.

  1. 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*/
    }
    lovecreatesbeauty, Mar 14, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Seong-Kook Shin
    Replies:
    1
    Views:
    482
    Richard Bos
    Jun 18, 2004
  2. Greenhorn
    Replies:
    15
    Views:
    800
    Keith Thompson
    Mar 6, 2005
  3. lovecreatesbeauty
    Replies:
    8
    Views:
    572
    Kevin D. Quitt
    Mar 15, 2005
  4. axr0284

    main without a return statement

    axr0284, Nov 7, 2007, in forum: C Programming
    Replies:
    20
    Views:
    682
  5. Jean-Hugues ROBERT
    Replies:
    26
    Views:
    396
    Kristof Bastiaensen
    May 2, 2004
Loading...

Share This Page