By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,429 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,429 IT Pros & Developers. It's quick & easy.

a question

P: n/a
Could anyone tell me why the result is that:
printf("%d",++5*++5);
the result is 49?
thanks
Nov 7 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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
Nov 7 '08 #2

P: n/a
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.
Nov 7 '08 #3

P: n/a
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
Nov 7 '08 #4

P: n/a
On Nov 7, 4:20 am, "c/c++ programming lover" <564462...@qq.comwrote:
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.
Nov 7 '08 #5

P: n/a
Salt_Peter wrote:
On Nov 7, 4:20 am, "c/c++ programming lover" <564462...@qq.comwrote:
>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"?
Nov 7 '08 #6

P: n/a
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.comwrote:
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);
Nov 8 '08 #7

P: n/a
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.comwrote:
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:ja*********@gmail.com
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
Nov 8 '08 #8

P: n/a
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.comwrote:
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.
Nov 10 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.