8.1 |
a) address. b) 0, NULL, an address. c)0.
|
8.2 |
- False. The operand of the address operator must be an lvalue; the address operator cannot be applied to constants or to expressions that do not result in references.
- False. A pointer to void cannot be dereferenced. Such a pointer does not have a type that enables the compiler to determine the number of bytes of memory to dereference and the type of the data to which the pointer points.
- False. Pointers of any type can be assigned to void pointers. Pointers of type void can be assigned to pointers of other types only with an explicit type cast.
|
8.3 |
- double numbers[ SIZE ] = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };
- double *nPtr;
-
cout << fixed << showpoint << setprecision( 1 );
for ( int i = 0; i < SIZE; i++ )
cout << numbers[ i ] <<' ';
-
nPtr = numbers;
nPtr = &numbers[ 0 ];
-
cout << fixed << showpoint << setprecision( 1 );
for ( int j = 0; j < SIZE; j++ )
cout << *( nPtr + j ) << ' ';
-
cout << fixed << showpoint << setprecision( 1 );
for ( int k = 0; k < SIZE; k++ )
cout << *( numbers + k ) << ' ';
-
cout << fixed << showpoint << setprecision( 1 );
for ( int m = 0; m < SIZE; m++ )
cout << nPtr[ m ] << ' ';
-
numbers[ 3 ]
*( numbers + 3 )
nPtr[ 3 ]
*( nPtr + 3 )
- The address is 1002500 + 8 * 8 = 1002564. The value is 8.8.
- The address of numbers[ 5 ] is 1002500 + 5 * 8 = 1002540.
The address of nPtr -= 4 is 1002540 - 4 * 8 = 1002508.
The value at that location is 1.1.
|
8.4 |
- double *fPtr;
- fPtr = &number1;
- cout << "The value of *fPtr is " << *fPtr << endl;
- number2 = *fPtr;
- cout << "The value of number2 is " << number2 << endl;
- cout << "The address of number1 is " << &number1 << endl;
- cout << "The address stored in fPtr is " << fPtr << endl;
Yes, the value is the same.
- strcpy( s1, s2 );
- cout << "strcmp(s1, s2) = " << strcmp( s1, s2 ) << endl;
- strncat( s1, s2, 10 );
- cout << "strlen(s1) = " << strlen( s1 ) << endl;
- ptr = strtok( s2, "," );
|
8.5 |
- void exchange( double *x, double *y )
- void exchange( double *, double * );
- int evaluate( int x, int (*poly)( int ) )
- int evaluate( int, int (*)( int ) );
- char vowel[] = "AEIOU";
char vowel[] = { 'A', 'E', 'I', 'O', 'U', ' |