C++C++11C++14C++17Introduction to C++Learn C++

Learn to Use Parameters in Functions in C++

In the C++ programming language, we can add functions with many parameters, each parameter may have different types. We can add as many parameters as we want by defining its type and its name to be used inside that function separated with ‘,’ coma. We can shape this usage in the most common syntax to define a function as below,

In the function declaration, the parameters have a clear correspondence to the arguments passed in the function call. So the called values should be in the same type or in a type that can be convertible to the defined parameter type. This is a very simple add function with two a and b integer parameters and its return type is also defined as an integer.

As you see we must define each type of parameter while both are integers. We can use bool, char, int, short int, unsigned short int, long int, unsigned long int, long long int, unsigned long long int, float, double, char, string, structures, objects, pointers, or any other class types as a parameter.  Note that all defined variable names are only available to use inside the function. Avoid using the same names as in the outside of the function, you might have conflicts in usage, this generally happens with mixing general parameters with function parameters. 

We can call this function to set a variable as below,

We can define many multiple variables in different types as below,

We can call this function as below,

As you see here we have four parameters and each has different data type.

Get started building powerful apps with C++Builder!

close

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

Related posts
C++Learn C++Videos

Learn C++ With Monoids, Monads, and Applicative Functors: Repeated Software Patterns (CPPCon 2020) Video

C++Learn C++Videos

Learn C++ With Pipes: How Plumbing Can Make Your C++ More Expressive by Jonathan Boccara (CPPCon 2020) Video

C++Introduction to C++Learn C++

Learn Classes and Objects in C++

C++C++11C++14C++17Introduction to C++Learn C++

Learn about Access Specifiers in C++ Classes

Worth reading...
Learn About Void and Return Type in Functions in C++
en_USEnglish