943,923 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3168
  • C RSS
Feb 10th, 2006
0

converting a char array to a single char

Expand Post »
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.
Similar Threads
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Feb 10th, 2006
0

Re: converting a char array to a single char

Quote ...
can a single char only hold 1 char?
Yes.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
eerok is offline Offline
1 posts
since Feb 2006
Feb 10th, 2006
0

Re: converting a char array to a single char

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Output to RTF
Next Thread in C Forum Timeline: pointer problems





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC