www.gibmonks.com

Main Page




Previous Page
Next Page

[Page 1099 (continued)]

Summary

  • Structures are collections of related variables (or aggregates) under one name.

  • Structures can contain variables of different data types.

  • Keyword struct begins every structure definition. Between the braces of the structure definition are the structure member declarations.

  • Members of the same structure must have unique names.

  • A structure definition creates a new data type that can be used to declare variables.

  • A structure can be 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 members in the structure, the remaining members are initialized to zero (or a null pointer for pointer members).

  • Entire structure variables may be assigned to structure variables of the same type.

  • A structure variable may be initialized with a structure variable of the same type.

  • Structure variables and individual structure members are passed to functions by value.

  • To pass a structure by reference, pass the address of the structure variable or a reference to the structure variable. An array of structures is passed by reference. To pass an array by value, create a structure with the array as a member.

  • Creating a new type name with typedef does not create a new type; it creates a name that is synonymous with a type defined previously.

  • The bitwise AND operator (&) takes two integral operands. A bit in the result is set to one if the corresponding bits in each of the operands are one.

  • Masks are used with bitwise AND to hide some bits while preserving others.

  • The bitwise inclusive-OR operator (|) takes two operands. A bit in the result is set to one if the corresponding bit in either operand is set to one.

  • Each of the bitwise operators (except complement) has a corresponding assignment operator.

  • The bitwise exclusive-OR operator (^) takes two operands. A bit in the result is set to one if exactly one of the corresponding bits in the two operands is set to one.

  • 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 zeros.

  • The right-shift operator (>>) shifts the bits of its left operand right by the number of bits specified in its right operand. Performing a right shift on an unsigned integer causes bits vacated at the left to be replaced by zeros. Vacated bits in signed integers can be replaced with zeros or onesthis is machine dependent.

  • The bitwise complement operator (~) takes one operand and inverts its bitsthis produces the one's complement of the operand.


  • [Page 1100]
  • Bit fields reduce storage use by storing data in the minimum number of bits required. Bit-field 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.

  • The bit-field width must be an integer constant.

  • If a bit field is specified without a name, the field is used as padding in the structure.

  • An unnamed bit field with width 0 aligns the next bit field on a new machine-word boundary.

  • Function islower determines whether its argument is a lowercase letter (az). Function isupper determines whether its argument is an uppercase letter (AZ).

  • Function isdigit determines whether its argument is a digit (09).

  • Function isalpha determines whether its argument is an uppercase (AZ) or lowercase letter (a-z).

  • Function isalnum determines whether its argument is an uppercase letter (AZ), a lowercase letter (az), or a digit (0-9).

  • Function isxdigit determines whether its argument is a hexadecimal digit (AF, a-f, 0-9).

  • Function toupper converts a lowercase letter to an uppercase letter. Function tolower converts an uppercase letter to a lowercase letter.

  • Function isspace determines whether its argument is one of the following white-space characters: ' ' (space), '\f', '\n', '\r', '\t' or '\v'.

  • Function iscntrl determines whether its argument is a control character, such as '\t', '\v, '\f', '\a', '\b', '\r' or '\n'.

  • Function ispunct determines whether its argument is a printing character other than a space, a digit or a letter.

  • Function isprint determines whether its argument is any printing character, including space.

  • Function isgraph determines whether its argument is a printing character other than space.

  • Function atof converts its argumenta string beginning with a series of digits that represents a floating-point numberto a double value.

  • Function atoi converts its argumenta string beginning with a series of digits that represents an integerto an int value.

  • Function atol converts its argumenta string beginning with a series of digits that represents a long integerto a long value.

  • Function strtod converts a sequence of characters representing a floating-point value to double. The function receives two argumentsa string (char *) and the address of a char * pointer. The string contains the character sequence to be converted, and the pointer to char * is assigned the remainder of the string after the conversion.

  • Function strtol converts a sequence of characters representing an integer to long. The function receives three argumentsa string (char *), the address of a char * pointer and an integer. The string contains the character sequence to be converted, the pointer to char * is assigned the location of the first character after the converted value and the integer specifies the base of the value being converted.

  • Function strtoul converts a sequence of characters representing an integer to unsigned long. The function receives three argumentsa string (char *), the address of a char * pointer and an integer. The string contains the character sequence to be converted, the pointer to char * is assigned the location of the first character after the converted value and the integer specifies the base of the value being converted.


  • [Page 1101]
  • Function strchr searches for the first occurrence of a character in a string. If the character is found, strchr returns a pointer to the character in the string; otherwise, strchr returns a null pointer.

  • Function strcspn determines the length of the initial part of the string in its first argument that does not contain any characters from the string in its second argument. The function returns the length of the segment.

  • Function strpbrk searches for the first occurrence in its first argument of any character that appears in its second argument. If a character from the second argument is found, strpbrk returns a pointer to the character; otherwise, strpbrk returns a null pointer.

  • Function strrchr searches for the last occurrence of a character in a string. If the character is found, strrchr returns a pointer to the character in the string; otherwise, it returns a null pointer.

  • Function strspn determines the length of the initial part of the string in its first argument that contains only characters from the string in its second argument and returns the length of the segment.

  • Function strstr searches for the first occurrence of its second string argument in its first string argument. If the second string is found in the first string, a pointer to the location of the string in the first argument is returned; otherwise it returns 0.

  • Function memcpy copies a specified number of characters from the object to which its second argument points into the object to which its first argument points. The function can receive a pointer to any object. The pointers are received by memcpy as void pointers and converted to char pointers for use in the function. Function memcpy manipulates the bytes of its argument as characters.

  • Function memmove copies a specified number of bytes from the object pointed to by its second argument to the object pointed to by its first argument. Copying is accomplished as if the bytes were copied from the second argument to a temporary character array, and then copied from the temporary array to the first argument.

  • Function memcmp compares the specified number of characters of its first and second arguments.

  • Function memchr searches for the first occurrence of a byte, represented as unsigned char, in the specified number of bytes of an object. If the byte is found, a pointer to it is returned; otherwise, a null pointer is returned.

  • Function memset copies its second argument, treated as an unsigned char, to a specified number of bytes of the object pointed to by the first argument.


Previous Page
Next Page