方法一:
#include <stdio.h>
int check_sys()
{
int i = 1;
int *p = &i;
char *q = (char *)p;
if (*q == 1)
{
return 0;
}
else
{
return 1;
}
}
int main()
{
int ret = check_sys();
if (ret == 1)
{
printf("big\n");
}
else
{
printf("little\n");
}
return 0;
}
//方法二:利用联合的特点
#include <stdio.h>
check_sys()
{
union UN
{
char c;
int i;
}un;
un.i = 1;
if (un.c == 1)
{
return 0;
}
else
{
return 1;
}
}
int main()
{
int ret = check_sys();
if (ret == 1)
{
printf("big\n");
}
else
{
printf("little\n");
}
return 0;
}
时间: 2024-10-11 19:16:29