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 graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

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

How To Learn The Move Constructors In Modern C++?

C++C++17Code SnippetLearn C++

How To Convert Char Array String To Unicode String Correctly In C++?

Artificial Intelligence TechC++Language FeatureLearn C++

How To Develop A Simple Hopfield Network In C++

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