Hacker News new | past | comments | ask | show | jobs | submit login

I'm rusty on C, and confused. What should I use instead of signed int?



unsigned int :)


and for negative numbers?


In that case, you can be pretty certain that you need a signed integer.


What if you only need to store negative integers?


Isn't that the same situation as only storing signed integers? The arithmetic is just a little different.


No, you get room for one more negative int. x = x < 0 ? -x : x; is a common buggy abs(), e.g. when printing an integer. One should test if it's negative, perhaps print the '-', and then ensure it's negative for the rest of the per-digit code.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: