On 28/04/2016 19:23, Barry Schwarz wrote:
> On Thu, 28 Apr 2016 12:51:55 +0100, JiiPee <
n...@notvalid.com> wrote:
>
>> What is the difference between arguments:
>>
>> void foo(char a[]) {}
>>
>> and
>>
>> void foo(char* a) {}
>>
>> Can the foo use the array the same way in both?
>>
>> char k[] = "hello";
>>
>> creates memory for k-array and copies hello there. But I can see char
>> a[] does not make a new array and copy the calling values there... it
>> seems like its a pointer only. Is this correct? Is I call foo("John") ,
>> i can see that I cannot modify a's values, so its clearly a pointer to
>> John-literal. Are both of those just pointer arguments?
> Despite the lexical similarity, there is a significant difference
> between the definition of an object (such as k) and the definition of
> a parameter (such as a). Functions receive the value of the arguments
> specified by the calling statement in the corresponding parameters
> specified by the function definition ***as if by assignment***.
>
> With a few exceptions that don't apply here, an unsubscripted array
> name in an expression is automatically converted to a pointer to the
> first element of the array with type pointer to element type.
ok, this exception I was wondering... becouse normally you make a copy