• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unary operator

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unary operators,conversion rules please

char x1=+x;
int x1=++x;

How the previous conditions are working.Can anyone please explain all the unary conversion rules.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first one is the unary plus operator. I don't believe the statement as you have it written is legal -- as the result of a mathematical expression gets promoted to int. So you will need to cast it back to a char (assuming x was originally a char).

The second operation is the prefix increment operator. And that should be legal assuming that x was an int (or smaller datatype).

Henry
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
char x1=+x;
int x1=++x;

In the above statment i am assuming that the data type of that x is int and you are adding that int with char including plus symbole. It will genrate a compile time error that

possible lose of precission

found int
requred character

and your second statment that is int x1=++x. Here ++ is the unary prefix operator. Here the whatever the value in the x that value will be first increse with 1 and assigned to that of x1.
 
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic