| | |
help understanding "char" data type
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Hi all,
I'm transistioning from the networking end of things and moving to the programming side, so, even though I've been around here for quite awhile, I have a pretty basic queston: since the char data type has a minimum range values between -127 to 128, how is a letter character or symbol ever given a negative value? Also, can the char data type hold more than one character - up to the permissibe range limit - or is it constrained to a single character value?
TIA
PS: fwiw, I'm using the Digital Mars (TM) C++ compiler, as per the course requirements.
I'm transistioning from the networking end of things and moving to the programming side, so, even though I've been around here for quite awhile, I have a pretty basic queston: since the char data type has a minimum range values between -127 to 128, how is a letter character or symbol ever given a negative value? Also, can the char data type hold more than one character - up to the permissibe range limit - or is it constrained to a single character value?
TIA
PS: fwiw, I'm using the Digital Mars (TM) C++ compiler, as per the course requirements.
"I do not feel obliged to believe that the same God who has endowed us with sense, reason, and intellect has intended us to forgo their use." - Galileo Galilei
"Science without religion is lame. Religion without science is blind." - Albert Einstein
"Good judgment comes from experience, experience comes from bad judgment." - author unknown
"Anyone who has never made a mistake has never tried anything new." - Albert Einstein
(why "aeinstein"?)
Peace Be with You
"Science without religion is lame. Religion without science is blind." - Albert Einstein
"Good judgment comes from experience, experience comes from bad judgment." - author unknown
"Anyone who has never made a mistake has never tried anything new." - Albert Einstein
(why "aeinstein"?)
Peace Be with You
In c and c++, char is sort of a misnomer -- it is meant to hold more than just characters, it is in fact a small one-byte integer and can be used just like integers of other sizes. unsigned char has a range of 0 to 255 (see limits.h for ranges on your operating system). If you look at an ascii chart such as this one you will see that standard ascii characters fall within the range of 32 to 126, all the other possible values are used for other miscellaneous things.
>>Also, can the char data type hold more than one character
In special circumstances, yes -- they are called Binary Coded Decimal (BCD) or Packed BCD. This is not very common on MS-Windows or *nix computers.
>>Also, can the char data type hold more than one character
In special circumstances, yes -- they are called Binary Coded Decimal (BCD) or Packed BCD. This is not very common on MS-Windows or *nix computers.
•
•
•
•
Originally Posted by aeinstein
Hi all,
I'm transistioning from the networking end of things and moving to the programming side, so, even though I've been around here for quite awhile, I have a pretty basic queston: since the char data type has a minimum range values between -127 to 128, how is a letter character or symbol ever given a negative value? Also, can the char data type hold more than one character - up to the permissibe range limit - or is it constrained to a single character value?
TIA
PS: fwiw, I'm using the Digital Mars (TM) C++ compiler, as per the course requirements.

back to your question, about char data type....actually a char data type is just equivalent to a byte data type in other progrmming languages such as java, visaul basic and others.. a char data type is just an 8 bit size of data yielding into 256 combinations... char could be used with two different attributes (signed, unsigned) the default is signed, meaning when you did not define it as unsigned(absolute value from 0 to 255), it is considered as signed(-127 to 128)
symbols or (i think u mean is ascii characters) are assigned with an absolute value ranges from 0 to 255(example A=65, B=66, 13=ENTER 8=BACKSAPCE..etc)
Also, can the char data type hold more than one character - up to the permissibe range limit - or is it constrained to a single character value?
>> yes.. a char data type hold more than one character (and it becomes a string) only when you declare it as an array example(char name[3]="TIA" , string[80]="daniweb") as long as it maximum index is greater than the length of the string...
Im not so good in explaining things.. but im trying my best to explain it to you.. hope you understand....
any more question and clarification just e-mail me <<email snipped>>..... im to glad to read your comment on my explaination... ^__^
Last edited by Dave Sinkula; May 23rd, 2006 at 11:55 am.
Hi Sunnypalsingh, Ancient Dragon & ivanCeras,
Thanks for all of your help, it's much appreciated, and it did answer the questions I had!
Thanks for all of your help, it's much appreciated, and it did answer the questions I had!
"I do not feel obliged to believe that the same God who has endowed us with sense, reason, and intellect has intended us to forgo their use." - Galileo Galilei
"Science without religion is lame. Religion without science is blind." - Albert Einstein
"Good judgment comes from experience, experience comes from bad judgment." - author unknown
"Anyone who has never made a mistake has never tried anything new." - Albert Einstein
(why "aeinstein"?)
Peace Be with You
"Science without religion is lame. Religion without science is blind." - Albert Einstein
"Good judgment comes from experience, experience comes from bad judgment." - author unknown
"Anyone who has never made a mistake has never tried anything new." - Albert Einstein
(why "aeinstein"?)
Peace Be with You
![]() |
Similar Threads
- Check data type input!! (C)
- Problems with changing values returned by RegQueryValueEx (C)
- help on data type conversion (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: Woah weird issue in my program...
- Next Thread: Console Color
Views: 5017 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






