943,963 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 8736
  • C++ RSS
May 23rd, 2006
0

help understanding "char" data type

Expand Post »
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.
Similar Threads
Team Colleague
Reputation Points: 186
Solved Threads: 8
Team Member - aka kaynine
aeinstein is offline Offline
643 posts
since May 2002
May 23rd, 2006
0

Re: help understanding "char" data type

SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005
May 23rd, 2006
0

Re: help understanding "char" data type

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
May 23rd, 2006
0

Re: help understanding "char" data type

Quote 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.
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... ^__^
Last edited by Dave Sinkula; May 23rd, 2006 at 11:55 am.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
ivanCeras is offline Offline
20 posts
since May 2006
May 23rd, 2006
0

Re: help understanding "char" data type

Hi Sunnypalsingh, Ancient Dragon & ivanCeras,

Thanks for all of your help, it's much appreciated, and it did answer the questions I had!
Team Colleague
Reputation Points: 186
Solved Threads: 8
Team Member - aka kaynine
aeinstein is offline Offline
643 posts
since May 2002

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: Woah weird issue in my program...
Next Thread in C++ Forum Timeline: Console Color





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


Follow us on Twitter


© 2011 DaniWeb® LLC