| | |
converting a char array to a single char
![]() |
•
•
Join Date: Dec 2004
Posts: 490
Reputation:
Solved Threads: 5
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.
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.
>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.
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.
In case you were wondering, yes, I do hate you.
![]() |
Similar Threads
- Converting specified elements of array of char (C++)
- Simple char array question (C)
- Read in a file and store in char array (C)
- adding data into an char array (C++)
- two-dimensional char array (Java)
Other Threads in the C Forum
- Previous Thread: Output to RTF
- Next Thread: pointer problems
Views: 3015 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C
api array arrays binary binarysearch bit c++ centimeter char character code codeblocks coke command conversion convert database decimal directory dude dynamic error exec executable factorial fgets file fork free function functions getline givemetehcode givemetehcodez grade graphics gtkwinlinux haiku highest histogram homework i/o input insert int integer lazy line linked linkedlist linux linuxsegmentationfault list lists loop malloc match matrix memory mysql no-effort output parallel path permutations pointer pointers problem process profile program programming read readfile recursion recursive recursiveloop recv reverse scanf scheduling simple socketprograming spoonfeeding string strings strtok structures student subscript system testautomation turbo-c unix user variable whythiscodecausesegmentationfault win32 windows _getdelim






