Summary

Section 22.2 Structure Definitions

  • Keyword struct (p. 900) begins every structure definition. Between the braces of the structure definition are the structure member declarations.

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

Section 22.3 typedef and using

  • Creating a new type name with typedef (p. 902) does not create a new type; it creates a name that’s synonymous with a type defined previously.

  • C++11 added the keyword using as another mechanism for creating type aliases.

Section 22.5 Bitwise Operators

  • The bitwise AND operator (&; p. 905) 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 (p. 907) are used with bitwise AND to hide some bits while preserving others.

  • The bitwise inclusive OR operator (|; p. 905) 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 (^; p. 905) 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 (<<; p. 905) 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 (>>; p. 905) shifts the bits of its left operand right by the number of bits specified in its right operand. Right shifting 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 ones.

  • The bitwise complement operator (~; p. 905) takes one operand and inverts its bits—this produces the one’s complement of the operand.

  • As of C++14, you may now include binary literals in your source code. To do so, precede a sequence of 1s and 0s with 0b or 0B.

Section 22.6 Bit Fields

  • Bit fields (p. 914) 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 (p. 917) in the structure.

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

Section 22.7 Character-Handling Library

  • Function islower (p. 920) determines if its argument is a lowercase letter (a–z). Function isupper (p. 920) determines whether its argument is an uppercase letter (A–Z).

  • Function isdigit (p. 918) determines if its argument is a digit (0–9).

  • Function isalpha (p. 918) determines if its argument is an uppercase (A–Z) or lowercase letter (a–z).

  • Function isalnum (p. 918) determines if its argument is an uppercase letter (A–Z), a lowercase letter (a–z), or a digit (0–9).

  • Function isxdigit (p. 918) determines if its argument is a hexadecimal digit (A–F, a–f, 0–9).

  • Function toupper (p. 920) converts a lowercase letter to an uppercase letter. Function tolower (p. 920) converts an uppercase letter to a lowercase letter.

  • Function isspace (p. 921) determines if its argument is one of the following whitespace characters: ' ' (space), 'f', ' ', ' ', ' ' or 'v'.

  • Function iscntrl (p. 921) determines if its argument is a control character, such as ' ', 'v', 'f', 'a', '', ' ' or ' '.

  • Function ispunct (p. 921) determines if its argument is a printing character other than a space, a digit or a letter.

  • Function isprint (p. 921) determines if its argument is any printing character, including space.

  • Function isgraph (p. 921) determines if its argument is a printing character other than space.

Section 22.8 C String-Manipulation Functions

  • Function strcpy (p. 924) copies its second argument into its first argument. You must ensure that the target array is large enough to store the string and its terminating null character.

  • Function strncpy (p. 924) is equivalent to strcpy, but it specifies the number of characters to be copied from the string into the array. The terminating null character will be copied only if the number of characters to be copied is at least one more than the length of the string.

  • Function strcat (p. 925) appends its second string argument—including the terminating null character—to its first string argument. The first character of the second string replaces the null ('') character of the first string. You must ensure that the target array used to store the first string is large enough to store both the first string and the second string.

  • Function strncat (p. 925) is equivalent to strcat, but it appends a specified number of characters from the second string to the first string. A terminating null character is appended to the result.

  • Function strcmp compares its first string argument with its second string argument character by character. The function returns zero if the strings are equal, a negative value if the first string is less than the second string and a positive value if the first string is greater than the second string.

  • Function strncmp is equivalent to strcmp, but it compares a specified number of characters. If the number of characters in one of the strings is less than the number of characters specified, strncmp compares characters until the null character in the shorter string is encountered.

  • A sequence of calls to strtok (p. 928) breaks a string into tokens that are separated by characters contained in a second string argument. The first call specifies the string to be tokenized as the first argument, and subsequent calls to continue tokenizing the same string specify NULL as the first argument. The function returns a pointer to the current token from each call. If there are no more tokens when strtok is called, NULL is returned.

  • Function strlen (p. 929) takes a string as an argument and returns the number of characters in the string—the terminating null character is not included in the length of the string.

Section 22.9 C String-Conversion Functions

  • Function atof (p. 931) converts its argument—a string beginning with a series of digits that represents a floating-point number—to a double value.

  • Function atoi (p. 931) converts its argument—a string beginning with a series of digits that represents an integer—to an int value.

  • Function atol (p. 932) converts its argument—a string beginning with a series of digits that represents a long integer—to a long value.

  • Function strtod (p. 932) converts a sequence of characters representing a floating-point value to double. The function receives two arguments—a 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 (p. 933) converts a sequence of characters representing an integer to long. It receives a 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 (p. 934) converts a sequence of characters representing an integer to unsigned long. It receives a 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.

Section 22.10 Search Functions of the C String-Handling Library

  • Function strchr (p. 935) searches for the first occurrence of a character in a string. If found, strchr returns a pointer to the character in the string; otherwise, strchr returns a null pointer.

  • Function strcspn (p. 936) 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 (p. 937) 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 (p. 937) 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 (p. 938) determines the length of the initial part of its first argument that contains only characters from the string in its second argument and returns the length of the segment.

  • Function strstr (p. 939) 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.

Section 22.11 Memory Functions of the C String-Handling Library

  • Function memcpy (p. 940) 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 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 (p. 941) 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, then copied from the temporary array to the first argument.

  • Function memcmp (p. 941) compares the specified number of characters of its first and second arguments.

  • Function memchr (p. 942) 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 (p. 943) copies its second argument, treated as an unsigned char, to a specified number of bytes of the object pointed to by the first argument.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset