help understanding "char" data type

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: May 2002
Posts: 633
Reputation: aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice 
Solved Threads: 9
Team Colleague
aeinstein's Avatar
aeinstein aeinstein is offline Offline
Team Member - aka kaynine

help understanding "char" data type

 
0
  #1
May 23rd, 2006
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 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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: help understanding "char" data type

 
0
  #2
May 23rd, 2006
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,678
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1503
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: help understanding "char" data type

 
0
  #3
May 23rd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 20
Reputation: ivanCeras is an unknown quantity at this point 
Solved Threads: 1
ivanCeras's Avatar
ivanCeras ivanCeras is offline Offline
Newbie Poster

Re: help understanding "char" data type

 
0
  #4
May 23rd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: May 2002
Posts: 633
Reputation: aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice 
Solved Threads: 9
Team Colleague
aeinstein's Avatar
aeinstein aeinstein is offline Offline
Team Member - aka kaynine

Re: help understanding "char" data type

 
0
  #5
May 23rd, 2006
Hi Sunnypalsingh, Ancient Dragon & ivanCeras,

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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 5017 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC