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!


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.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He was born in 1974, Eskisehir-Turkey, started coding in college and graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. He worked as a research assistant at the same university for more than 10 years. He received his MSc and PhD degrees from the same department at the same university. Since 2012, he is the founder and CEO of Esenja LLC Company. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Learn C++Syntax

What Is An Eligible Copy Assignment Operator In C++?

C++C++11C++14C++17C++20Learn C++Syntax

What Is A Trivial Copy Assignment Operator In C++?

C++C++11C++14C++17C++20Learn C++Syntax

What Is Uppercase T in C++ Syntax?

C++C++11C++14C++17Learn C++Syntax

What Is An Implicitly-defined Copy Assignment Operator In C++?

Worth reading...
Learn About C++ Functions