answersLogoWhite

0


Best Answer

Yes, if the programming language allows that, like most of high-level languages do. For example, in Java, arrays are defined by placing square brackets after type definition:

public int[] arrayOfIntegers = { 1, 2, 5, 10 };

public String[] someStrings = { "Hello", "World" };

public void thisMethodAcceptsArraysOfIntegers( int[] argument ) { }

public String andThoseStrings( String[] s ) { }

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

16y ago

When a array is passed to a function, the array is internally changed to a 'pointer'. And pointers are always passed by reference. Hence the answer to the question.

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

value ke reference

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why cannot arrays be passed by values to functions?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the purpose of using arrays in C language?

The purpose of using arrays in C is to store multiple values in one variable. Then you can make programs that use arrays like lists, printing values from multiple arrays into one line. It take memory in continues block then we can know memory location easily. We can retrieve data quickly.


Can an array be passed from a function to the calling portion of the program via a return statement?

It depends on the language, but in most cases yes, you can return arrays to callers via the return statement. In C, arrays can be returned from a function by reference (that is, by pointer) but never by value (arrays cannot be copied automatically). The array must be allocated on the heap, never on the stack (you cannot return references to local variables). However, beware that returning arrays by reference is unsafe because there's no way to determine the upper bound of the array. This is why many C library functions return multiple values through output parameters and use the return value to indicate error conditions. One way to return both the array and its size via a return statement is by returning a structure: struct array_info { void* array_ptr; /* pointer to first element in array */ int size; /* number of elements in the array */ }; Obviously you must cast the array_ptr member to the appropriate type before dereferencing any of the array elements. In C++, C-style arrays work just as they do in C. However, the preferred method is to use a vector rather than a C-style array. A vector is a class template that encapsulates a C-style array with size and reserve, along with a rich set of useful functions (as with all templates, you don't pay for what you don't use). Vectors can be returned from functions both by value and by reference. Vectors also support move semantics making it possible to return vectors allocated on the stack as well as on the heap. C++ also supports an array class template. This is specifically for fixed-size arrays but is otherwise similar to a vector.


Write a program to return a function using class in C Plus Plus?

Classes cannot return values, only functions can return values. But you cannot return a function from a function, you can only return a function pointer -- a pointer variable holding the address of the function you wish to return. All possible return values must be of the same type, therefore all function signatures and return types must be exactly the same -- only the name of the functions can differ.


CAN Overloaded functions can return default values?

I'm not sure I understand you as it wouldn't make sense for a function to return a default value. Do you actually mean can a function return an argument that has a default value? If so, then yes. Any argument passed to a function, whether defaulted or not, can be returned by the same function. If the argument is passed by value then you must return it by value. If passed by reference (which cannot be defaulted) then you can either return by reference or by value. However, if you pass by non-constant reference then you can just use the reference as an output argument, and use the actual return value for some other purpose, such as reporting any error condition(s) created by the function. Overloaded functions are no different to ordinary functions, the only criteria is that each overload has an unique signature. The return value does not form any part of the signature, thus signatures cannot differ by return type alone.


How many arguments can be passed to an applet using PARAM tags Explain all the parameters?

two arguments can be passed to applet using param tags NAMES and VALUES <PARAM NAME ="name" VALUES = "values"> Parameters are passed to applets in NAME=VALUE pairs in <PARAM> tags between the opening and closing APPLET tags. Inside the applet, you read the values passed through the PARAM tags with the getParameter() method of the java.applet.Appletclass.

Related questions

Why cannot arrays be passed by values to procedure?

Because C does not have procedures. Because in Java only elementary types (int, double, etc) are passed by-value, objects (array included) by-reference.


What is the purpose of using arrays in C language?

The purpose of using arrays in C is to store multiple values in one variable. Then you can make programs that use arrays like lists, printing values from multiple arrays into one line. It take memory in continues block then we can know memory location easily. We can retrieve data quickly.


How do you get difference between two or more arrays in PHP?

The inherit function `array_dif($arrayOne, $arrayTwo, $arrayThree, ...)` is likely what you're looking for. It compares two or more arrays, and returns an array of values that are unique among the arrays.


How does one use JavaScript arrays?

JavaScript arrays is used to generalize multiple values of data and store them in a single variable. This is a useful software in most programming languages.


What are the numbers formulas and functions used in calculations called?

You can refer to them generally as values. Formulas can use operands and functions use arguments.You can refer to them generally as values. Formulas can use operands and functions use arguments.You can refer to them generally as values. Formulas can use operands and functions use arguments.You can refer to them generally as values. Formulas can use operands and functions use arguments.You can refer to them generally as values. Formulas can use operands and functions use arguments.You can refer to them generally as values. Formulas can use operands and functions use arguments.You can refer to them generally as values. Formulas can use operands and functions use arguments.You can refer to them generally as values. Formulas can use operands and functions use arguments.You can refer to them generally as values. Formulas can use operands and functions use arguments.You can refer to them generally as values. Formulas can use operands and functions use arguments.You can refer to them generally as values. Formulas can use operands and functions use arguments.


Examples of filipino values that is passed on today?

Filipino values are still passed on today. An example of one of these values is care for and respect of elders.


What is the purpose of initialising an array?

Arrays are variables, so your question is: What is the purpose of initialising a variable? Answer: assigning initial values to them.


Can an array be passed from a function to the calling portion of the program via a return statement?

It depends on the language, but in most cases yes, you can return arrays to callers via the return statement. In C, arrays can be returned from a function by reference (that is, by pointer) but never by value (arrays cannot be copied automatically). The array must be allocated on the heap, never on the stack (you cannot return references to local variables). However, beware that returning arrays by reference is unsafe because there's no way to determine the upper bound of the array. This is why many C library functions return multiple values through output parameters and use the return value to indicate error conditions. One way to return both the array and its size via a return statement is by returning a structure: struct array_info { void* array_ptr; /* pointer to first element in array */ int size; /* number of elements in the array */ }; Obviously you must cast the array_ptr member to the appropriate type before dereferencing any of the array elements. In C++, C-style arrays work just as they do in C. However, the preferred method is to use a vector rather than a C-style array. A vector is a class template that encapsulates a C-style array with size and reserve, along with a rich set of useful functions (as with all templates, you don't pay for what you don't use). Vectors can be returned from functions both by value and by reference. Vectors also support move semantics making it possible to return vectors allocated on the stack as well as on the heap. C++ also supports an array class template. This is specifically for fixed-size arrays but is otherwise similar to a vector.


Is array list value type or reference type?

Arrays are reference type. array values are always pass by reference.


What is rational values?

Rational values- those are necessary to the functions and fulfillment of intellect and will.


Write a program to return a function using class in C Plus Plus?

Classes cannot return values, only functions can return values. But you cannot return a function from a function, you can only return a function pointer -- a pointer variable holding the address of the function you wish to return. All possible return values must be of the same type, therefore all function signatures and return types must be exactly the same -- only the name of the functions can differ.


Values used in calculations in functions are?

arguments. :)