Thread: Default Arguments in C

  1. #1
    Registered User
    Join Date
    Aug 2012

    Default Arguments in C

    #include <stdio.h>
    void func(int a, int b=2)
    int main()
        return 0;
    This code doesn't work in C. Is there a way to have variable b take a default value of 2 in C?

  2. #2
    Registered User
    Join Date
    Jun 2005
    No. Default arguments and function overloading are both specific to C++. There is no equivalent in C.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. default arguments
    By jackson6612 in forum C++ Programming
    Replies: 3
    Last Post: 06-01-2011, 11:57 PM
  2. Default arguments
    By swgh in forum C Programming
    Replies: 5
    Last Post: 06-29-2007, 06:27 PM
  3. default Arguments
    By kishore in forum C++ Programming
    Replies: 2
    Last Post: 01-06-2007, 02:17 AM
  4. Default Arguments Question...
    By tinkerbell20 in forum C++ Programming
    Replies: 4
    Last Post: 07-07-2005, 05:27 PM
  5. Default Arguments
    By pianorain in forum C++ Programming
    Replies: 9
    Last Post: 12-20-2002, 08:40 AM