How do you define an argument for a function such that the argument is
optional and has a default value assigned to it? I am sorry but I am
having memory lapses. 7 1402
Sathyaish wrote: How do you define an argument for a function such that the argument is optional and has a default value assigned to it? I am sorry but I am having memory lapses.
You use some other language with that capability, such as Ada.
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Sathyaish wrote: How do you define an argument for a function such that the argument is optional and has a default value assigned to it? I am sorry but I am having memory lapses.
int funcDefArgs(int a, int b = 4);
Remember to provide the default arguments only at the time of the decl.
of the function and **not** at definition.
Also, the rightmost arguments can be default. Soo, while 1. is wrong, 2
is prefectly fine.
1. int funcDefArgs(int a, int b = 4, int c);
2. int funcDefArgs(int a, int b = 3, int c = 2);
Try going to a pharmacist and ask for memory plus capsules. It might
help ;)
Jaspreet wrote: Sathyaish wrote:
How do you define an argument for a function such that the argument is optional and has a default value assigned to it? I am sorry but I am having memory lapses.
int funcDefArgs(int a, int b = 4);
Remember to provide the default arguments only at the time of the decl. of the function and **not** at definition.
Also, the rightmost arguments can be default. Soo, while 1. is wrong, 2 is prefectly fine.
1. int funcDefArgs(int a, int b = 4, int c); 2. int funcDefArgs(int a, int b = 3, int c = 2);
Try going to a pharmacist and ask for memory plus capsules. It might help ;)
And of course, this is a solution only for _Not_C_Language_.
It might be C++ but I cannot remember when in comp.lang.c;
comp.lang.c++ might know.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Michael Mair wrote: Jaspreet wrote: Sathyaish wrote:
How do you define an argument for a function such that the argument is optional and has a default value assigned to it? I am sorry but I am having memory lapses.
int funcDefArgs(int a, int b = 4);
Remember to provide the default arguments only at the time of the decl. of the function and **not** at definition.
Also, the rightmost arguments can be default. Soo, while 1. is wrong, 2 is prefectly fine.
1. int funcDefArgs(int a, int b = 4, int c); 2. int funcDefArgs(int a, int b = 3, int c = 2);
Try going to a pharmacist and ask for memory plus capsules. It might help ;)
And of course, this is a solution only for _Not_C_Language_. It might be C++ but I cannot remember when in comp.lang.c; comp.lang.c++ might know.
Cheers Michael
Sorry but I did not get that.
Jaspreet wrote: Michael Mair wrote:
Jaspreet wrote:
Sathyaish wrote:
How do you define an argument for a function such that the argument is optional and has a default value assigned to it? I am sorry but I am having memory lapses.
int funcDefArgs(int a, int b = 4);
Remember to provide the default arguments only at the time of the decl. of the function and **not** at definition.
Also, the rightmost arguments can be default. Soo, while 1. is wrong, 2 is prefectly fine.
1. int funcDefArgs(int a, int b = 4, int c); 2. int funcDefArgs(int a, int b = 3, int c = 2);
Try going to a pharmacist and ask for memory plus capsules. It might help ;)
And of course, this is a solution only for _Not_C_Language_. It might be C++ but I cannot remember when in comp.lang.c; comp.lang.c++ might know.
Cheers Michael
Sorry but I did not get that.
Sorry, my fault:
The short of it is that this is not possible in C, only in C++,
so your answer is wrong.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Michael Mair wrote:
[snip] Sorry, my fault: The short of it is that this is not possible in C, only in C++, so your answer is wrong.
Cheers Michael -- E-Mail: Mine is an /at/ gmx /dot/ de address.
Ah!! Yup apologies for posting a wrong solution.
On 26 Jun 2005 22:22:50 -0700, "Jaspreet" <js***********@gmail.com>
wrote: Sathyaish wrote: How do you define an argument for a function such that the argument is optional and has a default value assigned to it? I am sorry but I am having memory lapses. int funcDefArgs(int a, int b = 4);
Remember to provide the default arguments only at the time of the decl. of the function and **not** at definition.
Also, the rightmost arguments can be default. Soo, while 1. is wrong, 2 is prefectly fine.
1. int funcDefArgs(int a, int b = 4, int c); 2. int funcDefArgs(int a, int b = 3, int c = 2);
You need quotes around each of the arguments, like "int b = 4", and
don't forget that the prototype has to be something like
int funcDelArgs( char *s1, char *s2, char * s3);
Try going to a pharmacist and ask for memory plus capsules. It might help ;)
--
Al Balmer
Balmer Consulting re************************@att.net This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: J.R. |
last post by:
Hi folks,
The python can only support passing value in function call (right?), I'm
wondering how to effectively pass a large parameter, such as a large list or
dictionary?
It could achieved...
|
by: Edward Diener |
last post by:
In the tutorial on functions there are sections on default arguments and
keyword arguments, yet I don't see the syntactic difference between them.
For default arguments the tutorial shows:
def...
|
by: Agent Mulder |
last post by:
Hi group,
I want to know why this doesn't work
void f(int a=0,int b=1,int c=2){}
int main()
{
f(); //OK
f(1); //OK
f(1,2); //OK
f(1,2,3); //OK
|
by: earl |
last post by:
class temp
{
public:
temp();
foo(char, char, char*);
private:
char matrix;
};
temp::foo(char p, char o, char m = matrix )
|
by: Dan Cernat |
last post by:
Hi there,
A few threads I had a little chat about default values. I am starting this
thread because I want to hear more opinions about the default values of
function parameters. Some say they...
|
by: Matt |
last post by:
I try to compare the default constructor in Java and C++.
In C++, a default constructor has one of the two meansings
1) a constructor has ZERO parameter
Student()
{ //etc...
}
2) a...
|
by: aling |
last post by:
What's the rule of default argument of function in C++? I found that
the default argument of function could not necessary be a constant
value. Is it true? Previously I thought that the default...
|
by: Alan G Isaac |
last post by:
My class MyClass reuses many default parameters
with a small number of changes in each instance.
For various reasons I decided to put all the
parameters in a separate Params class, instances
of...
|
by: claudiu |
last post by:
Hi,
I'll go straight to the first question. Why does the code below
compile?
void f(int i = 0);
int main()
{
(&f)();
|
by: bukzor |
last post by:
I've found some bizzare behavior when using mutable values (lists,
dicts, etc) as the default argument of a function. I want to get the
community's feedback on this. It's easiest to explain with...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |