lets say I have this
char *something[] = {
"/bi",
"-c",
"5",
NULL,
NULL
};
but I want to declare it in hex, how 开发者_Go百科would I do this; compiler keeps erroring out on me:
char *something[] = {
{0x2f,0x62,0x69},
{0x2d,0x63},
{0x35},
{0x00},
{0x00}
};
to add something else to this, is 0x00 ALWAYS null? does 0x00 always translate to NULL on systems where NULL is -1 for example?
You can use hexadecimal escape sequences within a string literal. For example:
char *something[] = {
"\x2f\x62\x69",
"\x2d\x63"
};
To answer your question about NULL
and the null pointer: the macro NULL
is always 0. The compiler then converts that to an appropriate null pointer. The comp.lang.c FAQ has an entire section explaining this more thoroughly.
精彩评论