1、結構體內存分配按照最嚴格的數據類型分配
例:
struct student
{
int num;
char c;
};
struct student stu1,stu2,stus[20],*ps;
內存分配的時候按照int型分配(地址按照能被4整除),成員的排列次序不同,內存分配不同。。。
另外編譯器影響結構體的內存分配。。最有效的方式(sizeof(student))計算字節數。。
struct student
{
int num;
char name[20];
}stu1,stu2,stus[20],*ps;
struct
{
int num;
char name[20];
}stu1;//沒有結構體名稱,所以不能在其他地方定義變量。。
無語。。
2、結構體可以嵌套,但是結構體不能嵌套自身。。。
Linux定義: Linux is not unix!!!
struct student li,zhang={"zhang",1,2,3};
li=zhang;//結構體可以直接相等。。當然兩個不同的結構體變量不能直接賦值。。。
li={"li",1,2,3};//錯。。
if(stu1==stu2);//錯。。
struct student
{
int age;
char *name;
}*ps;
ps=(struct student *)malloc(sizeof(struct student));
(*ps).age=30;
(*ps).name=(char *)malloc(20);
strcpy((*ps).name,"jince");
free((*ps).name);//釋放順序。。。
free(ps);
3、海賊王更新。。。
4、typedef int intage;
typedef double real;
#define int intage;
#define char* string;
string s1,s2;//這時候存在問題。。。 char* s1,s2;。。。
typedef char* string;
string s1,s2;//OK
typedef int bool;
struct Rec
{
...
};
typedef struct Rec Rec;
Rec jince;
指針變量統一占4個字節。。。
指針數組。。。解決鏈表問題??
前一個節點記錄后一個節點的地址。。。。
typedef struct Link
{
int a;
char c;
Link *next;
}Link;
5、#ifndef LIST_H //預編譯命令。。。對于已經定義的LIST_H不進行編譯。。
posted on 2010-10-30 20:31
jince 閱讀(254)
評論(0) 編輯 收藏 引用