C++ Axioms

My note for c++

1.1.1

Data type char16_t, char32_t, or wchar_t with variables assigned to an octal representation of unicode characters are converted to a decimal when used with std::cout while char in Octal representation is conve…


This content originally appeared on DEV Community and was authored by hwangs12

My note for c++

1.1.1

Data type char16_t, char32_t, or wchar_t with variables assigned to an octal representation of unicode characters are converted to a decimal when used with std::cout while char in Octal representation is converted to a string literal.

Example

#include <iostream>

int main()
{
    // The following are Octal representation of 
    // a unicode character M.
    char16_t d1 = '\115';
    char32_t d2 = '\115';
    wchar_t d3 = '\115';
    char d4 = '\115'

    std::cout << d1 << " is the \x4d greatest number of all" << std::endl;
    // d1, d2, d3 are converted to decimal, hence shows 77 
    // in the output but d4 will be converted to character M. 

    return 0;
}

1.1.2

Hexadecimal (hex for short) representation uses A, B, C, D, E, F to represent numbers after 9. For example, 4D in hex is equivalent to 77 in decimal because D is equal to 13 and 4 * 16 + 13 = 77.

Example

#include <iostream>

int main()
{
    char16_t yo = '\x4d'; 
    // char16_t type converts to hex int with std::cout per 1.1.1
    std::cout << yo << " is the greatest number of all " << std::endl;
    // 77 is the greatest number of all
    return 0;
}

Note: Had A B C D E F not been used, it would have been more difficult to represent decimal numbers like 77 because \x4(13) is longer in length, and without the brackets, it will convert to a much bigger number.


This content originally appeared on DEV Community and was authored by hwangs12


Print Share Comment Cite Upload Translate Updates
APA

hwangs12 | Sciencx (2022-04-16T23:42:27+00:00) C++ Axioms. Retrieved from https://www.scien.cx/2022/04/16/c-axioms/

MLA
" » C++ Axioms." hwangs12 | Sciencx - Saturday April 16, 2022, https://www.scien.cx/2022/04/16/c-axioms/
HARVARD
hwangs12 | Sciencx Saturday April 16, 2022 » C++ Axioms., viewed ,<https://www.scien.cx/2022/04/16/c-axioms/>
VANCOUVER
hwangs12 | Sciencx - » C++ Axioms. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/16/c-axioms/
CHICAGO
" » C++ Axioms." hwangs12 | Sciencx - Accessed . https://www.scien.cx/2022/04/16/c-axioms/
IEEE
" » C++ Axioms." hwangs12 | Sciencx [Online]. Available: https://www.scien.cx/2022/04/16/c-axioms/. [Accessed: ]
rf:citation
» C++ Axioms | hwangs12 | Sciencx | https://www.scien.cx/2022/04/16/c-axioms/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.