Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of U suffix

Tags:

c++

c

What does the postfix (or suffix) U mean for the following values?

0U 100U 
like image 689
lovespring Avatar asked Dec 07 '10 19:12

lovespring


People also ask

What does u at end of hex mean?

It means that it is an unsigned hexadecimal constant of value 47 hex = 71 decimal. If the 'u' is omitted then it is a signed hexadecimal constant of value 47 hex.

What does 1U mean in C?

1U is unsigned. It can carry values twice as big, but without negative values. Depending on the environment, when using U, i can be a maximum of either 31 or 15, without causing an overflow. Without using U, i can be a maximum of 30 or 14. 31, 30 are for 32 bit int.

What does U mean in C after number?

it means "unsigned int", basically it functions like a cast to make sure that numeric constants are converted to the appropriate type at compile-time.

What does 0u mean in C++?

Thus ~0u means the maximum value of an object of type unsigned int when each bit of its internal representation is set to 1.


2 Answers

It stands for unsigned.

When you declare a constant, you can also specify its type. Another common example is L, which stands for long. (and you have to put it twice to specify a 64-bit constant).

Example: 1ULL.

It helps in avoiding explicit casts.

like image 200
ruslik Avatar answered Oct 07 '22 21:10

ruslik


Integer constants in C and C++ can optionally have several suffixes:

123u      the value 123 is an unsigned int
123l       (that's a lowercase L) 123 is a signed long
123L      ditto
123uL    unsigned long
123LL    a signed long long, a 64 bit or 128 bit value (depending on the environment)
123uLL  unsigned long long

like image 45
wallyk Avatar answered Oct 07 '22 23:10

wallyk