Thread: Easy question about arguments in a function

  1. #1
    pond-person
    Guest

    Easy question about arguments in a function

    lets say i make a function with 3 arguments:

    myfunction (X,Y,Z);

    in my program i call that function but i only need the middle argument. So would I write this:

    myfunction (,5,) ?? because that gives me errors

    Thanks for any help

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    No you can't. You have to pass all the arguments. If you find for some reason that you don't have to pass all the arguments then you most likely aren't using functions properly or you want a default value to take the missing arguments place.

  3. #3
    pond-person
    Guest
    thanks

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Polymorphic OOP
    No you can't. You have to pass all the arguments. If you find for some reason that you don't have to pass all the arguments then you most likely aren't using functions properly or you want a default value to take the missing arguments place.
    To clarify: You don't have to specify all of the arguments, provided you have default values set in the prototype. However, you must provide all arguments to the left of the last argument you decide to specify.

    To illustrate:

    void myfunction( int x = 0, int y = 1, int z = 2 );

    myfunction( someVar, 10 ); // valid
    myfunction( 20 ); // valid
    myfunction( , 10, 0 ); // invalid


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Yeah, that's why i mentioned default. You are still passing a value to the function, however you are relying on the compiler to do it for you.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Polymorphic OOP
    Yeah, that's why i mentioned default. You are still passing a value to the function, however you are relying on the compiler to do it for you.
    Nod. I just wanted to clarify how it worked in case they didn't know what a default argument was.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  2. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  3. Very easy function call question
    By INFERNO2K in forum C++ Programming
    Replies: 2
    Last Post: 11-04-2005, 08:26 PM
  4. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM