c與c++中的struct使用

c中

struct Student {
	int age;
	char name[60];
};

typedef struct Student2 {
	int age;
	char name[60];
} Student_t;

int main(int argc, char **argv) {


	struct Student s = {10,"Mile"};
	printf("%d%s\n", s.age,s.name);
	Student_t s2 = {11,"Pony"};
	printf("%d%s\n", s2.age,s2.name);
	
	return 0;
}

 

c++中,不需要加struct關鍵字,實質是一個類

struct Student {
	int age;
	char name[60];
};

int main(int argc, char **argv) {

	 Student s = {10,"Mile"};
     printf("%d%s\n", s.age,s.name);
}

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章