I don't know whats wrong. I'm trying to use a vairable of type char and I can't assign anything to it.
In short, you need to do this:
Code:
char number[20];
strcpy(number, "9");
In C++, array names are pointers. Pointers are variables that can be assigned addresses. Yes, it's true that if you do this:
char number[] = "King";
cout<<number;
number will display as a string and not an address, but that is because the << operator is programmed NOT to ouput the address of the type: pointer to char. Instead, the <<operator automatically dereferences a pointer to type char, which obtains the value at that address, and displays the text. That makes it difficult to know that the name of a char array is a pointer. For arrays of other types, the << operator displays an address when you output the array name:
int numbers[] = {1, 2, 3};
cout<<numbers; //006BFDEC
which makes it easy to know the array name is a pointer.
Since, something like "9" or "King" is not an address, it can't be assigned to number. If you want to assign some text to a char array, you can use the <cstring> function strcpy():
Code:
char number[20];
strcpy(number, "9");
cout<<number<<endl;