![]() |
| | #1 |
| Registered User Join Date: Aug 2009
Posts: 5
| Although the expression *((a<20)?&b:&c)=30; works but ((a<20)?b:c)=30 gives error: invalid lvalue in assignment. what could be the reason for it? Please need sum urgent help. Thanks in advance. |
| lazy_hack is offline | |
| | #2 |
| Registered User Join Date: Jan 2002 Location: Northern Virginia/Washington DC Metropolitan Area
Posts: 2,870
| The result of the left hand side of: Code: ((a<20)?b:c)=30 Code: 20=30
__________________ On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. --Charles Babbage, 1792-1871 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 |
| hk_mp5kpdw is offline | |
| | #3 |
| Registered User Join Date: Aug 2009
Posts: 5
| full program: Code: main()
{
int a=10,b,c;
((a<20)?b:c)=30;
printf("%d",b);
}
but if i replace the line with *((a<20)?&b:&c)=30; it works. please explain also why the second one works . |
| lazy_hack is offline | |
| | #4 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,362
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #5 |
| DESTINY Join Date: Jul 2008 Location: in front of my computer
Posts: 803
| In the code above b and c are having garbage values, that's why as told to you in post#2, it'll give you error, while using & you are directly "attacking" in the address, thus no error.
__________________ HOPE YOU UNDERSTAND....... By associating with wise people you will become wise yourself It's fine to celebrate success but it is more important to heed the lessons of failure We've got to put a lot of money into changing behavior PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D. IDE- Microsoft Visual Studio 2008 Express Edition |
| BEN10 is offline | |
| | #6 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,362
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #7 |
| DESTINY Join Date: Jul 2008 Location: in front of my computer
Posts: 803
| I think hk_mp5kpdw's post is also wrong then.
__________________ HOPE YOU UNDERSTAND....... By associating with wise people you will become wise yourself It's fine to celebrate success but it is more important to heed the lessons of failure We've got to put a lot of money into changing behavior PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D. IDE- Microsoft Visual Studio 2008 Express Edition |
| BEN10 is offline | |
| | #8 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,362
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #9 |
| DESTINY Join Date: Jul 2008 Location: in front of my computer
Posts: 803
| From hk_mp5kpdw's post, let b has a value of 12345 in the code given by the OP, then this will happen Code: 12345=30;
__________________ HOPE YOU UNDERSTAND....... By associating with wise people you will become wise yourself It's fine to celebrate success but it is more important to heed the lessons of failure We've got to put a lot of money into changing behavior PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D. IDE- Microsoft Visual Studio 2008 Express Edition |
| BEN10 is offline | |
| | #10 | |
| Registered User Join Date: Jun 2009 Location: US of A
Posts: 301
| Quote:
for example as in your case 12345 = 30 // this is wrong | |
| roaan is offline | |
| | #11 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,362
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #12 |
| Registered User Join Date: Aug 2009
Posts: 5
| thanks for the explanation... "the result of the conditional operator is not an lvalue" line is the crux i believe... the code was from test ur c skills book....just anther intrsting book.. |
| lazy_hack is offline | |
![]() |
| Tags |
| ? :, assignment, lvalue, pointers |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with making a Math Expression DLL | MindWorX | C Programming | 19 | 07-19-2007 11:37 PM |
| Screwy Linker Error - VC2005 | Tonto | C++ Programming | 5 | 06-19-2007 02:39 PM |
| recursion error | cchallenged | C Programming | 2 | 12-18-2006 09:15 AM |
| Please Help - Problem with Compilers | toonlover | C++ Programming | 5 | 07-23-2005 10:03 AM |
| sizeof and Expression Evaluation | Dave_Sinkula | C Programming | 2 | 08-11-2003 07:11 PM |