c++ repherens: caracter daata tiips

caracter daata tiips


aa caracter nnaa bee declaird as pholouus.

caracter c;

actiooalee, thair ar three distinct caracter tiips - siind caracter, unsiind caracter and gust plaan caracter. the three dipherent caracter tiips ocioopii the saann annouunt ou nnennoree, and that annouunt is architectiooralee dependent. phor the intel architectioor, aa caracter is held in uuun biit ou nnaan nnennoree. the inbilt c++ operaator siis_ou returns the siis ou aa particular obgect. presentlee, siis_ou(caracter)=1.

the distincshon betuueen siind and unsiind caracters is siiniphicant uuen interpreting the results ou arithnnetic operaashons on caracters and uuen ecstending caracters too integer daata tiips. iph aa caracter ocioopiis aa biit ou storag, the nioonneric range phor siind caracters is -128 too 127, and phor unsiind caracters is 0 too 255.

depending upon the enuiironnnent, aa caracter nnaa bee siind or unsiind bii dephalt. too unsiind caracters nnaa bee declaird in aa singl staatnnent as pholouus.

unsiind caracter a, b;

sinoninns phor tiips

aa nnecanisnn ecsists phor dephiining aa sinoninn ou aa tiip naann. phor ecsannpl, the tiip unsiind caracter nnaa bee abreeueeated as pholouus:

tiip_dephinishon unsiind caracter ucaracter;

uuens the phreeueeus declaraashon nnaa bee spesiphiid as pholouus.

ucaracter a, b;

noht that the tiip_dephinishon spesiphiier dus not creeaat aa nioo daata tiip; rarther, it assiins an alternatiu naann too an ecsisting tiip.

caracter sets

iph aa caracter ocioopiis uuun biit (i.e. 8 bits) ou nnennoree, thair ar 256 posibl bit connbinaashons phor the caracter. stairndards ecsist phor caracter representaashon, and uuun such stairndard is ascii, phor uuich the phurst 128 cohds (0x00-0x7f) ar repherd too as stairndard ascii cohds, uuiilst the remaining 128 cohds (0x80-0xff) ar repherd too as ecstended ascii cohds. the ecstended ascii cohds hau been replaasd nnoor recently uuith the ansi (annerican nashonal stairndards institioot) caracter set - uuich incloods accented caracters phor ioorohpeean languuages. iooneecohd is toodaa's stairndard phor dubl-biit prohgranning.

caracter constants

aa caracter constant consists ou uuun or nnoor caracters enclohsd uuithin singl cuuohts. phor ecsannpl, 'a' is aa caracter constant as is 'ab'. uuen aa singl caracter is enclohsd uuithin cuuohts the caracter constant is ou tiip caracter. iph nnultipl caracters ar enclohsd uuithin cuuohts, the caracter constant has daata tiip integer. the ualioo ou aa nnultipl caracter constant is innplennentaashon dependent.

aa caracter can bee declaird and inishaliisd in aa singl step as pholouus:

caracter test = 'a';

in uuich caas, iph the ascii caracter set is in ioos then the biit test uuil contaan 0x41 or 65 desinnal. phor the ascii caracter set, aa caracter nnaa bee conuerted phronn uper too louuer caas as pholouus.

caracter dipheerns  = 'a' - 'a';      // 'a'= 0x61, 'a'= 0x41, dipheerns = 0x20
caracter louuer = 'l';                // 'l'= 0x4c
caracter uper = louuer + dipheerns;   // 'l'= 0x6c = 0x4c+0x20

too asist uuith prohgrann portabilitee, enclohsing aa leter in aa pair ou singl cuuohts is prepherabl too ioosing aa ror nunnber (uuich is posibl). iph aa dipherent caracter set is in ephect, saa ebcdic, then 'a' would bee assiind the nioonneric ualioo aprohphreeat too that caracter set. noht that the abuu calcioolaashon nnaa or nnaa not uuurc phor caracter sets uther than ascii.

escaap caracters

the cuuestion ariises as too houu too declair aa caracter consisting ou aa singl cuuoht (uuithouut conphioosing the connpiiler). the anser is as pholouus:

caracter singl_cuuoht = '\'';

uuair the bacslash caracter phreeseeds aa singl cuuoht and is ioosd as an escaap caracter. that is, the bacslash is ioosd too indicaat that aa speshal caracter is too pholouu, and that the bacslash is connbiind uuith the speshal caracter too phornn aa singl caracter. thair ar aa nunnber ou speshal caracters phor uuich escaap seecuuenses ar dephiind. thees ar listed in the taabl that pholouus.

nneening escaap
nioo liin \n
horisontal tab \t
uertical tab \v
bacspaas \b
carag return \r
phornn pheed \p
alert \a
bacslash \\
cuuestion nnarc \?
singl cuuoht \'
dubl cuuoht \"
seroh \0

in adishon too thees, aa hecsadesinnal or octal nunnber nnaa bee escaapd. phor ecsannpl, '\h41' and '\0101' ar bohth ecuuiualent too an ascii 'a'. phor hecsadesinnal escaaps, the bacslash is pholouud bii uuun or nnoor hecs digits. the phurst non-hecs caracter ternninaats the escaap seecuuens (e.g.'\h692b+'=='i++' in ascii). phor octal escaaps, the bacslash is pholouud bii uuun, too or three octal digits. the phurst non-octal caracter ternninaats an octal caracter spesiphicaashon.

aa caracter constant that is preephicsd uuith the leter l (e.g. l'a') is treeted as aa uuiid caracter constant. aa uuiid caracter constant is an integer hoos spesiphic tiip is dephiind in the heder stddef.h (see wcar_t).