面试题c++

1.
void countSize()
{
	char *str1="hello,snowman";
	char str2[]="hello,snowman";
	char str3[20]="hello,snowman";
	char *str4;
	str4 = (char*)malloc(sizeof(char)*20);
	strcpy(str4, "hello,snowman");

	cout<<"1. "<<sizeof("hello,snowman")<<endl;
	cout<<"2. "<<sizeof(str1)<<endl;
	cout<<"3. "<<sizeof(str2)<<endl;
	cout<<"4. "<<sizeof(str3)<<endl;
	cout<<"5. "<<sizeof(str4)<<endl;

	return;
}


2. 

struct ST
{
	int id;
	int n;
};

void pointer1()
{
	struct ST *ptr;
	ptr = (struct ST*)malloc(sizeof(struct ST));

	ptr->id=101;
	ptr->n=10;
}

void pointer2()
{
	struct ST *ptr;
	ptr = (struct ST*)malloc(sizeof(struct ST));

	free(ptr);

	if(ptr!=NULL)
	{
		ptr->id=101;
		ptr->n=10;
	}
}

3.

class CBall
{
public:
	CBall();
	~CBall();

public:
	void getBall();

private:
	int m_id;
	char *m_ballName;
};
class CFootBall:CBall
{
public:
	CFootBall();
	~CFootBall();

public:
	void getBall();

private:
    int m_teamId;
	string m_country;
};

4.

struct STUDENT
{
	int id;
	char name[20];
	int score[10];
};

void setStudent(struct STUDENT &stu)
{
	char myName[30]={"DavidBeckham"};
	int score[10]={90,92,96,0};
	stu.id=10;
	memcpy(stu.score, score, sizeof(score));
	strncpy(stu.name, myName, sizeof(myName));

	return;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值