Golden California Girls said:
Was thinking the second wasn't allowed ever. Toss an extern in
front of the first so it's value can't be known at compile time even
inside a function then. Isn't that the real root difference between
initialization and assignment, or call it the why both exist.
No, that's not the difference at all.
An initialization is always part of a declaration. It can occur
either outside any function definition (in which case the initializer
must contain only constant expressions), or at block scope (in which
case the initializer can contain any arbitrary expressions, as long as
they're of the right type).
An assignment is an expression (and adding a semicolon to it makes it
a statement). It's always separate from the declaration of the thing
being assigned to.
For example:
void foo(void)
{
int x = rand(); /* a declaration with an initializer */
int y; /* a declaration with no initializer */
y = rand(); /* an assignment, not a declaration */
/* ... */
}
In informal speech, it's common to mix up the two terms, but when
discussing writing C code it's important to keep the distinction in
mind. One example: it's very common to refer to a variable that's
never had a value assigned to it as "uninitialized"; it can be
"initialized" either with an initializer or with an assignment (or by
calling memcpy, or memset, or ...).