char str[] ="Hello"; does not work if it declared as member field of some class

Hello, guys!

I am confused with initialization of char[] array with string. I've not yet found correct answer for the question. Please help!

The below code contains two lines of code (b initialization). One works correctly (if char pointer used), but another one don't (if char[] used) .

class C {
    char a[6] = "Hello";
    char b[] = " World!";  // Does not work!  WHY???
    //    char *b = " World!";  // Do work
    char c = 'x';
    char d = 'y';

  public:
    void print() {
      Serial.println(a);
      Serial.println(b);
      Serial.println(c);
      Serial.println(d);
      Serial.println("");
      Serial.println(int(a));
      Serial.println(int(b));
      Serial.println(int(&c));
      Serial.println(int(&d));
    }
};

C c;

void setup() {
  Serial.begin(9600);
  while (!Serial) { }
  c.print();
}

void loop() {
}

I expected:
Hello
World!
x
y
256
285
264
265

But I see:
Hello
xy
x
y
256
262
262
263

In case of (char b[] = " World!") char pointer is incorrect. It does not point to " World!" string. More over the pointer of the char c declared below has the same value as b.

Short answer: You can't do it that way.
It's discussed some here: c++ - Initialize character arrays in class - Stack Overflow
One of the comments in that thread: "This limitation in C++ is a safety feature so that people don't accidentally change class layout without realizing it. Use an explicit bound."

One of the comments in that thread: "This limitation in C++ is a safety feature so that people don't accidentally change class layout without realizing it. Use an explicit bound."

The reason that is important is that I should be able to get the size of a class instance, which should remain constant. When the class contains an array that has a defined (by the programmer) size, that is the case.

When the class contains an array that has a computed size (the compiler determines the size), that is not the case, as the programmer could change the amount of data that the compiler counts.

Bottom line - don't initialize variables in the header file. That should be done in the source file.