search

Home  >  Q&A  >  body text

c++ - int a = int(); 这个int()是什么用法呢?

下面这段代码

int a = int();
cout<<a<<endl;

输出是0;

我想知道这个int()是什么用法。或者您可以告诉我用什么名词可以搜索到这个内容,我想具体得了解一下。

PHP中文网PHP中文网2803 days ago545

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:53:31

    Keywords: constructor

    For a type, the type name itself is the constructor of the type
    For example, there is a class

    class A {
        ...
    };

    Then A() is the constructor of type A. Using A() you can get a variable of type A.
    int is a built-in type, so int() calls the constructor of the int type and returns an int variable.

    reply
    0
  • Cancelreply