Mayur Raikwar
Mayur Raikwar

Reputation: 105

Post Increment Concept in C

Output and Why? As per My knowledge post increment evaluate after the execution of the statement.Here On the left side if logical 'i' value will be 1 or 2?

#include <stdio.h>
int main()
{
    int i = 1;
    if (i++ && (i == 1))
        printf("Yes\n");
    else
        printf("No\n");
}

Upvotes: 1

Views: 77

Answers (2)

ryo33
ryo33

Reputation: 31

The result will be No because i will be incremented immediately after i++ has been evaluated.
Please try i++ * i++ * i++.

Upvotes: -1

haccks
haccks

Reputation: 106122

Here On the left side if logical 'i' value will be 1 or 2?

It will be 2 because there is a sequence point between the evaluation of left and right operand of logical &&.

c-faq defines sequence point as

A sequence point is a point in time at which the dust has settled and all side effects which have been seen so far are guaranteed to be complete.

It means that before evaluating right operand of &&, side effect to i has been guaranteed to be done.

Upvotes: 2

Related Questions