if(a=='('|| '{') cout<< "true";
You have two problems with that statement.
1. Operator precedence
Your condition is not like this:
a == ('(' || '{')
…but like this:
(a == '(') || '{'
2. How operators work
But, even if it were like the first one, that's just not how boolean operators work.
Although it is common in English (and other human languages) to say things like:
if X is Y or Z...
… that is not quite how boolean logic works.
Your approach would be parsed more like this:
if X-is-Y, or Z...
And something like (a == '(')
is going to give you a boolean, then OR that boolean with '{'
. Not what you intended at all: a character like '{'
is always "truthy", and anything OR'd with true
is true
, so that whole condition will always result in true
.
What you need is:
if X-is-Y, or X-is-Z
To accomplish this, rewrite your condition like this:
a == '(' || a == '{'