473,383 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Default arguments

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.

Nov 15 '05 #1
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
Nov 15 '05 #2
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 ;)

Nov 15 '05 #3
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.
Nov 15 '05 #4
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.

Nov 15 '05 #5
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.
Nov 15 '05 #6

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.

Nov 15 '05 #7
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
Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
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...
14
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...
8
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
12
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 )
18
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...
18
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...
4
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...
10
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...
12
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)();
35
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...
0
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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...
0
BarryA
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...
1
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.