• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Operators

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You nust cast it:
char c=(char) a&b;
 
Sathi Chowdhury
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic