Is the following undefined behavior

Discussion in 'C Programming' started by Chad, Feb 21, 2011.

  1. Chad

    Chad Guest

    Given the following...

    #include <stdio.h>

    int main(void)
    {
    int i = 7;
    int j = 7;

    int k = i++ + ++i;
    int l = ++j + j++;

    printf("k is: %d\n", k);
    printf("l is: %d\n", l);

    return 0;
    }

    I get..

    k is: 16
    l is: 16
     
    Chad, Feb 21, 2011
    #1
    1. Advertising

  2. Chad <> writes:
    > Given the following...

    [...]
    > int k = i++ + ++i;
    > int l = ++j + j++;


    Undefined behavior. Read section 3 of the comp.lang.c FAQ,
    <http://www.c-faq.com/>; 3.2 is particularly relevant.

    [...]
    > I get..

    [...]

    It doesn't matter what you get.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Feb 21, 2011
    #2
    1. Advertising

  3. Chad

    Eric Sosman Guest

    On 2/21/2011 4:11 PM, Chad wrote:
    > Given the following...
    >
    > #include<stdio.h>
    >
    > int main(void)
    > {
    > int i = 7;
    > int j = 7;
    >
    > int k = i++ + ++i;


    Undefined behavior.

    > int l = ++j + j++;


    Undefined behavior (if the program gets this far).

    > printf("k is: %d\n", k);
    > printf("l is: %d\n", l);
    >
    > return 0;
    > }
    >
    > I get..
    >
    > k is: 16
    > l is: 16


    (Shrug.)

    --
    Eric Sosman
    d
     
    Eric Sosman, Feb 21, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mantorok Redgormor
    Replies:
    70
    Views:
    1,843
    Dan Pop
    Feb 17, 2004
  2. Neroku
    Replies:
    12
    Views:
    558
    Flash Gordon
    Feb 12, 2007
  3. grocery_stocker
    Replies:
    7
    Views:
    245
  4. VK
    Replies:
    45
    Views:
    664
    Dr John Stockton
    Sep 12, 2006
  5. Wake up Brazil
    Replies:
    10
    Views:
    148
    Öö Tiib
    Apr 16, 2014
Loading...

Share This Page