Trailing u in Hex Number C/C++ [duplicate] - c++

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Meaning of U suffix
I'm going through code that has a bunch of defines that look like:
#define HEX_NUMBER (0x000000FFu)
What is the trailing u? I've tried compiling with and without it and I don't see any difference.

Appending u to any integral constant makes the compiler interpret it as unsigned.

Related

C++ string length [duplicate]

This question already has answers here:
What does the C++ standard state the size of int, long type to be?
(24 answers)
Getting the actual length of a UTF-8 encoded std::string?
(11 answers)
Closed 2 years ago.
I was reading the documentation of string::length and, as you can see, it says that
Returns the length of the string, in terms of bytes.
So my question is, is this ensured to be also the number of char that it contains?
I know that usually a char is 1 byte, but is this ensured somewhere? Like in the standard or somewhere else?

Why are my array values changing? [duplicate]

This question already has answers here:
How does a leading zero change a numeric literal in Java?
(3 answers)
Closed 7 years ago.
I'm trying to initialize an int array, but when I go back to reference it, my values change as you can see here. For example my values {010, 011} are changing to {8,9}. Can anyone tell me why this is happening? Thank you in advance!
Numbers starting with a zero are treated as octal by the compiler.
010 in octal is 8.
Maybe just use 10 to initialise the values.
By prefixing the 10 with 0, you are telling the compiler that it is an octal number(base-8 number). To solve this, simply initialize your values as {10,11}

What is the difference between 0x and '\x' in C++? [duplicate]

This question already has answers here:
What does \x mean in C/C++?
(7 answers)
strlen - the length of the string is sometimes increased by 1
(1 answer)
Closed 8 years ago.
I know that hex-decimal number is usually prefixed with 0x in C/C++ language.
For example, 0x5A means 90 in decimal.
But I saw an example code using single-quoted character with '\x'.
BYTE outputBuffer[index++] = '\x5A'; // instead of 0x5A
Is the meaning of '\x5A' exactly the same as 0x5A?
If so, why is there alternative way of hex-decimal notation?
For a character, both are quite equal.
But only one can be mixed into a string with other normal characters. "ABC\x5A"
And only one can be used to initialize a large integral type: long long x = 0x1234567812345678LL;

How does C++ understand two letter characters [duplicate]

This question already has answers here:
Multicharacter literal in C and C++
(6 answers)
What do single quotes do in C++ when used on multiple characters?
(5 answers)
Closed 9 years ago.
C++ seems to allow up to four characters to be held in single quotes, such as:
char c = 'abcd';
but at runtime, only the last value ('d') seems to be actually stored away. This behavior seems to happen for pairs of two, three, or four (at five the compiler finally calls uncle). But what's the deal with this design? I don't really see the logic in it.

boolean operator in c++ [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What does 'unsigned temp:3' mean?
I saw some c++ code today that used single colons.
bool variable_name : 1;
what is the difference between this and
bool variable_name = true;
The ": 1" means it is a bit field with 1 bit, or at least that's what it means in C. It probably was put there to save some memory, allowing multiple bools to be stored in the same byte. The downside is that you probably can't make a pointer to that bool.