www.gibmonks.com

Main Page




Previous Page
Next Page

[Page 1103 (continued)]

Answers to Self-Review Exercises

22.1

a) structure. b) bitwise AND (&). c) members. d) bitwise inclusive-OR (|). e) struct. f) typedef. g) bitwise exclusive-OR (^). h) mask. i) structure member (.), structure pointer (->). j) left-shift operator (<<), right-shift operator (>>).

22.2

  1. False. A structure can contain many data types.

  2. False. The members of separate structures can have the same names, but the members of the same structure must have unique names.


  3. [Page 1104]
  4. False. typedef is used to define aliases for previously defined data types.

  5. False. Structures are passed to functions by value by default and may be passed by reference.

22.3

  1.  struct Part
     {
        int partNumber;
        char partName[ 26 ];
     };
    

  2. typedef part * partptr

  3. Part a;
    Part b[ 10 ];
    Part *ptr;
    

  4. cin >> a.partNumber >> a.partName;

  5. b[ 3 ] = a;

  6. ptr = b;

  7. cout << ( ptr + 3 )->partNumber << ' '
         << ( ptr + 3 )->partName << endl;
    

22.4

  1. Error: The parentheses that should enclose *cPtr have been omitted, causing the order of evaluation of the expression to be incorrect.

  2. Error: The array subscript has been omitted. The expression should be hearts[ 10 ].face.

  3. Error: A semicolon is required to end a structure definition.

  4. Error: Variables of different structure types cannot be assigned to one another.

22.5

  1. c = toupper( c );

  2. cout << '\'' << c << "\' "
         << ( isdigit( c ) ? "is a" : "is not a" )
          << " digit" << endl;
    
  3. cout << atol( "1234567" ) << endl;
    
  4. cout << '\'' << c << "\' "
         << ( iscntrl( c ) ? "is a" : "is not a" )
          << " control character" << endl;
    
  5. ptr = strrchr( s1, c );
    
  6. out << atof( "8.63582" ) << endl;
    
  7. cout << '\'' << c << "\' "
          << ( isalpha( c ) ? "is a" : "is not a" )
          << " letter" << endl;
    
  8. ptr = strstr( s1, s2 );
    
  9. cout << '\'' << c << "\' "
          << ( isprint( c ) ? "is a" : "is not a" )
          << " printing character" << endl;
    
  10. ptr = strpbrk( s1, s2 );
    
  11. ptr = strchr( s1, c );
    
  12. cout << atoi( "-21" ) << endl;
    


Previous Page
Next Page