// structtype.cpp: 定義控制台應用程式的入口點。
//#include "stdafx.h"
#include using namespace std;
struct student ;
int main()
; student* p = &stu;//定義乙個指向結構體student的指標
cout << stu.num << endl
<< stu.name << endl
<< stu.age << endl;
cout << p->num << endl//通過結構體指標進行結構體元素的輸出
<< p->name << endl
<< p->age << endl;
cout << &stu << endl
<< &(stu.num) << endl //stu與stu,name的位址相同,且各成員位址相連
<< &(stu.name) << endl
<< &(stu.age) << endl;
//cout << &student << endl;
//不允許使用型別名
return 0;
}
c 之結構體
結構是使用 struct 關鍵字定義的,與類相似,都表示可以包含資料成員和函式成員的資料結構。一般情況下,我們很少使用結構,而且很多人也並不建議使用結構,但作為.net framework 一般型別系統中的乙個基本架構,還是有必要了解一下的。結構的特徵 結構是一種值型別,並且不需要堆分配。結構的例項...
c 之結構體
include using namespace std include 結構體 屬於使用者自定義的資料型別,允許使用者儲存不同的資料型別 自定義資料型別,一些型別集合組成的乙個型別 語法 struct 型別名稱 1.建立學生資料型別 學生包括 姓名,年齡,分數 struct student s3 2...
c語言結構體之結構體巢狀
注意 1結構體內部再次定義乙個結構體 但是沒有建立結構體的例項 也就是說再次定義的結構體內部的變數會被當做母結構體的成員變數 1 struct tianchao 2 11 12 13 void mainww 14 24 25 struct tianchao 26 b1 內部定義的第一種方式 35 s...