Can any body confirm me pls if I am right. I tested through code 1) shift operators can be applied to char type operand 2) the unary +,- can not be applied to char type operand 3) ~ (bitwise inversion)can be applied to char type operand
ego hu
Ranch Hand
Joined: Mar 20, 2001
Posts: 53
posted
0
Can any body confirm me pls if I am right. I tested through code 1) shift operators can be applied to char type operand char is promoted to int. 2) the unary +,- can not be applied to char type operand char is unsigned. 3) ~ (bitwise inversion)can be applied to char type operand char is promoted to int.
mansoor iqbal
Ranch Hand
Joined: Aug 14, 2000
Posts: 91
posted
0
char a='s'; char b='o'; System.out.println(a); System.out.println(b); System.out.println(a | b); System.out.println(a ^ b); prints out s,o,127,28
means u can even perform logical operations on char as well.
Sathi Chowdhury
Ranch Hand
Joined: Mar 16, 2001
Posts: 52
posted
0
thank u Mansoor and Ego.I was just filling up a chart for what operators can be applied to what type operands... thanks for the help.. Sathi
Pratiti Naphade
Ranch Hand
Joined: Mar 13, 2001
Posts: 39
posted
0
they are not performed on char... in the prnt line it is converted to int. try this char a = 'a'; char b = 'b'; char c = a& b;//error
ego hu
Ranch Hand
Joined: Mar 20, 2001
Posts: 53
posted
0
You nust cast it: char c=(char) a&b;
Sathi Chowdhury
Ranch Hand
Joined: Mar 16, 2001
Posts: 52
posted
0
because result type of all binary operation should be at least int type. int a; char c='a'; char d='b'; a=c&d;// works fine