1.
2
.
#include <stdio.h>
#include <string.h>
union Store
{
char p;
int a;
};
int main(int argc, const char *argv[])
{
union Store A;
A.a=0x12345678;
printf("%#X\n",A.a);
printf("%#X\n",A.p);
printf("%p\n",&A.p);
printf("%p\n",&A.p+3);
char *p1=&A.a;
printf("%#X\n",*p1);
printf("%p\n",p1);
printf("%p\n",p1+3);
return 0;
}
3
#include<stdio.h>
#include<string.h>
#include"seq.h"
int main(int argc, const char *argv[])
{
seq_p L=create_seq_list();
printf("%d\n",seq_empty(L));
printf("%d\n",seq_full(L));
return 0;
}
ubuntu@ubuntu:seq_list$ cat seq.c
#include<stdio.h>
#include<string.h>
#include"seq.h"
seq_p create_seq_list()
{
seq_p L=(seq_p)malloc(sizeof(seq));
if(L==NULL)
{
printf("空间申请失败\n");
return 0;
}
L->len=0;
bzero(L,sizeof(L->data));
return L;
}
int seq_empty(seq_p L)
{
if(L==NULL)
{
return -1;
}
return *(L->data)==0?1:0;
}
int seq_full(seq_p L)
{
if(L==NULL)
{
return -1;
}
return *(L->data+MAX-1)!=0?1:0;
}
ubuntu@ubuntu:seq_list$ cat seq.h
#ifndef __SEQ_H__
#define __SEQ_H__
#include <stdlib.h>
#define MAX 7
typedef int datatype;
typedef struct seq_list
{
datatype data[MAX];
int len;
}seq,*seq_p;
seq_p create_seq_list();
int seq_empty(seq_p L);
int seq_full(seq_p L);
#endif