What is the difference between:
void foo(item* list)
{
cout << list[xxx].string;
}
and
void this(item list[])
{
cout << list[xxx].string;
}
Assuming item is:
struct item
{
char* string;
}
With the pointer pointing to the first of an array of chars
and list
is just an array of items...
The parameter is referred to as the variables that are defined during a function declaration or definition. These variables are used to receive the arguments that are passed during a function call.
When a function is called, the values that are passed during the call are called as arguments. The values which are defined at the time of the function prototype or definition of the function are called as parameters.
While calling a function, the arguments can be passed to a function in two ways, Call by value and call by reference. The actual parameter is passed to a function. New memory area created for the passed parameters, can be used only within the function.
While calling a function, the arguments can be passed to a function in two ways, Call by value and call by reference. The actual parameter is passed to a function. New memory area created for the passed parameters, can be used only within the function. The actual parameters cannot be modified here.
To the compiler, there is no difference.
It reads different though. []
suggests you want to pass an array to the function, whereas *
could also mean just a simple pointer.
Note that arrays decay to pointers when passed as parameters (in case you didn't already know).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With