a question

  • Thread starter c/c++ programming lover
  • Start date
C

c/c++ programming lover

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

Juha Nieminen

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

error: lvalue required as increment operand
 
S

Salt_Peter

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.
 
J

Juha Nieminen

Salt_Peter said:
It doesn't matter what the result is. Its undefined behavior.

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

Salt_Peter

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);
 
J

James Kanze

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.
 
A

anon

Salt_Peter said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top