1判断结构体所占空间大小 2两种判断大小端存储的方式 3完善顺序表创建

文章探讨了不同数据类型的结构体在32位和64位环境下的空间占用,比较了大小端存储方式,并展示了顺序表的创建、判断满/空以及插入和删除操作。
摘要由CSDN通过智能技术生成

 结构体空间计算

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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值