487 views
0 votes
0 votes
what is sequence point? please explain..

1 Answer

Best answer
6 votes
6 votes
I so want to explain this. Consider the following code.
int main()
{
    int i = 4;
    i = i++ + ++i;
    printf("%d",i);
    return 0;
}

In the above code we are trying to update the variable 'i' multiple times within the statements. But in C we have something called as Sequence points where all the side effects are updated.

In the expression ++i, the main effect is the return f the value (i+1) and the side effect is the change of the value at memory location of i. But C doesn't guarantee the update of the side effect until the next sequence point (it can happen anytime before that depending on the compiler implementation). Here, semicolon(;) is a sequence point and we are trying to update the variable thrice before that. So it is compiler dependent on what output we get and in what order the variables are updated.

See this link for more clearity:https://gateoverflow.in/62411/undefined-behaviour-in-c

edited by

Related questions

0 votes
0 votes
0 answers
3
Sanjay Sharma asked Oct 29, 2017
418 views
Assume x,y and z are floating point variables and they have been assigned the values x = 8.8, y = 3.5 and z = - 5.2. The value of arithmetic expression 2*x / (3*y) is A. ...