[Courses] Re: pointers, array's, and sizeof()
Laurel Fan
laurel at sdf.lonestar.org
Sun Feb 3 00:13:51 EST 2002
On Sat, Feb 02, 2002 at 09:04:24PM -0800, Dreaming Kat wrote:
> The last exception, the name of the array being a string literal
> initializer for a character array, means that you've said something
> like:
>
> char oldArray[ 10 ];
> /* put stuff in oldArray */
> char newArray[] = oldArray;
>
> this works exactly like you'd expect, the contents of oldArray are
> copied into newArray. I'll include this in my little sample program
> tomorrow too.
Are you sure? I don't think you can cause an array copy with an
assignment, even at initialization.
With this code:
char oldArray[] = "abc";
char newArray[] = oldArray;
I get a compile error. (array initialized from non-constant array
expression)
Even with this:
const char oldArray[] = "abc";
char newArray[] = oldArray;
I get a different error. (invalid initializer)
AFAIK, the only way to intialize an array is with bracket notation,
eg:
char oldArray[] = {'a', 'b', 'c', '\0'};
or, for arrays of char, a string literal:
char oldArray[] = "abc";
--
laurel at sdf.lonestar.org
SDF Public Access UNIX System - http://sdf.lonestar.org
More information about the Courses
mailing list