How to write a program to find endianess of a machine ?

#include <stdio.h>
#include <stdlib.h>

static inline int little_endian() {
int endian = 1;
return (0 == (*(char *)&endian));
}

int main (int argc, char **argv)
{

printf("This machine is ");
little_endian() ? printf("little") : printf("big");
printf(" endian\n");

exit(0);
}