The Wayback Machine - https://web.archive.org/web/20240723141732/https://www.geeksforgeeks.org/g-fact-20/
Open In App

What is evaluation order of function parameters in C?

Last Updated : 28 May, 2017
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
Report

It is compiler dependent in C. It is never safe to depend on the order of evaluation of side effects. For example, a function call like below may very well behave differently from one compiler to another:




void func (int, int);
    
int i = 2;
func (i++, i++);


There is no guarantee (in either the C or the C++ standard language definitions) that the increments will be evaluated in any particular order. Either increment might happen first. func might get the arguments `2, 3′, or it might get `3, 2′, or even `2, 2′.

Source: http://gcc.gnu.org/onlinedocs/gcc/Non_002dbugs.html



Similar Reads

Evaluation order of operands
Consider the below program. C/C++ Code // C++ implementation #include <bits/stdc++.h> using namespace std; int x = 0; int f1() { x = 5; return x; } int f2() { x = 10; return x; } int main() { int p = f1() + f2(); cout << ("%d ", x); getchar(); return 0; } C/C++ Code #include <stdio.h> int x = 0; int f1() { x = 5; return
3 min read
Why Does C Treat Array Parameters as Pointers?
In C, array parameters are treated as pointers mainly to, To increase the efficiency of codeTo save time It is inefficient to copy the array data in terms of both memory and time; and most of the time, when we pass an array our intention is to just refer to the array we are interested in, not to create a copy of the array. The following two definit
2 min read
Do Not Use sizeof For Array Parameters in C
Using sizeof directly to find the size of arrays can result in an error in the code, as array parameters are treated as pointers. Consider the below program. C/C++ Code // C Program to demonstrate incorrect usage of sizeof() for // arrays #include <stdio.h> void fun(int arr[]) { int i; // sizeof should not be used here to get number // of ele
4 min read
GFact | Does JavaScript guarantee object property order?
There is a quite popular query about whether Java Script guarantees object property order or not. Here, in this article let us know about this famous query in detail. If we create an object for example: var obj = {};obj.prop1 = "Foo";obj.prop2 = "Bar"; Will the resulting object always look like this? { prop1 : "Foo", prop2 : "Bar" } Will the proper
2 min read
Order of operands for logical operators
The order of operands of logical operators &&, || are important in C/C++. In mathematics, logical AND, OR, etc... operations are commutative. The result will not change even if we swap RHS and LHS of the operator. In C/C++ (may be in other languages as well)  even though these operators are commutative, their order is critical. For example
1 min read
Sort Vector of Pairs in descending order in C++
We have discussed some of the cases of sorting vector of pairs in below set 1. Sorting Vector of Pairs in C++ | Set 1 (Sort by first and second) More cases are discussed in this article. Sometimes we require to sort the vector in reverse order. In those instances, rather than first sorting the vector and later using "reverse" function increases the
5 min read
Sorting 2D Vector in C++ | Set 2 (In descending order by row and column)
We have discussed some of the cases of sorting 2D vector in below set 1. Sorting 2D Vector in C++ | Set 1 (By row and column) More cases are discussed in this article Case 3 : To sort a particular row of 2D vector in descending order This type of sorting arranges a selected row of 2D vector in descending order . This is achieved by using “sort()” a
4 min read
Sort Vector of Pairs in ascending order in C++
What is Vector of Pairs? A pair is a container which stores two values mapped to each other, and a vector containing multiple number of such pairs is called a vector of pairs. Syntax: vector<pair<Type1, Type2>> vecName;Here, Type 1: The data type of the first element of the pair.Type 2: The data type of the second element of the pair.ve
5 min read
C Function Arguments and Function Return Values
Prerequisite: Functions in C A function in C can be called either with arguments or without arguments. These functions may or may not return values to the calling functions. All C functions can be called either with arguments or without arguments in a C program. Also, they may or may not return any values. Hence the function prototype of a function
6 min read
Write a one line C function to round floating point numbers
Algorithm: roundNo(num) 1. If num is positive then add 0.5. 2. Else subtract 0.5. 3. Type cast the result to int and return. Example: num = 1.67, (int) num + 0.5 = (int)2.17 = 2 num = -1.67, (int) num - 0.5 = -(int)2.17 = -2 Implementation: /* Program for rounding floating point numbers */ # include<stdio.h> int roundNo(float num) { return nu
1 min read
Article Tags :
three90RightbarBannerImg