double cube( double x ) { return( x * x * x ); } |
The parameter specification
double x |
is actually a declaration.
It's somewhat like the construct:
extern double x |
Example:
Array definition: int a[10]; // SIZE is required // in array definition Array declaration: extern int a[]; or: extern int a[10]; |
int sum( int a[10] ) { int s = 0; for ( i = 0; i < 10; i++ ) s = s + a[i]; } |
int sum( int a[] ) // No size info !!! { int s = 0; for ( i = 0; i < 10; i++ ) s = s + a[i]; } |
This is only allowed when the array variable (a) is declared !!!
int main ( int argc, char * argv[] ) { ... } |
|
In the figure above, we see that:
argv[0] points to the string "Hello" argv[1] points to the string "World" |
int main(int argc, char *argv[]) { int i; for ( i = 0; i < argc; i++ ) cout << "argv[" << i << "] = " << argv[i] << endl; } |
int Integer.parseInt( String s ); double Double.parseDouble( String s ); |
Notice that these are class (static) methods.
int atoi( char *s ); // ASCII to Integer double atof( char * s ); // ASCII to float |
Example:
int main(int argc, char *argv[]) { int i; double sum = 0; for ( i = 1; i < argc; i++ ) sum = sum + atof( argv[i] ); cout << "sum = " << sum << endl; } |