Is this part of the standard?

C

copx

Is the "-" operator (meaning * (-1) ) part of the standard?

Example program:

#include <stdio.h>

int main(void)
{
int a = -5;

printf("%d", -a); /* should print 5 */

return 0;
}


Is that portable?
 
V

Vladimir S. Oka

copx said:
Is the "-" operator (meaning * (-1) ) part of the standard?

Yes (C&V 6.5.3). It's called "unary minus" (same as in maths, really).
Example program:

#include <stdio.h>

int main(void)
{
int a = -5;

printf("%d", -a); /* should print 5 */

return 0;
}


Is that portable?

No, as you did not terminate `printf` with '\n'. Not doing so makes it
possible for a conforming implementation to do anything, including not
printing out any characters at all. ;-)

As for a unary `-`, yes, it is.

Cheers

Vladimir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top