a question

Discussion in 'C++' started by c/c++ programming lover, Nov 7, 2008.

  1. Could anyone tell me why the result is that:
    printf("%d",++5*++5);
    the result is 49?
    thanks
     
    c/c++ programming lover, Nov 7, 2008
    #1
    1. Advertising

  2. c/c++ programming lover wrote:
    > Could anyone tell me why the result is that:
    > printf("%d",++5*++5);
    > the result is 49?


    error: lvalue required as increment operand
     
    Juha Nieminen, Nov 7, 2008
    #2
    1. Advertising

  3. c/c++ programming lover

    Salt_Peter Guest

    On Nov 7, 4:20 am, "c/c++ programming lover" <> wrote:
    > Could anyone tell me why the result is that:
    > printf("%d",++5*++5);
    > the result is 49?
    > thanks


    It doesn't matter what the result is. Its undefined behavior.
     
    Salt_Peter, Nov 7, 2008
    #3
  4. Salt_Peter wrote:
    > On Nov 7, 4:20 am, "c/c++ programming lover" <> wrote:
    >> Could anyone tell me why the result is that:
    >> printf("%d",++5*++5);
    >> the result is 49?
    >> thanks

    >
    > It doesn't matter what the result is. Its undefined behavior.


    Does the standard really specify a syntax error as "undefined behavior"?
     
    Juha Nieminen, Nov 7, 2008
    #4
  5. c/c++ programming lover

    Salt_Peter Guest

    On Nov 7, 5:49 pm, Juha Nieminen <> wrote:
    > Salt_Peter wrote:
    > > On Nov 7, 4:20 am, "c/c++ programming lover" <> wrote:
    > >> Could anyone tell me why the result is that:
    > >> printf("%d",++5*++5);
    > >> the result is 49?
    > >> thanks

    >
    > > It doesn't matter what the result is. Its undefined behavior.

    >
    > Does the standard really specify a syntax error as "undefined behavior"?


    Its a syntax error, yes, thats the obvious answer. Error or not, the
    OP's intent was to ask what the following might have a guaranteed
    result:

    int n(5);
    printf("%d",++n*++n);
     
    Salt_Peter, Nov 7, 2008
    #5
  6. c/c++ programming lover

    James Kanze Guest

    On Nov 7, 11:49 pm, Juha Nieminen <> wrote:
    > Salt_Peter wrote:
    > > On Nov 7, 4:20 am, "c/c++ programming lover" <> wrote:
    > >> Could anyone tell me why the result is that:
    > >> printf("%d",++5*++5);
    > >> the result is 49?
    > >> thanks


    > > It doesn't matter what the result is. Its undefined
    > > behavior.


    > Does the standard really specify a syntax error as "undefined
    > behavior"?


    It does, actually. The implementation is required to emit a
    diagnostic, but what happens next is undefined behavior.

    In practice, of course, from a QoI point of view, the
    implementation will normally not generate an object file. The
    rule is there to allow the implementation to use ill-formed
    constructs as an extension; once the compiler has output a
    diagnostic (the message "this is an extension", for example),
    it's free to go on and compile the code, assigning any meaning
    it wants to it.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Nov 8, 2008
    #6
  7. c/c++ programming lover

    anon Guest

    Salt_Peter wrote:
    > On Nov 7, 5:49 pm, Juha Nieminen <> wrote:
    >> Salt_Peter wrote:
    >>> On Nov 7, 4:20 am, "c/c++ programming lover" <> wrote:
    >>>> Could anyone tell me why the result is that:
    >>>> printf("%d",++5*++5);
    >>>> the result is 49?
    >>>> thanks
    >>> It doesn't matter what the result is. Its undefined behavior.

    >> Does the standard really specify a syntax error as "undefined behavior"?

    >
    > Its a syntax error, yes, thats the obvious answer. Error or not, the
    > OP's intent was to ask what the following might have a guaranteed
    > result:
    >
    > int n(5);
    > printf("%d",++n*++n);


    Intent or not, what he wrote produces a syntax error.
     
    anon, Nov 10, 2008
    #7
    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. sean
    Replies:
    1
    Views:
    627
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    697
    Iain Norman
    Feb 16, 2005
  3. =?Utf-8?B?YW5kcmV3MDA3?=

    question row filter (more of sql query question)

    =?Utf-8?B?YW5kcmV3MDA3?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    975
    Scott Allen
    Oct 6, 2005
  4. Philip Meyer
    Replies:
    0
    Views:
    447
    Philip Meyer
    Nov 30, 2003
  5. Bit Byte
    Replies:
    1
    Views:
    882
    Teemu Keiski
    Jan 28, 2007
Loading...

Share This Page