Hello guys.

I've got a query which is most likey really simple. I've got an array of char's thats :

char temp[10] = "abcd";

I'm wondering why I can't put these into char a;

since char a = 'abcde' would be legal right? Or can a single char only hold 1 char?

Since an int can hold 123456789. and so can the int array.

can a single char only hold 1 char?

Yes.

>char a = 'abcde' would be legal right?
If the implementation allows a character literal like that then it's perfectly legal. However, the result is not the same as an array consisting of the characters 'a','b','c', and 'd' in any case.

>Or can a single char only hold 1 char?
Obviously, a single char can only hold a single char value. Anything else is just silly.

>Since an int can hold 123456789.
Maybe, maybe not. A 16-bit int can't hold that value, but a 32-bit int can.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.