Welcome, Guest. Please login or register.

Author Topic: C string syntax incoherent ? ...  (Read 2404 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Fats

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 672
    • Show all replies
Re: Stupid bloody C string question...
« on: December 27, 2004, 12:03:42 PM »
Quote
The other case, char strg[11] = "C rules!!!"; is really where my confusion came from.


Exactly, I think your confusion comes from the fact that in a variable declaration the = has a different meaning then in a normal C statement.
In a variable declaration the = character is used to initialize the variable and this initialization allows to initialize all the single members of an array.
The = in a statement is an assignment and can only assign a value to one member of an array.

So the following statement is OK:

char test[4] = "foo";

But the following is illegal :

char test[4];

test = "foo";


or

char test[4];

test[4] = "foo";


greets,
Staf.
Trust me...                                              I know what I\'m doing