char = () ?

Rather than hijack someones thread I've made this thread.
Here is the OP:
http://www.cplusplus.com/forum/beginner/58741/

I saw some code on his/her post that I've never seen before and was wondering what it does.
1
2
3
4
5
6
7
char gender;

cout << "please enter the candidates information (Enter 'x' to exit) " << endl;

cout << setw(10) << "Gender: ";
gender = ('x' || 'X' || 'F' || 'f' || 'm' || 'M') ;
cin >> gender;


What is the purpose of the following line:
gender = ('x' || 'X' || 'F' || 'f' || 'm' || 'M') ;

Thanks.
It has no purpose, it's nonsense. It's equivalent to gender=1;.
Ah right, thanks.

It really is useless then.
that's wrong for me || (or) and && (and) are for logical operation.

('x' || 'X' || 'F' || 'f' || 'm' || 'M') ;

This is just wrong,2 reasons :

the gender is not assigned at first,after char gender;

and gender = ('x' || 'X' || 'F' || 'f' || 'm' || 'M') ;

doesnt make sense. gender == 'x' || gender == 'X' can use || operator but it returns boolean value,true or false.

because gender is not assigned,line 6 sounds more funny

So my advice :

1
2
3
char gender;
cin >> gender;
if(gender == 'x' || gender == 'X' || (More here)) {/*Do something here*/}
Yeah, that's more than likely why I've never seen it like that! lol
Last edited on
Topic archived. No new replies allowed.