Expert C Programming

(Jeff_L) #1

Check Those Bit Patterns


Write a one-liner to check whether or not the bit pattern for floating point 0.0 is the same as
integer zero on your system.


Here's how you initialize a two-dimensional array of strings:


char vegetables[][9] = { "beet",


"barley",


"basil",


"broccoli",


"beans" };


One useful facility is to set up an array of pointers. String literals can be used as array initializers, and
the compiler will correctly store the addresses in the array. Thus,


char *vegetables[] = { "carrot",


"celery",


"corn",


"cilantro",


"crispy fried potatoes" }; /* works


fine */


Notice how the initialization part is identical to the array of arrays of characters initialization. Only
string literals have this privilege of initializing pointer arrays. Arrays of pointers can't be directly
initialized with non-string types:


int weights[] = { / will NOT compile successfully


*/


{1,2,3,4,5},


{6,7},


{8,9,10}


}; /* will NOT compile successfully


*/


The secret to doing this kind of initialization is to create the rows as individual arrays, and use those
array names to initialize the original array.


int row_1[] = {1,2,3,4,5,-1}; / -1 is end-of-row marker /

Free download pdf