
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Order of evaluation in C++ function parameters
We pass different arguments into some functions. Now one questions may come in our mind, that what the order of evaluation of the function parameters. Is it left to right or right to left?
To check the evaluation order we will use a simple program. Here some parameters are passing. From the output, we can find how they are evaluated.
Example
#include<iostream> using namespace std; void test_function(int x, int y, int z) { cout << "The value of x: " << x << endl; cout << "The value of y: " << y << endl; cout << "The value of z: " << z << endl; } main() { int a = 10; test_function(a++, a++, a++); }
Output
The value of x: 12 The value of y: 11 The value of z: 10
From this output, we can easily understand the evaluation sequence. At first the z is taken, so it is holding 10, then y is taken, so it is 11, and finally, x is taken. So the value is 12.
- Related Articles
- What is evaluation order of function parameters in C?
- Evaluation order of operands in C++
- What are default-parameters for function parameters in JavaScript?
- JavaScript Function Parameters
- Evaluation of Prefix Expressions in C++
- Evaluation of Expression Tree in C++
- Evaluation of Risk in Investments in C++
- What are function parameters in JavaScript?
- Destructuring and function parameters in JavaScript
- Value parameters vs Reference parameters vs Output Parameters in C#
- What are default function parameters in JavaScript?
- Explain the evaluation of expressions of stacks in C language
- Method Parameters in C#
- How can I declare optional function parameters in JavaScript?
- How to pass the parameters in the PowerShell function?

Advertisements