Results 1 to 3 of 3

Thread: How the controls for the post increment

  1. #1
    Join Date
    Jun 2008
    Location
    India
    Beans
    252
    Distro
    Ubuntu 10.04 Lucid Lynx

    How the controls for the post increment

    #include<stdio.h>
    int main()
    {
    int a=5;
    a=a++ * a++;
    printf("%d",a);
    return 0;
    }


    #include<stdio.h>
    int main()
    {
    int a=5;
    printf("%d",a=(a++ * a++));
    return 0;
    }


    Friends,
    here i get the output 27 and 30 respectively Please may i know how the control goes I can able to understand the first one but How the 2nd one? what is the difference between both of them?
    by
    Visit me
    Click

  2. #2
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,187
    Distro
    Kubuntu

    Re: How the controls for the post increment

    Code:
    #include <stdio.h>
    
    int main(void)
    {
       int a = 5;
       int y = a++ * a++;
    
       printf("a = %d, y = %d\n", a, y);
       return 0;
    }
    Code:
    gcc -Wall foo.c
    foo.c: In function ‘main’:
    foo.c:6: warning: operation on ‘a’ may be undefined
    Thus the final answer: operation on ‘a’ may be undefined

    And because of such, you should not develop code like this.

  3. #3
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: How the controls for the post increment

    heres a little explanation why its undefined:
    http://en.wikipedia.org/wiki/Sequence_point

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •