tutorials confuse

This step in tutorial https://www.cplusplus.com/doc/tutorial/constants/

I'm confuse since there isn't many example for all those new terms, also I don't really get when to use the new term like u and l, ul. I understand they has different char size.

also this one

1
2
3
4
  R"(string with \backslash)"
  R"&%$(string with \backslash)&%$"

	


i dont get it at all, what is raw and UTF 8? sequence? Do i need to look up each of those define in internet before i process the tutorial?

backslash is \ right? i get it. its being using for long line u can use it to make it shorter to read.

to be clear, double and float mean decimal such as 0.43, only different is size?
float is smaller than double right?
The size of an int can be any size depending on the hardware/operating system on your computer. In addition to int, there are also char, short, long and long long. the main requirements are that:

sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long).

Let's say you have a system where int is 2 bytes, long is 4 bytes and long long is 8 bytes.

5 -> A 2-byte value containing the numeric value 5
5l -> A 4-byte value containing the numeric value 5
5ll -> An 8-byte value containing the numeric value 5

Integer types can be signed or unsigned. If they are signed, the upper bit is a sign bit (pos. or neg.), and the magnitude is contained in the rest of the lower bits. There is also a coding method called 2s complement that expresses how negative numbers are represented, so it's not just simply flipping the sign bit. The point is, however, that for a 16 bit signed integer, you can only use 15 bits for the magnitude of the number. Your range for a 16-bit signed int is -32768 to +32767.

If the integer type is unsigned, it cannot represent negative numbers. Thus, a 16-bit unsigned int can represent the values 0 - 65535.

So, in the scenario mentioned above:

5u -> a 2-byte unsigned int containing the numeric value 5
5ul -> a 4-byte unsigned int containing the numeric value 5.

The R"..." construct means you can provide a character constant without using escape characters. In normal C++ usage, certain characters need to be handled separately. for instance, quotation marks are used to delineate the beginning and ending of a C-style string. If you want the string to contain a quotation mark, you must "escape" the quotation mark by placing a backslash in front of it. That way, C++ knows that the quotation mark is a character within the string, not the termination of the string.

However, with raw strings, you can use the 'R' construct to simplify string constants and skip the escape characters. If you have a string that contains quotation marks or parentheses, you can define your own sequence to delineate the beginning and ending of the raw string.

Yes, '\' is a backslash.

The double type has, I believe, 2x the number of bits as a float, thus the name "double". You should prefer to used doubles unless there is an ulterior reason not to.
I appreciate your clearly explaining. I finally get it all those now. Thank you
Last edited on
Another tutorial site you might want to look at is "Learn C++:"
https://www.learncpp.com/

A look at constants:
https://www.learncpp.com/cpp-tutorial/const-constexpr-and-symbolic-constants/

As your knowledge of C++ grows you will learn about others forms of const.

Sadly the tutorial here at CPP is out of date, no C++17 or later. Learn C++ is still being updated.
I checked Learn C++ its truly is better at tutorial. Thank for the recommend.
Topic archived. No new replies allowed.