C or C++

Discussion in 'C' started by KRV, Jul 22, 2013.

  1. KRV

    KRV New Member

    Joined:
    Dec 26, 2011
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    LEARNING
    Location:
    SRI LANKA
    Hi guys does default value for function prototypes are available in C.
    int func(int i=5);

    always give me a error saying there must be ';' ',' or ')' before '='
     
  2. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    I don't believe C has that feature. You could probably use a struct as a hack but you'd still need to pass one in as an argument.

    Code:
    typedef struct
    {
        int def_val;
    } foo;
    
    void bar(foo *t)
    {
        // do something with t->def_val
    }
    
    int main(void)
    {
        foo test = { 5 };
        bar(&test);
        ...
    }
    There's some complicated stuff over at stackoverflow if you're interested in giving that a try.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice