![]() |
| ||
| Priority in Operators Primary (x) x.y f(x) a[x] x++ x--new typeof sizeof checked unchecked Unary + -~ ! ++x --x (T)x Multiplicative * / % Additive + - Shift << >> Relational < > <= >= is as Equality == != Logical AND& Logical XOR^ Logical OR| Conditional AND&& Conditional OR|| Conditional c?x:y Assignment = += -= *= /= %= <<= >>= &= ^= |= Operators on the same level are evaluated from left to right For better programming skills remember above priority in operators. Thanks, Anuj |
| ||
| Re: Priority in Operators For more effective programming, don't try and memorise this list; bracket expressions appropriately so that any programmer can read them whether or not they have also memorised this list (practically nobody has). OK, it's probably safe to assume that most programmers know that * and / have priority over + and -. But beyond that, nobody generally remembers or cares that, say, AND has higher precedence over XOR. And nobody is going to think you're a "better programmer" because you've pointlessly memorised this list. N.B. This list isn't "handed down by God". It's valid for C, Java and other languages that have deliberately chosen to use the same order of precedence. But some other language could choose to use a different order. |
| ||
| Re: Priority in Operators > For better programming skills remember above priority in operators I've been doing C for 20 years, and I still can't be bothered to remember it. The same goes for a large part of the standard C library. I know what functions exist, but I don't remember parameter orders for every single one of them (that's what man pages are for). I know roughly where everything goes, but if the expression becomes too complex (which is a hint in itself), then I just use ( ) Besides, if you're writing code commercially, you have to figure that at some point, someone who knows less C than you will be maintaining it at some point. So it pays to be not overly clever with your code. |
| ||
| Re: Priority in Operators ++ to both of the above posts. If you're writing a lot of code that depends on knowing that list well, no one will want to work with you (including yourself when you are trying to track down your own bugs 3 months later). |
| All times are GMT -4. The time now is 5:49 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC