Perhaps char myarr[16]={0x00};
isn't a good example to begin with, since both the explicit and implicit member initializations use zeros, making it harder to explain what's happening in that situation. I thought that a real-life example, with non-zero values could be more illustrative:
/**
* Map of characters allowed in a URL
*
* !, \, (, ), *, -, ., 0-9, A-Z, _, a-z, ~
*
* Allowed characters are set to non-zero (themselves, for easier tracking)
*/
static const char ALLOWED_IN_URL[256] = {
/* 0 1 2 3 4 5 6 7 8 9*/
/* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 30 */ 0, 0, 0, '!', 0, 0, 0, 0, 0, '\'',
/* 40 */ '(', ')', '*', 0, 0, '-', '.', 0, '0', '1',
/* 50 */ '2', '3', '4', '5', '6', '7', '8', '9', 0, 0,
/* 60 */ 0, 0, 0, 0, 0, 'A', 'B', 'C', 'D', 'E',
/* 70 */ 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
/* 80 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
/* 90 */ 'Z', 0, 0, 0, 0, '_', 0, 'a', 'b', 'c',
/* 100 */ 'd', 'e', 'f', 'g' , 'h', 'i', 'j', 'k', 'l', 'm',
/* 110 */ 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
/* 120 */ 'x', 'y', 'z', 0, 0, 0, '~',
};
This is a lookup table that can be used when URL-encoding a string. Only the characters that are allowed in a URL are set to a non-zero value. A zero means that the character is not allowed and needs to be URL-encoded (%xx
). Notice that the table abruptly ends with a comma after the tilde character. None of the characters following the tilde are allowed and so should be set to zero. But instead of writing many more zeros to fill the table up to 256 entries, we let the compiler implicitly initialize the rest of the entries to zero.