(Find the Error) Find the error in each of the following program segments and explain how to correct it:

a) ```
float cube( float ); // function prototype
cube( float number ) // function definition
{
return number * number * number;
}
```
b) ```
register auto int x = 7;
```
c) ```
int randomNumber = srand();
```
d) ```
float y = 123.45678;
int x;
```
e) ```
double square( double number )
{
double number;
return number * number;
}
```
f) ```
int sum( int n )
{
if ( n == 0 )
return 0;
else
return n + sum( n );
}
```


a) Error: The function definition defaults to a return type of int.
Correction: Specify a return type of float for the function definition.
b) Error: Only one storage class specifier can be used.
Correction: Remove either register or auto.
c) Error: Function srand takes an unsigned argument and does not return a value.
Correction: Use rand instead of srand.
d) Error: Variable number is declared twice.
Correction: Remove the declaration of variable number within the {}.
f) Error: Infinite recursion.
Correction: Change sum( n ) to sum( n - 1 ).

Computer Science & Information Technology

You might also like to view...

Consider the code segment below. Which of the following statements is false?

Dim array(5) As Integer a) The first statement declares an array reference. b) The second statement creates the array. c) array is a reference to an array of integers. d) The value of array( 3 ) is -1.

Computer Science & Information Technology

Which of the following statements is true?

a. Class Matcher provides methods find, lookingAt, replaceFirst and replaceAll. b. Method matches (from class String, Pattern or Matcher) will return true only if the entire search object matches the regular expression. c. Methods find and lookingAt (from class Matcher) will return true if a portion of the search object matches the regular expression. d. All of the above.

Computer Science & Information Technology

To get an accurate view of SQL Server performance using SQL Server Activity Monitor without affecting overall system performance, how often should the server be polled?

A. 10 times/second B. 1 time/second C. 1 time/10 seconds D. 10 times/minute

Computer Science & Information Technology

Java was originally developed for:

a. Operating systems development. b. Intelligent consumer devices. c. Personal computers. d. Distributed computing.

Computer Science & Information Technology