结构体空间计算
64位/32位
struct data{
char t1;
char t2;
unsigned short t3;
unsigned long t4;
}; 16 /8
struct data{
char t1;
int t2;
short t3;
}; 12 /12
struct s1 {
char c1;
int i;
char c2;
};12 /12
struct s2 {
char c1;
char c2;
int i;
};8 /8
typedef struct Test
{
short a;
struct {
int b;
double c;
char d;
}p;
int e;
}Test; 40/24
typedef struct Test
{
short a;
struct {
int b;
double c[10];
char d;
};
int e;
}Test;112 /96
struct C{
char b;
int a;
short c;
}; 12 /12
struct C {
char a;
char b[3];
char c;
}; 5 /5
typedef struct
{
int b;
char a;
long e;
char c;
float d;
double t;
}node; 32 /28
验证大小端存储
用数据截断
int main(int argc, const char *argv[])
{
int a=0x12345678;
char*p=(char*)&a;
if(*p==0x78){
printf("小端存储\n");
}else printf("大端存储\n");
return 0;
}
用共用体
typedef union{
char c;
int i;
}jud;
int main(int argc, const char *argv[])
{
jud a;
a.i=0x12345678;
if(a.c==0x78){
printf("小端存储\n");
}else printf("大端存储\n");
return 0;
}
3完善顺序表
seq_p create_seqlist(){
seq_p seq=(seq_p)malloc(sizeof(struct seqlist));
if(seq==NULL){
return NULL;
}
seq->len=0;
memset(seq,0,sizeof(seq->data));
return seq;
}
bool full_jud(seq_p seq){
return seq->len==MAXSIZE?true :false;
}
bool empty_jud(seq_p seq){
return seq->len==0?true:false;
}
int add_seq(seq_p seq,datatype key){
if(full_jud(seq)==true)return -1;
seq->data[seq->len++]=key;
return 0;
}
void output(seq_p seq){
if(empty_jud(seq)==true)return ;
for(int i=0;i<seq->len;i++){
printf("%d\t",seq->data[i]);
}
putchar(10);
return ;
}
int del_seq(seq_p seq){
if(empty_jud(seq)==true)return -1;
seq->data[seq->len--]=0;
return 0;
}