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.

## All 4 Replies

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.

commented: Sometimes it's the littlest detail that counts the most! +6

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.

Hi TIA... it is good that you are maximizing your capability not just in one aspect... i appreciated that... :)

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

Hi Sunnypalsingh, Ancient Dragon & ivanCeras,

Thanks for all of your help, it's much appreciated, and it did answer the questions I had! :)

Be a part of the DaniWeb community

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