User`s manual

Dynamic C Users Manual digi.com 243
13.10 Other Operators
The cast operator converts one data type to another. A floating-point value is truncated when converted
to integer. The bit patterns of character and integer data are not changed with the cast operator, although
high-order bits will be lost if the receiving value is not large enough to hold the converted value.
unsigned i; float x = 10.5; char c;
i = (unsigned)x; // i gets 10;
c = *(char*)&x; // c gets the low byte of x
typedef ... typeA;
typedef ... typeB;
typeA item1;
typeB item2;
...
item2 = (typeB)item1; // forces item1 to be treated as a typeB
The sizeof operator is a unary operator that returns the size (in bytes) of a variable, structure, array, or
union. It operates at compile time as if it were a built-in function, taking an object or a type as a parameter.
typedef struct{
int x;
char y;
float z;
} record;
record array[100];
int a, b, c, d;
char cc[] = "Fourscore and seven";
char *list[] = { "ABC", "DEFG", "HI" };
#define array_size sizeof(record)*100 // number of bytes in array
a = sizeof(record); // 7
b = array_size; // 700
c = sizeof(cc); // 20
d = sizeof(list); // 6
Why is
sizeof(list) equal to 6? list is an array of 3 pointers (to char) and pointers have two
bytes.
Why is sizeof(cc) equal to 20 and not 19? C strings have a terminating null byte appended by the
compiler.
(type)
sizeof