---
title: "快速判断处理器大小端模式"
author: "steven-zhou"
date: "2008-10-30T10:24:17Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2008-12-15T16:58:37Z"
id: 259936
url: "https://stevenos.iteye.com/blog/259936"
---

```C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    int i = 1;
    char *cp = (char *)&i;
    if (*cp) //如果此时cp指向的内存为1的话，则为小端，否则为大端。
        printf("Little Endian\n");
    else 
        printf("Big Endian\n");

    exit(EXIT_SUCCESS);
}

```