1、結(jié)構(gòu)體內(nèi)存分配按照最嚴(yán)格的數(shù)據(jù)類型分配
例:
struct student
{
int num;
char c;
};
struct student stu1,stu2,stus[20],*ps;
內(nèi)存分配的時(shí)候按照int型分配(地址按照能被4整除),成員的排列次序不同,內(nèi)存分配不同。。。
另外編譯器影響結(jié)構(gòu)體的內(nèi)存分配。。最有效的方式(sizeof(student))計(jì)算字節(jié)數(shù)。。
struct student
{
int num;
char name[20];
}stu1,stu2,stus[20],*ps;
struct
{
int num;
char name[20];
}stu1;//沒有結(jié)構(gòu)體名稱,所以不能在其他地方定義變量。。
無語。。
2、結(jié)構(gòu)體可以嵌套,但是結(jié)構(gòu)體不能嵌套自身。。。
Linux定義: Linux is not unix!!!
struct student li,zhang={"zhang",1,2,3};
li=zhang;//結(jié)構(gòu)體可以直接相等。。當(dāng)然兩個不同的結(jié)構(gòu)體變量不能直接賦值。。。
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;//這時(shí)候存在問題。。。 char* s1,s2;。。。
typedef char* string;
string s1,s2;//OK
typedef int bool;
struct Rec
{
...
};
typedef struct Rec Rec;
Rec jince;
指針變量統(tǒng)一占4個字節(jié)。。。
指針數(shù)組。。。解決鏈表問題??
前一個節(jié)點(diǎn)記錄后一個節(jié)點(diǎn)的地址。。。。
typedef struct Link
{
int a;
char c;
Link *next;
}Link;
5、#ifndef LIST_H //預(yù)編譯命令。。。對于已經(jīng)定義的LIST_H不進(jìn)行編譯。。
posted on 2010-10-30 20:31
jince 閱讀(249)
評論(0) 編輯 收藏 引用