answersLogoWhite

0


Best Answer

Yes, it can. It allows to save a lot of memory because you do need to copy all data, you just use the direct address. You can do in at least two ways. One way is to use pointers, second is to use array itself. It's better to use array notation because it's easier to read programs.

First way:

void setData(double data, int dataSize);//prototype
...
int main()
{
...
const int dataSize = 5;//size of array, can be any int, 5 is used here
double data[dataSize] = {0.0};//set all elements to zero
...
setData(data, dataSize);
...
return 0;
}
...
void setData(double data[], int dataSize)
{
for (int i(0); i < dataSize; i++)
{
data[i] = i;//sets each element of array to its number

}

}
...

Second way:

void setData(double data[], int dataSize);//prototype
...
int main()
{
...
const int dataSize = 5;//size of array, can be any int, 5 is used here
double data[dataSize] = {0.0};//set all elements to zero
...
setData(data, dataSize);
...
return 0;

}
...
void setData(double data, int dataSize)
{
for (int i(0); i < dataSize; i++)
{
*(data) = i;//sets each element of array to its number

}

}
...

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: The address of an array can be passed as an argument to a function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What happen when a c program passes an array as a function argument?

When an array name is passed as a function argument, the address of the first element is passed to the function. In a way, this is implicit call by reference. The receiving function can treat that address as a pointer, or as an array name, and it can manipulate the actual calling argument if desired.


How is an array name interpretedwhen it is passed to a function?

An array is still an array, regardless of how you pass it into functions. It is still an array-type variable at the beginning of a function. However, the function itself may manipulate the array by "imploding" it into a string with a delimiter, using array values with only specific keys, and such.


When an array name is passed to function in c?

It 's address is received by the function . that any changes in the value of array elements in the function will result in actual change.


How can a structure be passed as an argument to a function?

A structure is like an array. You can only pass its address. struct _mystruct { int p; ... } mystruct; myfunction (&amp;struct _mystruct mystruct s) { s.p; ... }


Why the array is starting from zero?

By design; it makes the compiler's work easier. 1-based array's addressing-function: Address (array, index) = Address (array) + (index-1)*Elemsize(array) 0-based array's addressing-function: Address (array, index) = Address (array) + index*Elemsize (array)


How can and array be passed to a funaction?

try this: &lt;function-name&gt; ( &lt;array-name&gt; )


Argument Array in java script?

There is an arguments object in JavaScript. This object is treated much like an array (but it's not actually an array.)You can however reference the arguments passed to a function via this array. For instance, if we call a function like so:exampleFunc('Tom', 15, 'potato');Then we can access the value of Tom at the local variable arguments[0].


What is signifience the name of an array?

The name of an array serves as a reference to the start address of the array and thus to the first element of the array. If the array is fixed length and within the scope of its declaration, the compiler can determine its length from the name alone. However, when an array name is passed to a function, it implicitly converts to a pointer and the size information is lost. thus the size must be passed as a separate argument. The only general purpose exceptions supported by the standard library are null-terminated character arrays (C-style strings) and null-terminated arrays of C-style strings (terminated by a double-null).


Why should a function that accepts an array as an argument and processes that array also accept an argument specifying the array?

Basically in c++ passing an array as an argument only provides a pointer to the first value and that function won't know how many values it has.If you read beyond the size you will just get garbage from memory.


What does array map do in php?

The array_map function in PHP loops over each elements of the passed array(s), and runs the given function. It then returns a new array that contains the values returned by each call to the given function.


How do you pass a 2D array in a functions?

if you were to call a function you would write it as: function(array[][], int pretend, double pretend2); arrays will always be passed by reference, not by value.


How an array passed to a function?

Arrays should be passed by reference or by pointer, never by value (passing by value passes a copy of the reference, not the reference itself). The array length should also be passed to the function (by constant value) to prevent buffer overflows. Alternatively, in object-oriented languages, arrays can be wrapped in a class of object. Since the array is a member of the class, it doesn't need to be passed to the member methods, thus the function can become a member method of the class itself or a derivative of the class. Or the object containing the array can be passed to external functions by reference.