a question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • c/c++ programming lover

    a question

    Could anyone tell me why the result is that:
    printf("%d",++5 *++5);
    the result is 49?
    thanks
  • Juha Nieminen

    #2
    Re: a question

    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

    Comment

    • blargg

      #3
      Re: a question

      Juha Nieminen wrote:
      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
      Maybe 49 is the error code his compiler gives for such an error.

      Comment

      • Victor Bazarov

        #4
        Re: a question

        blargg wrote:
        Juha Nieminen wrote:
        >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
        >
        Maybe 49 is the error code his compiler gives for such an error.
        I think 'lover' just was asking about

        int a = 5;
        printf("%d", ++a*++a); // prints 49

        Which has undefined behaviour last time I looked.

        V
        --
        Please remove capital 'A's when replying by e-mail
        I do not respond to top-posted replies, please don't ask

        Comment

        • Salt_Peter

          #5
          Re: a question

          On Nov 7, 4:20 am, "c/c++ programming lover" <564462...@qq.c omwrote:
          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.

          Comment

          • Juha Nieminen

            #6
            Re: a question

            Salt_Peter wrote:
            On Nov 7, 4:20 am, "c/c++ programming lover" <564462...@qq.c omwrote:
            >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"?

            Comment

            • Salt_Peter

              #7
              Re: a question

              On Nov 7, 5:49 pm, Juha Nieminen <nos...@thanks. invalidwrote:
              Salt_Peter wrote:
              On Nov 7, 4:20 am, "c/c++ programming lover" <564462...@qq.c omwrote:
              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);

              Comment

              • James Kanze

                #8
                Re: a question

                On Nov 7, 11:49 pm, Juha Nieminen <nos...@thanks. invalidwrote:
                Salt_Peter wrote:
                On Nov 7, 4:20 am, "c/c++ programming lover" <564462...@qq.c omwrote:
                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:james.kan ze@gmail.com
                Conseils en informatique orientée objet/
                Beratung in objektorientier ter Datenverarbeitu ng
                9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                Comment

                • anon

                  #9
                  Re: a question

                  Salt_Peter wrote:
                  On Nov 7, 5:49 pm, Juha Nieminen <nos...@thanks. invalidwrote:
                  >Salt_Peter wrote:
                  >>On Nov 7, 4:20 am, "c/c++ programming lover" <564462...@qq.c omwrote:
                  >>>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.

                  Comment

                  Working...