954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

converting a char array to a single char

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.

Acidburn
Posting Pro
511 posts since Dec 2004
Reputation Points: 12
Solved Threads: 5
 
can a single char only hold 1 char?


Yes.

eerok
Newbie Poster
1 post since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

>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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You