C语言-结构体与共用体
int 4字节;char 1字节;short 2字节;float 4字节;
1字节bytes=8位bits(2^8);
struct date
{int month;int day;int year;
}
struct
{int num;char name[20];char sex;struct date birthday;float score;
}boy1,boy2;
#include <stdio.h>
void main()
{struct date{int month;int day;int year;};struct{int num;char name[20];char sex;struct date birthday;float score;}boy1,boy2;
#include <stdio.h>void main()
{struct student{int num;char *name;char sex;float score;} boy1, boy2;boy1.num = 007;boy1.name = "Jane";printf("Please input sex and score\n");scanf("%c %f", &boy1.sex, &boy1.score);boy2 = boy1;printf("Number = %d\nName = %s\n", boy2.num, boy2.name);printf("Sex = %c\nScore = %f\n", boy2.sex, boy2.score);}
/*student1和student2在内存中各占?个字节*/
/*( 4 + 20 + 1 + 4 + 4 + 30 = 67 )*/
#include<stdio.h>
void main()
{struct student{int num;char name[20];char sex;int age;float score;char addr[30];}stu1,stu2;printf("%d\n",sizeof(stu1));
}
//实际为68
结构体数组:
一个通讯录:
#include"stdio.h"
#define NUM 3
struct person
{char name[20];char phone[10];
};
void main()
{struct person man[NUM];int i;for(i=0;i<NUM;i++){printf("input name:\n");gets(man[i].name);printf("input phone:\n");gets(man[i].phone);}printf("name\t\tphone\n\n");for(i=0;i<NUM;i++){printf("%s\t\t%s\n\n",man[i].name,man[i].phone);}
}
例题:对候选人得票的统计程序。设有3个候选人,每次输入一个得票的候选人的名字,要求最后输出各人得票结果。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>#define NUM 4
struct person
{char name[20];int count;
}candidate[NUM]={{"A",0},{"B",0},{"C",0},{"D",0}
};
char *winner();
char *winner()
{int i=0,winner=i;for(;i<NUM;i++){if(candidate[winner].count<candidate[i].count){winner=i;}}return candidate[winner].name;
}
void main()
{int i,j;char candidate_name[20];printf("欢迎进入优秀毕业生投票系统:()\n\n");printf("候选人有:A B C D\n\n");for(i=1;i<=10;i++){printf("第%2d位投票,请写下支持的候选人名字:",i);scanf("%s",candidate_name);for(j=0;j<NUM;j++){if(0==strcmp(candidate_name,candidate[j].name)){candidate[j].count++;}}}printf("\n");for(i=0;i<4;i++){printf("%s同学得票数为:%d\n",candidate[i].name,candidate[i].count);}printf("\n");printf("本次投票活动的胜利者是:%s",winner());printf("\n");system("pause");
}
指向结构体类型数据的指针:
一个结构体变量的指针就是该结构体变量所占据的内存段的起始地址。指针变量的值是结构体变量的起始地址,也可以用来指向结构体数组中的元素;与前面讨论的各类指针变量相同,结构指针变量也必须要先赋值后才能使用,是把结构变量的首地址赋予该指针变量,不能把结构名赋予该指针变量。因为,结构名只能表示一个结构形式,编译系统并不对它分配内存空间。只有当某变量被说明为这种类型的结构时,才对该变量分配存储空间。
struct stu{..........}boy;pstu=&boy
其访问的一般形式为:
(*结构指针变量).成员名 (*pstu).num
结构指针变量->成员名 pstu->num
#include<stdio.h>
struct stu
{int num;char *name;char sex;float score;
}boy1={102,"CSDN",'M',78.5};
void main()
{struct stu *pstu;pstu=&boy1;printf("Number = %d\nName = %s\n",boy1.num,boy1.name);printf("Sex = %c\nScore = %f\n\n",boy1.sex,boy1.score);printf("Number = %d\nName = %s\n",(*pstu).num,(*pstu).name);printf("Sex = %c\nScore = %f\n\n",(*pstu).sex,(*pstu).score);printf("Number = %d\nName = %s\n",pstu->num,pstu->name);printf("Sex = %c\nScore = %f\n\n",pstu->sex,pstu->score);
}
结构指针变量作函数参数:将一个结构体变量的值传递给另一个函数,有3个方法:
(1)用结构体变量的成员作参数
(2)用结构体变量作实参
(3)用指向结构体变量(或数组)的指针作实参,将结构体变量(或数组)的地址传给形参
例题:有一个结构体变量stu,内含学生学号、姓名和3门课程的成绩。通过调用函数print中将它们输出,要求:
先用结构体变量作函数参数:
#include<stdio.h>
#include<string.h>
struct student
{int num;char *name;float score[3];
};
void print(struct student);
void main()
{struct student stu;stu.num=8;stu.name="csdn.net!";stu.score[0]=98.5;stu.score[1]=99.0;stu.score[2]=99.5;print(stu);
}
void print(struct student stu)
{printf("\tnum : %d\n",stu.num);printf("\tname : %s\n",stu.name);printf("\tscore_1 : %5.2f\n",stu.score[0]);printf("\tscore_2 : %5.2f\n",stu.score[1]);printf("\tscore_3 : %5.2f\n",stu.score[2]);printf("\n");
}
改用指向结构体变量的指针作实参:
#include <stdio.h>
#include <string.h>struct student
{int num;char name[20];float score[3];
};void print(struct student *);void main()
{struct student stu;stu.num = 8;strcpy(stu.name,"csdn.net!");stu.score[0] = 98.5;stu.score[1] = 99.0;stu.score[2] = 99.5;print(&stu);
}void print(struct student *p)
{printf("\tnum : %d\n", p->num);printf("\tname : %s\n", p->name);printf("\tscore_1 : %5.2f\n", p->score[0]);printf("\tscore_2 : %5.2f\n", p->score[1]);printf("\tscore_3 : %5.2f\n", p->score[2]);printf("\n");
}
动态存储分配
在数组一章中,曾介绍过数组的长度是预先定义好的,在整个程序中固定不变。C语言中不允许动态数组类型。例如:int a[n];用变量表示长度,想对数组的大小作动态说明,这是错误的。但是在实际的编程中,往往会发生这种情况,即所需的内存空间取决于实际输入的数据,而无法预先确定。所以对于这种问题,用数组的办法很难解决!
为了解决上述问题,C语言提供了一些内存管理函数,这些内存管理函数可以按需要动态地分配内存空间,也可把不再使用的空间回收待用,为有效地利用内存资源提供了手段。
常用的内存管理函数有以下三个:
1. 分配内存空间函数 malloc、calloc
2. 释放内存空间函数 free
malloc函数:
函数原型为void *malloc(unsigned int size);
其作用是在内存的动态存储区中分配一个长度为size的连续空间(size是一个无符号数)。
此函数的返回值是一个指向分配域起始地址的指针(类型为void)。
如果此函数未能成功地执行(例如内存空间不足),则返回空指针(NULL)。
calloc函数:
函数原型为void *calloc(unsigned n, unsigned size);
其作用是在内存的动态存储区中分配n个长度为size的连续空间。
函数返回一个指向分配域起始地址的指针;
如果分配不成功,返回NULL。
用calloc函数可以为一维数组开辟动态存储空间,n为数组元素个数,每个元素长度为size。
free函数:
函数原型为void free(void *p);
其作用是释放由p指向的内存区,使这部分内存区能被其他变量使用。
p是最近一次调用calloc或malloc函数时返回的值。
free函数无返回值。
链 表 : 可以动态分配
链表是一种常见的重要的数据结构,是动态地进行存储分配的一种结构。
链表的组成:
头指针:存放一个地址,该地址指向第一个元素
结点:用户需要的实际数据和链接节点的指针
我们尝试根据下图建立链表:
#include <stdio.h>
struct student
{long num;float score;struct student *next;
};
void main()
{struct student a,b,c,*head;a.num=10101;a.score=89.5;b.num=10103;b.score=90;c.num=10107;c.score=85;head=&a;a.next=&b;b.next=&c;c.next=NULL;do{printf("%ld %5.1f\n",head->num,head->score);head=head->next;}while(head!=NULL);}
建立动态链表:
所谓建立动态链表是指在程序执行过程中从无到有地建立起一个链表,即一个一个地开辟结点和输入各结点数据,并建立起前后相链的关系。
作业:根据下面的分析写一程序建立一个含有学生(学号,成绩)数据的单向动态链表。
(约定:我们约定学号不会为零,如果输入的学号为0,则表示建立链表的过程完成,该结点不应连接到链表中。)
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>#define LEN sizeof(struct student)//student结构的大小
struct student *creat();//创建链表
void print(struct student *head);//打印链表的函数struct student
{int num;float score;struct student *next;
};int n;void main()
{struct student *stu;stu=creat();print(stu);printf("\n\n");system("pause");
}struct student *creat()
{struct student *head;//定义指针struct student *p1,*p2;p1 = p2 = (struct student *)malloc(LEN);//初始化指针,获取动态空间printf("Please enter the num: ");scanf("%d",&p1->num);printf("Please enter the score: ");scanf("%f",&p1->score);head=NULL;n=0;while(p1->num )//当p1.num不等于0{n++;//第一个节点if( 1 == n ){head = p1;}else{p2->next = p1;}p2 = p1;p1 = (struct student *)malloc(LEN);printf("\nPlease enter the num: ");scanf("%d",&p1->num);printf("Please enter the score: ");scanf("%f",&p1->score);}p2->next = NULL;return head;//返回首地址
}
void print(struct student *head)
{struct student *p;printf("\nThere are %d records!\n\n",n);p=head;if (head){do{printf("学号为%d的成绩是: %f\n",p->num,p->score);p = p->next;}while (p);}
}
题目:写一函数以删除动态链表中指定的结点。
解题思路:
一、从p指向的第一个结点开始,检查该结点中的num值是否等于输入的要求删除的那个学号。
二、如果相等就将该结点删除,如不相等,就将p后移一个结点,再如此进行下去,直到遇到表尾为止。
三、可以设两个指针变量p1和p2,先使p1指向第一个结点 。
四、如果要删除的不是第一个结点,则使p1后移指向下一个结点(将p1->next赋给p1),在此之前应将p1的值赋给p2 ,使p2指向刚才检查过的那个结点。
五、将以上几点我们综合得出算法流程图:
#include<malloc.h>
#include<stdlib.h>#define LEN sizeof(struct student)struct student *creat();
struct student *del(struct student *head, int num);void print(struct student *head);struct student
{int num;float score;struct student *next;
};int n;void main()
{struct student *stu, *p;int n;stu=creat();p=stu;print(p);printf("Please enter the num to delete: ");scanf("%d",&n);print(del(p,n));printf("\n\n");system("pause");
}struct student *creat()
{struct student *head;struct student *p1,*p2;p1=p2=(struct student *)malloc(LEN);printf("Please enter the num: ");scanf("%d",&p1->num);printf("Please enter the score: ");scanf("%d",&p1->score);head=NULL;n=0;while(p1->num){n++;if(1==n){head=p1;}else{p2->next=p1;}p2=p1;p1=(struct student *)malloc(LEN);printf("\nPlease enter the num: ");scanf("%d",&p1->num);printf("\nPlease enter the score: ");scanf("%f",&p1->score);}p2->next=NULL;return head;
}void print(struct student *head)
{struct student *p;printf("\nThere are %d records!\n\n",n);p=head;if(head){do{printf("学号为%d的成绩是:%f\n",p->num,p->score);p=p->next;}while(p);}
}
struct student *del(struct student *head,int num)
{struct student *p1,*p2;if(NULL==head){printf("\nThis is null!\n");goto end;}p1=head;while(p1->num != num && p1->next != NULL){p2=p1;p1=p1->next;}if(num ==p1->num){if(p1==head){head=p1->next;}else{p2->next=p1->next;}printf("Delete NO: %d succeed!\n",num);n=n-1;}else{printf("%d not been found!\n",num);}
end:return head;
}
对链表的插入操作
对链表的插入是指将一个结点插入到一个已有的链表中。为了能做到正确插入,必须解决两个问题:
① 怎样找到插入的位置; ② 怎样实现插入。
我们可以先用指针变量p0指向待插入的结点,p1指向第一个结点。将p0->num与p1->num相比较,如果p0->num>p1-> num ,此时将p1后移,并使p2指向刚才p1所指的结点。
情形1:插入位置在链表头
情形2:插入位置在链表尾
情形3:插入位置属于中部
流程图如下:
源程序如下:
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>#define LEN sizeof(struct student) // student结构的大小struct student *creat(); //创建链表
struct student *del(struct student *head, int num); //del函数用于删除结点, *head即链表
//的头指针, num是要删除的结点num。
struct student *insert(struct student *head, struct student *stu_2); // 第一个参数需要被插入的链表
// 第二个参数待插入的结构的地址void print(struct student *head); //打印链表struct student
{int num;float score;struct student *next;
};int n; //全局变量,用来记录存放了多少数据。void main()
{struct student *stu, *p, stu_2;int n;stu = creat();p = stu;print(p);printf("\nPlease input the num to delete: ");scanf("%d", &n);print(del(p, n));printf("\nPlease input the num to insert: ");scanf("%d", &stu_2.num);printf("Please input the score: ");scanf("%f", &stu_2.score);p = insert(stu, &stu_2);print(p);printf("\n\n");system("pause");
}struct student *creat()
{struct student *head;struct student *p1, *p2;p1 = p2 = (struct student *)malloc(LEN); // LEN是student结构的大小printf("Please enter the num :");scanf("%d", &p1->num);printf("Please enter the score :");scanf("%f", &p1->score);head = NULL;n = 0;while (p1->num){n++;if (1 == n){head = p1;}else{p2->next = p1;}p2 = p1;p1 = (struct student *)malloc(LEN);printf("\nPlease enter the num :");scanf("%d", &p1->num);printf("Please enter the score :");scanf("%f", &p1->score);}p2->next = NULL;return head;
}void print(struct student *head)
{struct student *p;printf("\nThere are %d records!\n\n", n);p = head;if (head){do{printf("学号为 %d 的成绩是: %f\n", p->num, p->score);p = p->next;} while (p);}
}struct student *del(struct student *head, int num)
{struct student *p1, *p2;if (NULL == head){printf("\nThis list is null!\n");goto end;}p1 = head;while (p1->num != num && p1->next != NULL){p2 = p1;p1 = p1->next;}if (num == p1->num){if (p1 == head){head = p1->next;}else{p2->next = p1->next;}printf("Delete No: %d succeed!\n", num);n = n - 1;}else{printf("%d not been found!\n", num);}end:return head;
}struct student *insert(struct student *head, struct student *stu_2)
{struct student *p0, *p1, *p2;p1 = head;p0 = stu_2;if (NULL == head){head = p0;p0->next = NULL;}else{while ((p0->num > p1->num) && (p1->next != NULL)) //两种情况推出while,一:{p2 = p1;p1 = p1->next;}if (p0->num <= p1->num){if (head == p1) // p1是头结点,插入头部{head = p0;}else // 普通情况,插入中间{p2->next = p0;}p0->next = p1;}else // p0的num最大,插入到末尾{p1->next = p0;p0->next = NULL;}}n = n + 1; // 由于插入了,所以增加了一位数据成员进入链表中。return head;
}
共用体
共用体的概念 :使几个不同的变量共占同一段内存的结构称为 “共用体”类型的结构。
定义共用体类型变量的一般形式为:
union 共用体名
{
成员表列
}变量表列;
union data
{int i;char ch;float f;
} a, b, c;
union data
{int i;char ch;float f;
};
union data a, b, c;
共用体和结构体的比较:
结构体变量所占内存长度是各成员占的内存长度之和。每个成员分别占有其自己的内存单元。
共用体变量所占的内存长度等于最长的成员的长度。
共用体变量的引用方式:只有先定义了共用体变量才能引用它,而且不能引用共用体变量,而只能引用共用体变量中的成员。
例如:前面定义了a、b、c为共用体变量
a.i (引用共用体变量中的整型变量i)
a.ch(引用共用体变量中的字符变量ch)
a.f (引用共用体变量中的实型变量f)
共用体类型数据的特点:
同一个内存段可以用来存放几种不同类型的成员,但在每一瞬时只能存放其中一种,而不是同时存放几种。
共用体变量中起作用的成员是最后一次存放的成员,在存入一个新的成员后原有的成员就失去作用。
共用体变量的地址和它的各成员的地址都是同一地址。
不能对共用体变量名赋值,也不能企图引用变量名来得到一个值,又不能在定义共用体变量时对它初始化。
不能把共用体变量作为函数参数,也不能使函数带回共用体变量,但可以使用指向共用体变量的指针
共用体类型可以出现在结构体类型定义中,也可以定义共用体数组。反之,结构体也可以出现在共用体类型定义中,数组也可以作为共用体的成员。
应用情况:
设有若干个人员的数据,其中有学生和教师。学生的数据中包括:姓名、号码、性别、职业、班级。教师的数据包括:姓名、号码、性别、职业、职务。可以看出,学生和教师所包含的数据是不同的。现要求把它们放在同一表格中。
#include <stdio.h>struct
{int num;char name[10];char sex;char job;union{int banji;char position[10];}category;
}person[2];//为了方便先假设一个学生一个老师。void main()
{int i;//以下是输入数据for(i=0;i<2;i++){printf("Please input the num: ");scanf("%d",&person[i].num);printf("Please input the name: ");scanf("%s",person[i].name);fflush(stdin);//功能是清空输入缓冲区,为确保不影响后面的数据读取//例如在读完一个字符串后紧接着又要读取一个字符,此时应该先执行fflush(stdin);printf("Please input the sex(M/F): ");scanf("%c",&person[i].sex);fflush(stdin);printf("Please input the job(s/t): ");scanf("%c",&person[i].job);fflush(stdin);if(person[i].job == 's'){printf("Please input the class: ");scanf("%d",&person[i].category.banji);fflush(stdin);}else if(person[i].job == 't'){printf("Please input the position: ");scanf("%s",&person[i].category.position);fflush(stdin);}else{printf("Input Error!\n");}printf("\n");}//以下是输出数据printf("No. name sex job class/possition\n");for(i=0;i<2;i++){if(person[i].job == 's'){printf("%-6d%-10s%-3c%-3c%10d\n",person[i].num,person[i].name,person[i].sex,person[i].job,person[i].category.banji);}else{printf("%-6d%-10s%-3c%-3c%10s\n",person[i].num,person[i].name,person[i].sex,person[i].job,person[i].category.position);}}
}
枚举类型
在实际问题中,有些变量的取值被限定在一个有限的范围内。例如,一个星期内只有七天,一年只有十二个月,一个班每周有六门课程等等。如果把这些量说明为整型,字符型或其它类型显然是不妥当的。为此,C语言提供了一种称为“枚举”的类型。
枚举变量的声明
设有变量a,b,c被说明为上述的weekday,可采用下述任一种方式:
enum weekday{sun,mou,tue,wed,thu,fri,sat};
enum weekday a,b,c;
或
enum weekday{sun,mou,tue,wed,thu,fri,sat}a,b,c;
或
enum {sun,mou,tue,wed,thu,fri,sat}a,b,c;
枚举类型中需要注意的地方
在“枚举”类型的定义中列举出所有可能的取值,被说明为该“枚举”类型的变量取值不能超过定义的范围。
应该说明的是,枚举类型是一种基本数据类型,而不是一种构造类型,因为它不能再分解为任何基本类型。
在枚举值表中应罗列出所有可用值。这些值也称为枚举元素。
在C编译中,对枚举元素按常量处理,故称枚举常量。它们不是变量,不能对它们赋值。
枚举元素作为常量,它们是有值的,C语言编译按定义时的顺序使它们的值为0,1,2…
枚举值可以用来作判断比较。
一个整数不能直接赋给一个枚举变量。
实例:
#include <stdio.h>
void main()
{enum weekday{sun,mon,tue,wed,thu,fri,sat}a,b,c;a=sun;//a=1不行b=mon;c=tue;//自动赋值 0,1,2printf("%d,%d,%d",a,b,c);printf("\n\n");
}
#include<stdio.h>
void main()
{enum boy{Tom, Danny, Gan, Lilei }month[31],j;int i;j=Tom;for(i=1;i<=30;i++){month[i]=j;j++;if(j>Lilei){j=Tom;}}for(i=1;i<=30;i++){switch(month[i]){case Tom: printf("%d\t%s\t",i,"Tom");break;case Danny: printf("%d\t%s\t",i,"Danny");break;case Gan: printf("%d\t%s\t",i,"Gan");break;case Lilei: printf("%d\t%s\t",i,"Lilei");break;default:break;}}printf("\n");
}
用typedef定义类型
用typedef声明新的类型名来代替已有的类型名
声明INTEGER为整型
typedef int INTEGER
#include <stdio.h>typedef int INTEGER;void main()
{INTEGER i=1;int j=2;printf("%d,%d\n\n",i,j);
}
声明结构类型
Typedef struct{
int month;
int day;
int year;
}DATE;
#include <stdio.h>
typedef struct
{int month;int day;int year;
}DATE;void main()
{DATE date_one;date_one.month=12;date_one.day=31;date_one.year=2019;printf("%d - %d - %d \n",date_one.year,date_one.month,date_one.day);
}
声明NUM为整型数组类型
typedef int NUM[100];
#include <stdio.h>
typedef int NUM[100];void main()
{NUM num={0};printf("%d\n\n",sizeof(num));
}
声明STRING为字符指针类型
typedef char* STRING;
#include <stdio.h>
typedef char* P;
void main()
{P p1;p1="I love csdn.net";printf("%s\n",p1);
}
声明 POINTER 为指向函数的指针类型,该函数返回整型值。
typedef int (*POINTER)();
#include <stdio.h>
typedef int(*P)();void fun();
void fun()
{printf("I love csdn!\n");
}void main()
{P p1;//声明p1指针,类型是int(*p1)();p1=fun;//p1=&fun;也对//即函数名称就是函数的地址(p1)();
}
用typedef定义类型的方法
先按定义变量的方法写出定义体(如:int i)
将变量名换成新类型名(例如:将i换成COUNT)。
在最前面加typedef(例如:typedef int COUNT)
然后可以用新类型名去定义变量(例如:COUNT i, j;)
关于 typedef的一些说明
用typedef 可以声明各种类型名,但不能用来定义变量。
用typedef 只是对已经存在的类型增加一个类型名,而没有创造新的类型。
当不同源文件中用到同一类型数据时,常用typedef 声明一些数据类型,把它们单独放在一个文件中,然后在需要用到它们的文件中用#include命令把它们包含进来。
使用typedef 有利于程序的通用与移植。
typedef与#define有相似之处,例如:typedef int COUNT;#define COUNT int 的作用都是用COUNT 代表 int。但是,它们二者是不同的。
#define是在预编译时处理的,它只能作简单的字符串替换,而typedef是在编译时处理的。实际上它并不是作简单的字符串替换,而是采用如同定义变量的方法那样来声明一个类型。
区别: typedef 和 define
typedef (int*) p1; 是语句
和
#define p2 int* 是命令
另外注意,一个有分号,一个没有分号!
C语言-结构体与共用体相关推荐
- C语言之结构体和共用体
C语言之结构体和共用体 算上这篇笔记加上之前的四篇笔记,C语言基础我们也就告一段落了,对于刚刚接触c语言的童鞋们来说,这些以及足够了,稍后我会发布数据结构,对于想要深入学习的童鞋可以继续关注.本人也算 ...
- 【C语言】结构体、共用体、位域
结构体 1. 结构体的声明方法 struct struct_name {data_type member1;data_type member2;.. }; 这是其中一种声明方式~ 2.定义一个结构体变 ...
- C语言入门系列之10.结构体和共用体
文章目录 一.结构体变量的基本使用 1.概述 2.定义结构体类型变量的方法 3.结构体变量的引用 4.结构体变量的初始化 二.结构体的高级应用 1.结构体数组 Ⅰ定义结构体数组 Ⅱ结构体数组的初始化 ...
- C语言结构体与共用体03
小甲鱼结构体与共用体03 实战例题:有一个结构体变量stu,内含学生学号.姓名和3门课程的成绩.通过调用函数print将它们输出. ①先用结构体变量作函数参数: //先用结构体变量作函数参数 #inc ...
- 江哥带你玩转C语言 | 14 - 结构体-枚举-共用体
什么是结构体 结构体和数组一样属于构造类型 数组是用于保存一组相同类型数据的, 而结构体是用于保存一组不同类型数组的 例如,在学生登记表中,姓名应为字符型;学号可为整型或字符型;年龄应为整型;性别应为 ...
- 结构体与共用体05 - 零基础入门学习C语言57
第十章:结构体与共用体05 让编程改变世界 Change the world by program 对链表结点的删除操作实现 实现源代码: [codesyntax lang="c" ...
- 结构体与共用体07 - 零基础入门学习C语言59
第十章:结构体与共用体07 让编程改变世界 Change the world by program 用typedef定义类型 用typedef声明新的类型名来代替已有的类型名 声明INTEGER为 ...
- 结构体与共用体C语言
结构体与共用体 结构体的定义 引例 比如学生是一个整体,学生有姓名.性别.学号--我们更希望把一个事物整体的操作 自定义数据类型 基础数据类型是电脑定义好了的,默认的数据类型 自定义数据类型意义:需要 ...
- C语言——结构体、共用体
结构体.共用体 1.结构体 基础知识 代码基本写法 内存对齐 2. 共用体 引论 定义 基础写法 共用体大小 1.结构体 基础知识 类似于Java中的javaBean,可以将一些变量封装成一些对象.同 ...
最新文章
- 知道了05后的隐藏技能之后,我酸了…​
- 导入CSS的三种方式
- mysql和php的登录注册界面_php实现注册和登录界面的方法
- 1044 拦截导弹——http://codevs.cn/problem/1044/
- 算法导论——优先队列(大到小)
- python opencv cv2.cvtColor()方法(将图像从一种颜色空间转换为另一种颜色空间)(转换成灰度图)
- java xpath 解析xml_使用XPATH解析XML文件
- 查询某字段不重复记录的SQL语句
- 2000条你应知的WPF小姿势 基础篇40-44 启动关闭,Xaml,逻辑树
- javascript轮播图超详细
- python制作微信聊天机器人:10行代码让你秒变撩妹达人
- 各大主流社交软件显示ip地址-如何实现ip飘移
- C++四书五经_完整版(侯捷)
- 3步上架iOS APP【2022最新教程】
- 芝士合集(以便查看)
- JavaSE 接口与内部类
- ArcGIS server如何将自己的小地图叠加到Google maps或者Virtual Earth上
- NOJ 2015年陕西省程序设计竞赛网络预赛(正式赛)(小女警的异世界之战-前序中序求后序)
- 高屋建瓴之WebMail攻与防
- Dicom 图像--像素值(灰度值)转为CT值