What is char () type in C ++?

I compiled and ran the following code snippets in the GCCcompiler. He worked successfully.

#include <iostream>
using namespace std;

int main()
{
    char ch = char('A'); 
    cout<<ch<<endl;
    return 0;
}

Conclusion:

A

So, is there a char () function of a built-in type or a system call?

+4
source share
2 answers

Technically, this is a type. The phrase used in the standard to describe syntax is "Explicit type conversion (functional notation)." The description of the effect of the standard ([expr.type.conv] / 2) is as follows:

, ( , ) (8.4). [...] [T] he prvalue , (11.6).

"A" ( ), char 1 char ( ).

, , , . , (T)x static_cast<T>(x). , ctor, , . , ctor, explicit, , ( , ctor ), T ch = value; ( , , , ).


1. , , ++ C. C int, char.

+11

:

 char ch = char('A'); 

char, char. . , , , T :

T var = T(arg);

. , , T ( ), char(arg) .

+4

Source: https://habr.com/ru/post/1678387/


All Articles