Groups | Search | Server Info | Login | Register


Groups > comp.lang.c.moderated > #493

Re: How to declare a function parameter to be optional?

From GilNajera <gilnajera@gmail.com>
Newsgroups comp.lang.c.moderated
Subject Re: How to declare a function parameter to be optional?
Date 2011-02-09 12:22 -0600
Organization http://groups.google.com
Message-ID <clcm-20110209-0002@plethora.net> (permalink)
References <clcm-20110207-0001@plethora.net>

Show all headers | View raw


Hi!

On 7 feb, 22:58, Pushkar Prasad <pushkar.pra...@live.com> wrote:
> Hello All
>
> Is there a way to ensure that one of the function argument is set as
> optional. So that it is not mandatory for the caller to pass that
> parameter and yet if necessary can be used?

You must set a default value to that parameter when declaring the
function:

void myFunction(int parameter1, int optional_parameter=23);

All non optional parameters must precede the optional ones.

So, when you call myFunction using just one parameter, the second will
take the value of 23.

Hope this helps.
-- 
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.

Back to comp.lang.c.moderated | Previous | NextNext in thread | Find similar


Thread

Re: How to declare a function parameter to be optional? GilNajera <gilnajera@gmail.com> - 2011-02-09 12:22 -0600
  Re: How to declare a function parameter to be optional? Jens <jens.gustedt@gmail.com> - 2011-02-10 21:40 -0600
  Re: How to declare a function parameter to be optional? David RF <davranfor@gmail.com> - 2011-02-10 21:41 -0600

csiph-web