Problem : 5


#include<stdio.h>

int main ()
{
    int i = 5;
    printf("%d\n", i = ++i == 6);
    return 0;
}

// What's the output ? [Do not execute / run]
// Source : http://www.youngprogrammer.com/
Advertisements

5 thoughts on “Problem : 5

  1. C expression always executes from right to left.
    lets analyze, printf(“%d\n”, i = ++i == 6);
    ++i == 6, will execute first.
    this is a condition which checks, whether ++i is equals to 6
    it is true. becoz, i = 5 and its pre-incremented, i.e value of ‘i’ increases before checking the condition
    so, ++i == 6 returns true. integer value of true = 1
    integer value of false = 0
    that is, left most ‘i’ is initialized to 1

    Correct Output : 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s