有关结构体的问题
struct stu{int a;int b;};struct stu1{char a;char b;};
main(){
struct stu1 a1;
struct stu a;
a.a=1;
a.b=2;
a1.a='a';
a1.b='c';
printf("a:%d %d \na1:%c %c ",a,a1);
}
为什么a的内容可以正确输出,a1的却不可以?结构体类型的变量名到底代表了什么?结构体变量到底能不能进行进行整体操作?
* 坐标数据,可从数据表或外部数据文件中获取 DIMENSION aList[3,2] aList[1,1] = 1.0 aList[1,2] = 5.0 aList[2,1] = 3.0 aList[2,2] = 3.0 aList[3,1] = 2.0 aList[3,2] = 4.0 * 建立坐标数组 CLEAR ? "排序前" ? nNumber = ALEN(aList,1) DIMENSION aCoords[nNumber] FOR nIndex = 1 TO nNumber aCoords[nIndex] = CREATEOBJECT("Coord", aList[nIndex,1], aList[nIndex,2]) ? aCoords[nIndex].ToString() NEXT ? Sort_Coord(@aCoords) && 加@符号表示以传递地址方式传递参数 * 输出结果 ? "排序后" ? FOR nIndex = 1 TO nNumber ? aCoords[nIndex].ToString() NEXT ? RETURN *------------------------ * 自定义坐标类 *------------------------ DEFINE CLASS Coord AS Custom HIDDEN x, y && 内部数据,不允许外部直接修改x,y的值 x = 0 && 横坐标 y = 0 && 纵坐标 *------------------------ * 直接初始化,若不输入参数,则默认为(0,0) *------------------------ PROCEDURE Init(tnX, tnY) IF PCOUNT() == 0 This.x = 0 This.y = 0 ELSE IF (VARTYPE(tnX) == "N") .AND. (VARTYPE(tnY) == "N") This.x = tnX This.y = tnY ELSE This.x = 0 This.y = 0 ENDIF ENDIF ENDPROC FUNCTION GetX RETURN This.x ENDFUNC FUNCTION GetY RETURN This.y ENDFUNC *------------------------ * 将另一坐标赋值给本坐标 * 参数:toCoord -- 源坐标 *------------------------ FUNCTION SetFromCoord(toCoord AS Coord) This.x = toCoord.GetX() This.y = toCoord.GetY() ENDPROC *------------------------ * 比较本坐标与另一坐标的关系 * 参数:toCoord -- 比较的坐标 * tnFlag -- 比较横坐标抑或纵坐标,0是横坐标(默认),1是纵坐标 * 返回:小于等于比较坐标,则返回真,否则返回假 *------------------------ FUNCTION Compare(toCoord AS Coord, tnFlag AS Integer) AS Boolean IF (PCOUNT() < 2) .OR. (VARTYPE(tnFlag) != "N") tnFlag = 0 ENDIF IF tnFlag != 0 tnFlag = 1 ENDIF RETURN IIF(tnFlag == 0, This.x <= toCoord.GetX(), This.y <= toCoord.GetY()) ENDFUNC *------------------------ * 将坐标转换为字符串形式 *------------------------ FUNCTION ToString() AS Character RETURN "(" + TRANSFORM(This.x) + "," + TRANSFORM(This.y) + ")" ENDFUNC ENDDEFINE *------------------------ * 用冒泡排序算法对坐标数组进行排序 * 参数:taCoords -- 需排序的坐标数组,在原数组中返回排序结果 * tnFlag -- 坐标比较标志,0是横坐标(默认),1是纵坐标 *------------------------ PROCEDURE Sort_Coord(taCoords AS Coord, tnFlag AS Integer) LOCAL i, j, n, loCoord loCoord = CREATEOBJECT("Coord") n = ALEN(taCoords,1) FOR i = 1 TO n - 1 FOR j = 2 TO n IF !taCoords[i].Compare(taCoords[j], tnFlag) && taCoords[i] > taCoords[j] loCoord.SetFromCoord(taCoords[i]) taCoords[i].SetFromCoord(taCoords[j]) taCoords[j].SetFromCoord(loCoord) ENDIF NEXT NEXT ENDPROC