Getting Negative Int

  • Thread starter Thread starter Smithers
  • Start date Start date
S

Smithers

int k = 8;

elsewhere in the code, I need to k to be -8.

I could do this:

int negativeVal = 0 - k;

is there a better way?

Thanks!
 
Smithers said:
int k = 8;

elsewhere in the code, I need to k to be -8.

I could do this:

int negativeVal = 0 - k;

is there a better way?

Thanks!

Not sure, have you tried:

int negativeVal = -k;

HTH,
Mythran
 
Back
Top