Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > a question

Reply
Thread Tools

a question

 
 
c/c++ programming lover
Guest
Posts: n/a
 
      11-07-2008
Could anyone tell me why the result is that:
printf("%d",++5*++5);
the result is 49?
thanks
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      11-07-2008
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
 
Reply With Quote
 
 
 
 
Salt_Peter
Guest
Posts: n/a
 
      11-07-2008
On Nov 7, 4:20 am, "c/c++ programming lover" <(E-Mail Removed)> 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.
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      11-07-2008
Salt_Peter wrote:
> On Nov 7, 4:20 am, "c/c++ programming lover" <(E-Mail Removed)> 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"?
 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      11-07-2008
On Nov 7, 5:49 pm, Juha Nieminen <(E-Mail Removed)> wrote:
> Salt_Peter wrote:
> > On Nov 7, 4:20 am, "c/c++ programming lover" <(E-Mail Removed)> 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);
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      11-08-2008
On Nov 7, 11:49*pm, Juha Nieminen <(E-Mail Removed)> wrote:
> Salt_Peter wrote:
> > On Nov 7, 4:20 am, "c/c++ programming lover" <(E-Mail Removed)> 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:(E-Mail Removed)
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
 
Reply With Quote
 
anon
Guest
Posts: n/a
 
      11-10-2008
Salt_Peter wrote:
> On Nov 7, 5:49 pm, Juha Nieminen <(E-Mail Removed)> wrote:
>> Salt_Peter wrote:
>>> On Nov 7, 4:20 am, "c/c++ programming lover" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments