You are here:

C/C output confused

Advertisement


Question
Help -
void main ()
{
int a=-5;
-a;
cout<<a;
... }
Output is -5
Why isnt dis output 5 ..

Answer
Hello Vikas.

The line:
-a;
does evaluate the negative of "a", but the result is not stored. To change the value of "a", the result has to be assigned back to "a".

If you change the line to:
a = -a;

You will get the result you expect.

I hope that answers your question.

Best regards
Zlatko

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Zlatko

Expertise

No longer taking questions.

Experience

No longer taking questions.

Education/Credentials
No longer taking questions.

©2012 About.com, a part of The New York Times Company. All rights reserved.