syntax

Why are some arguments enclosed in parentheses?

(first == second) ? "equal" : "not equal";
Sometimes (in your case too) just to make things clearer, other times to override operator precedence just like in mathematics.
http://www.cplusplus.com/doc/tutorial/operators/
Last edited on
closed account (S6k9GNh0)
It's recommended to always use parenthesis to help clarify the order of things. If you don't know if you should use parenthesis or not, as a rule of thumb, just use parenthesis.
Last edited on
I always use paranthesis. Even for obvious things like (x * 5) + 3. Makes it so much easier to read.
Ever thought programming in Lisp?
Hahaha

Well I never have THAT many parenthesis. I avoid compound statements as much as possible. Nothing wrong with new lines and whitespace.
Extra parens do not always enhance readability, IMHO.

After all, most people don't do things like:

( ( cout << "Hello " ) << "World ) << endl;

or

memcpy( ( dest ), ( src ), ( sizeof( src ) ) );


Most people use parens, as computerequip stated, to clarify things. But the problem is
that what is not clear to one person is perfectly clear to another, and in the latter case
the parens are just syntactic baggage.
Thanks, so parens are used to help clarify statements and used for c++ syntax; as in type casting.

LOL, on Lisp programming!

Topic archived. No new replies allowed.