Chapter 16 Bits, characters, string, and structures 1. Structures are collections of related variables, sometimes referred to as aggregates, under one name. 2. Structures can contain variables of different types. 3. The keyword struct begins every structure definition. Within the braces of the structure definition are the structure member declaration. 4. Members of the same structure must have unique names. 5. A structure definition creates a new data type that can be used to decalre variables. 6. A structure can initialized with an initializer list by following the variable in the declaration with an equal sign and a comma-separated list of initializers enclosed in braces. If there are fewer initializers in the list than the members in the structure, the remaining members are automatically initilized to zero (or NULL for pointer members). 7. Entire structure variables may be assigned to structure variables of the same type. 8. A structure variable may be initilized with a structure variable of the same type. 9. Structure variables and individual structure members are passed to functions call-by-value. Array members are, of course, passed-by-reference. 10. To pass a structure call-by-reference, pass the address of the structure variable. 11. A array of structure is automatically passed-by-reference. 12. To pass an array call-by-value, create a structure with the array as a member. 13. Create a new name with typedef does not create a new type; it create a name that is synonymous to a type defined previously. 14. The bitwise AND operator (&) takes two integral opeands. A bit in the result is set to 1 if the corresponding bits in each of the operands are 1. 15. The bitwise OR operator (|) takes two integral opeands. A bit in the result is set to 1 if either one of the corresponding bits in each of the operands is 1. 16. The bitwise exclusive OR operator (^) takes two operands. A bit in the result is set to 1 if exactly one of the corresponding bits in the two operands is 1. 17. The left shift operator (<<) shifts the bits of its left operand left by the number of bits specified by its right operand. Bits vacated to the right are replaced with 0s. 18. The right shift operator (>>) shifts the bits of its left operand right by the number of bits specified by its right operand. Bits vacated to the left are replaced with 0s if it is unsigned integer, otherwise it can be replaced by sign bit or 0s depend on machine. 19. The bitwise complement operator (~) takes one operand and reverses its bits -- this produces the one's complement of the operand. 20. Bit fields members must be declared as int or unsigned. A bit field is declared by following an unsigned or int member name with a colon and the width of the bit field. 21. An unsigned bit field with width 0 is used to align the next bit field on a new machine word boundary. 22. The following convertion functions are useful: islower isupper isdigit isalpha isalnum isxdigit toupper tolower isspace iscntrl ispunct isgraph ato atoi atol strtod strtol strtoul strchr strcspn strpbrk strrchr strspn strstr memcpy memmove memmp memchr memset strerror 23. Provide a structure name when creating a structure type. The structure name is convenient for declaring new variables of the sturcture type later in the program and is required if the structure will be passed as a parameter to a function. 24. Capitalize typedef name to emphasize that these names are synonyms for other type names. 25. Although the bit fields save space, using them can ause the compiler to generate slower executing machine language code. This occurs because it takes extra machine instructions to access only portions of an addressable storage unit. This is one of the many space-time tradeoffs that occur in computer science.