voip
风的方向
厚德致远,博学敦行!
posts - 52,comments - 21,trackbacks - 0

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 阅读(226) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


哈哈哈哈哈哈