【问题标题】:Any one explain the below code and what is its output?任何人解释以下代码及其输出是什么?
【发布时间】:2017-12-16 21:45:28
【问题描述】:

c++ 代码 我无法理解类内的指针。 char *txtTemp = NULL 这一行代表什么?

#include<iostream.h>
#include<string.h>
#include<malloc.h>
class BixString
{
    char txtName[20]; 
    public:
    BixString(char *txtTemp = NULL)
    {
        if(txtTemp != NULL)
        strcpy(txtName, txtTemp);
    }
    void Display(void)
    {
        cout<<txtName;
    }
};
int main()
{
    char *txtName = (char*)malloc(10);
    strcpy(txtName, "IndiaBIX");
    *txtName = 48;
    BixString objTemp(txtName);
    cout<< sizeof(txtName);
    return 0; 
}

【问题讨论】:

标签: c++ oop pointers


【解决方案1】:

这是一个默认参数,因此您可以不带参数调用BixString(),而txtTemp 变量将为NULL

【讨论】:

    猜你喜欢
    • 2021-11-04
    • 1970-01-01
    • 2020-05-29
    • 2016-05-08
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    相关资源
    最近更新 更多