9.9 ARRAY ARGUMENTS


9.9 ARRAY ARGUMENTS

There is a big difference between C++ and Java in how array arguments are passed to functions. In C++, it is not possible to pass an array by value; an argument of type T[] is converted to a T* when passed to a function. Since only a pointer to the array is passed, the size of the array is not available to the called function. For C-style strings that is not a problem, since the size of the array of characters can be determined locally by looking for the null terminating character. For other arrays, however, it becomes necessary to use an additional argument for specifying the size of the array.

In Java, an array is passed to a function like any other object. As was mentioned earlier in Section 7.10, a Java array is a class type object.




Programming With Objects[c] A Comparative Presentation of Object-Oriented Programming With C++ and Java
Programming with Objects: A Comparative Presentation of Object Oriented Programming with C++ and Java
ISBN: 0471268526
EAN: 2147483647
Year: 2005
Pages: 273
Authors: Avinash Kak

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net