answersLogoWhite

0


Best Answer

Default arguments are function parameters for which a default value is implied when not explicitly stated.

int foo(int x, int base=10 ) {

return( x%base); }

The above function assumes 'base' is 10 unless you specify otherwise when making the call. Thus calling foo(15) will return 5, as will foo(5,10), but foo(15,16) will return 15.

Note that default parameters must appear after all non-default parameters in a function declaration. Once you specify a default parameter, all other parameters that follow must also have default values.

Note also that when the definition of a function is split from its declaration, only the declaration should declare the default parameters:

// Declaration:

int foo(int x, int base=10 );

// Definition:

int foo(int x, int base ) {

return( x%base); }

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are default arguments in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are default arguments in c?

Nothing.


What parameter to a function is one for which an automatic value is supplied if do not explicitly use one in C programming?

You are referring to default arguments. However, C does not support default arguments. That's a C++ feature.


What is default value of formal arguments?

In C, there is no default value for formal parameters. In C++, there can be, but the value is whatever you declare in the function declaration.


Which is the default parameter passing technique in c plus plus language?

The default is to pass by value.


What is the default access specifier in C plus plus?

private


What is the difference between implicit and explicit call of constructor in c plus plus?

An implicit constructor call will always call the default constructor, whereas explicit constructor calls allow to chose the best constructor and passing of arguments into the constructor.


How is the default constructor equivalent to a constructor having default arguments?

Any constructor that can be invoked without explicitly passing any arguments is a default constructor. Note that there can be only one default constructor so there can only be one constructor where all arguments have default values or one constructor that has no arguments, but not both. A constructor where all arguments have default values is a useful means of combining two or more constructors into a single default constructor, thus reducing verbosity and code duplication.


What are the different parameter passing methods used by c plus plus?

Pass by value, constant value, reference and constant reference. Pass by value is the default in C++ (pass by reference is the default in Java).


What is default name of c plus plus?

If you mean the original name of C++, it was originally called "C with Classes". However, after the introduction of template metaprogramming, it was renamed C++ which meant "the successor to C".


How will you pass arguments to a function in c plus plus?

If you have this function: int add(int x, int y) { return x + y; } you would pass the arguments when calling the function in the () like this: add(4, 7); 4 & 7 would be the arguments.


What do you mean by default arguments. How do you delare them?

Gand mrao


Does your computer have visual basic c plus plus?

Basic and C++ are two different languages. You can have them both, but you need to install them. By default Windows OSes do not have it. When Linux based have an option to install C++ compiler.