GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Feb-2005, 11:39
81k5blzr 81k5blzr is offline
New Member
 
Join Date: Feb 2005
Posts: 2
81k5blzr is on a distinguished road

equivalent expressions


I have the following code:

int a = 1, b = 2, c = 3;
a += b += c += 7;

Is the following code the equivalent expression fully parenthesized:
(a = (a + (b)) = (b + (c)) = (c + 7))

If not please help because I am at a loss. I know that the code simplifies to the following:
a = a + b
b = b + c
c = c + 7

Please help this is a self taught distance course and I am struggling hard since it is my first programming language.
Thanks
  #2  
Old 14-Feb-2005, 12:16
QED's Avatar
QED QED is offline
Member
 
Join Date: Feb 2005
Location: Hudson Valley, NY
Posts: 231
QED is a jewel in the roughQED is a jewel in the roughQED is a jewel in the rough
Quote:
int a = 1, b = 2, c = 3;
a += b += c += 7;

Is the following code the equivalent expression fully parenthesized:
(a = (a + (b)) = (b + (c)) = (c + 7))

If not please help because I am at a loss. I know that the code simplifies to the following:
a = a + b
b = b + c
c = c + 7
Your 3-line simplification is nearly correct, but the order should be reversed because the assignment operators are resolved right-to-left. That is:
CPP / C++ / C Code:
c = c + 7;
b = b + c;
a = a + b;
As for the parenthetical expression, I believe it should be:
CPP / C++ / C Code:
( (a) = (a) + ( (b) = (b) + ( (c) = ( (c) + (7) ) ) ) );

Matthew

(Edited)
  #3  
Old 14-Feb-2005, 13:52
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,310
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by 81k5blzr
I have the following code:

int a = 1, b = 2, c = 3;
a += b += c += 7;

Is the following code the equivalent expression fully parenthesized:
(a = (a + (b)) = (b + (c)) = (c + 7))

If not please help because I am at a loss. I know that the code simplifies to the following:
a = a + b
b = b + c
c = c + 7

Please help this is a self taught distance course and I am struggling hard since it is my first programming language.
Thanks


Here's a suggestion:

Put both expressions in a program and print out the results. Once you see the "right answer" (that is: are the results the same or different?) work your way back to see if you can explain it. Maybe break the expressions into multiple statements. That could give some clues.

If you develop a methodology for learning I think you can learn a lot more (and also answer your own questions when there's no one else around).

My methodology for learning new or puzzling aspects of a programming language is:

Plug it into a program. Try it. (What's the worst that could happen? What's the best that could happen?)

If you get results that you don't understand, ask specific questions.

Regards,

Dave
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
equivalent of clrscr() on unix/linux?? nkhambal C Programming Language 1 03-Sep-2004 16:53
help with gnu regular expressions henrywidd C Programming Language 1 19-May-2004 05:45
regular expressions erniegerdie MySQL / PHP Forum 6 08-Mar-2004 05:46
Regular Expressions question. JdS MySQL / PHP Forum 3 04-Nov-2002 14:04

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:19.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.