Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unsigned keyword in C++

Tags:

c++

unsigned

Does the unsigned keyword default to a specific data type in C++? I am trying to write a function for a class for the prototype:

unsigned Rotate(unsigned object, int count) 

But I don't really get what unsigned means. Shouldn't it be like unsigned int or something?

like image 268
Crystal Avatar asked Jan 20 '10 08:01

Crystal


People also ask

Why unsigned is used in C?

An unsigned Integer means the variable can hold only a positive value. This format specifier is used within the printf() function for printing the unsigned integer variables.

What is signed and unsigned keyword in C?

The term "unsigned" in computer programming indicates a variable that can hold only positive numbers. The term "signed" in computer code indicates that a variable can hold negative and positive values. The property can be applied to most of the numeric data types including int, char, short and long.

Is unsigned a keyword?

The keyword unsigned is a data type specifier, which only represents non-negative integers i.e. positive numbers and zero.

What is an unsigned type?

An unsigned data type simply means that the data type will only hold positive values; negatives aren't allowed to be stored in the data type. Unsigned data types include int, char, short, and long.


2 Answers

From the link above:

Several of these types can be modified using the keywords signed, unsigned, short, and long. When one of these type modifiers is used by itself, a data type of int is assumed

This means that you can assume the author is using ints.

like image 91
futureelite7 Avatar answered Oct 02 '22 19:10

futureelite7


Integer Types:

short            -> signed short signed short unsigned short int              -> signed int signed int unsigned int signed           -> signed int unsigned         -> unsigned int long             -> signed long signed long unsigned long 

Be careful of char:

char  (is signed or unsigned depending on the implmentation) signed char unsigned char 
like image 42
Martin York Avatar answered Oct 02 '22 18:10

Martin York