C与C++的struct区别

 C++中struct定义一个新的数据类型,例:

#include<iostream>
using namespace std;

struct teacher
{
	string name[32];
	int age;
};

int main()
{
	teacher t1;
	t1.age = 40;
	cout << t1.age;
	//system("pause");
	return 0;
 }

C中struct只是定义一个不同数据的集合,使用时需要加上struct

struct teacher
{
	string name[32];
	int age;
};

int main()
{
	struct teacher t1;
	t1.age = 40;
	printf("hello");
	//system("pause");
	return 0;
 }

                                                                                                                                                                                                   NoN小旻

                                                                                                                                                                                                   2018.9.15

猜你喜欢

转载自blog.csdn.net/qq_38386991/article/details/82714014