Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
94 views
Unit 1
Uploaded by
Saptarshee Mitra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Unit 1 For Later
Download
Save
Save Unit 1 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
94 views
Unit 1
Uploaded by
Saptarshee Mitra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Unit 1 For Later
Carousel Previous
Carousel Next
Save
Save Unit 1 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 18
Search
Fullscreen
Kulkarni’s Classes, Dombivli 73 S S S s B S 5 5 5 Pe P iKulkarni’s Classes, Dombivli Fundamentals of C++Kulkarnf's Classes, Dornbivit FE/CP.1 4 His ih Level Languages - > Progeming nthe machine level language was hain epee robles and thooe ar std as flows. 9} Wing he programe inthe machine level language ow ove language ie, the lnguage of 0 and ‘ewes tedious ») Debugging (.e.ing cut he logical error) the programs wien nthe machine evel language was Auta ous, ) Every gta proosster has fs own machine lava language. Hence fe progr wien using machine angiage of ene procesar wal nol work wih the oer ig! proceso, f means thal the programs wren nthe machine level language erent portable, > The programmers need a language which would net have sbove dscusod problems and tat has resutec Ino te evelopment che High Level Languages. > In 1820, language calle a6 ALGOL-40 was developed by the Inleatinat Commits. The language wae foc ‘ener. oo abstract an was hg ales, Hence he language was rejected by many of the programmer, In 1963, a language caled as CPL (Combined Programming Language), was developed al Cambridge University, UX. The lnguage was rejected by the programmer forthe sina reasone seta of ALGOL-D, tn 1967, Metin Richards develope a language caled st BCPL (Baste Combined Programming Language) ‘The language was including ony the bale features of CPL. The BCPL was too eral and oo speofc end ence was ct suf to cover vary ef appicatons. Hance tho fanguage wa eocod bythe programmer. In 188, language cae as B was developed by Ken Thompton at ATAT Bel Labe, USA. The language was recon fr te sr rasons as at of te BCP. > In 1072, Dennis Ritchie doveopod a language called a6 © at ATE Bel Labs, USA. The language was oveioped in such 2 manner, thal was having sma oot of elements vbich was good enough o ever large ‘ange of applications. The was the reaton du to which he language wes accaped by the programmer. The language € proves fests cf high love language aswell tow evel anguage hance afin stormed a mde lvalangusg. Ltr on Bilan Kemighan Joined Dennis Ritchie and thy together reid the lorguage forthe ANS (American Ntionl Standard Ines) approval The standard version ofthe Ianguago la, ANBHE became vale in 1676, > The € language became very popular Stuctured Programming Language for programing apts. The language was sulale for Procedure Ovented Programming (sleo called as Function Orloted Programing) approach. As to comple ofthe cere sofware projects boing developed was inceatng & was besoming cut to ‘manage lt using Procedure Orient Programming concepts. This resutd into the deveomert of 2 new rograming aprezch cae as Object Orlanied Programming 9prosch > In 4878, Dr. Stroustrup staid developing a language at ATAT Bell Labs, USA to suppor ebjectereted programming. Whe develonng this language, the idea wae Yo develop new language n uch a way Bat \wataver was woking wth C shuld alo workin new language andthe new language should have its own new features ie. Objet Ortened Features. The language was oiginaly called ss C with Classes whch wat lner on renamed a C4. We deveping the Cs, the care was akon thal whatever works n © must workin Co means that ever vale € program is avaid C4 program aso Hence Iti eld that the language Cos .superat ofthe Ianguage C, Thus the C++ suppers both Procedure(Function) Oriented Programming at well as Object Oriented Programming. The development of the C++ was cried in 1862. Laer on the LUVATTATATATE TATU TUT UOT T LEDUC ECU CTE En oe oar ak8) Character set by Keywords ©) Wentiers 4) Data Typos ©) Corstants 4) Variables ©) Operators 1) Expressions 1) Preprocessor Drecves 1.2.4 Character Set “sThe character sets noting bal posse cersctors that can be used win the language C++. ne large (Gre all tho characters that belong to standard ASCII (Amartean Standard Code for Information lterchange) character etre nce. + Fotoning ar some of he charactor presentin ASC character set Alohabets > az ane Dots > ont “+ Te sandars ASC character sot has got nl 128 charactors, Every character has got ts own une ASC cade, These code values ange fom 0 0127. 1.2.2 Keywords - "The keywords ar rehing bu the words wbich has oot protetied resning In thal enguege. As © programmer sno con ot change meaning of theso keywords. These keywords must be used for he predained pupene, The yoo ate ale called as reserved words. 1+ Fobowing ar he kaywerds defined inthe tnguage C+*. esr conte oat eH signed wy ato ofa for operator szeot ‘ypedet break elo fend vate state on case es ‘0 poteced = sruct_ unsigned eh ouble abe wien itu oe ae ne reoistor template wid ass eum at satu this vote const oxen tong stort throw wile 1.2.3 Mentifiers = «yan Idan is noting bat the name given to the programming elements such ab constants, varies, araye, ‘urea The purpose of intr et dontty these programing lemers wih thelr own names, The res fer foming ‘denier names are gen a folows. . GP-| Notes : Prepared by Samir Lele 12: Jkarnl's Clasees, Dombivil FE/GP-1 ‘ules for enter Names — 41) Anidentfername is tobe made up of alphabets tare) end cigs No oer special characters are slowed. 2) Aa denier came can no tan wth dg. 8) The underacora_)is the any special harcter hats alowed te fora the name of an enti. 46) The underscore heated ae an sphabot. 5) The lowercase letters andthe upperesc lear wil fer rom eachother wh forming ihe Wertier names. For @9. a and A aro diferent ientier names. Silay a the flowing eight iene: names are tere ftom eoch ar ‘np mn Np NP Nop MnP Np MP 8) Te keywords ae ret alowed tobe used sioner oomes. Fotowng ar some vali ident nas. © abe abet23 athe mac temp _lo_velght Folovng are some wat ertier names withthe reasons of iva, oto ‘he cheraclr ia nt allowed ze «a denier riane moat otbein ih tele vetame ‘he bank oace el alowed, te Se teyorionatalowedeskeneime. 2.4 DataTwes- AscTT vawe “Tho data ypee used n Cr+ can be classied foo “OAR ‘pi — 6s ‘or da ype ‘oe 37 midldnck sia Derived data types User defined data types ‘sree | 1 = Pointer Clee Wega] [void | | Floing Reterenca Enumerated int ]Leter} Cao] Canto ‘The ANSLOr* commie has adie wo more deta pes named as wchar_ and boot {Integer data ize (int) ‘+The data ype intincices integer constants, ineger arabes a ineger expressions. + Thointoger number's noting but sequence of its which maybe preceded bys pls) sgn aby minus.) gn + The decimal plot or exponent sgn er any ar specs cnaraceris not alowed ‘Shares dta ype (che )~ +The at yp char includes character consis, character vata anc character gression. +The choracter data type i made up fal te vad ASC characters. Ter ace 128 cerca nthe tnd ‘ASC character st. Every hercter has at unique vl otwoen Of 127 ~ CPA Notes : Prepared by Samir LeleFloat cate te (float) ‘+The dea ype Boat cludes oat pet constants, ong pln varables an latng poet exresions 1+ The floating point number e made up of its Ot @ along wih eter a decimal point exponent sgn bath. ‘+ The Mating pent number may be preceded wih plus sign or minus) ign. No oer special charactors are alowed ‘Double datatype ( double) “Te data pe double Includes double ype constants, double type variates and dbl pe oxpreatrs “Te aoube type number lo made up of digs 10 @ along wih ele a decimal point r exponent sgn or both “The couble type number may be proceed wih a lus) sgn or minus) sgn. No ober spell charocer ae alowed. “Thus, the deta of douse type data ae same as hat ofthe fost ype dat. The oolvlference betwen te Mo is Note Derived deta types ane nar Defined datatype wilde dacusse inte ert anon wren ta 4.2.4.1 Data types with Qualifiers {9-f0\t, Mavis in Cte er ae fur ere ques raed a slg, nslgned, sort a tong Tee gules ae sed wih ne dla pes mad abn ow double end car along able stow ah val onions e tata pes nd cues, Data Type With Qualttiors Range Of Values char saptav1a7 (P w?=1) ‘gned har 26104427 (2 7-1) unsigned oe 025s (0 Ft) shoot “Sawin o32767_(-2" 02"=1) ‘ined sett -s2reate 132787 (2% wo2"—1) unsigned hot in ‘01965895 (0 102-1) at “$ee8 wo #92767 (-2" 1021) ned it 2708 9032707 (-2" o2*= 1) signed nt 195595 (0102-1) lengint paraagbaso 2147469047 (2 tw") Sioned ong it 2147489648 0 +2147489667 (-2" 102") ‘signs ong int 0 <2oten720s (0 w2*—1) fost Bad HO 034 C10 eoubie 247 1092 17 x10 Tong double 34x10 toa 1110 “The data ype char equtes one memory by fr Sinege. One meow bf china braun Bi. The Ui tered esate La, 88 conaone Ha he combatant rapa oe thats romain a fh embaton saed pote vhs ao wh ze. Hane erage of sv e128 “The signed char has got sare dtals ws tat of the char. The becaute chr is thing but sled chat, by tout. Thus. the qual sioned bocomes redundant. lth characters fom the ASCH character set wit) ‘les ranging om © to 27 wil ato herenge of char and signed ch. “The unsigned char reques one memory byte fr storage. Hance athe 2" Le 26 combinations wil be wtsed {or ren negate vues, Hance the range of values wil be Oto 286, ‘CP-1 Notes : Prepared by Semir Lele: v7TEUTETITTTUTTAVTAT UA TUDO COU LULL UUCLEL UOT OU CLE. Kulkam?'s Classes, Dombivii FE/ cP. + Thelt rogues wo memory bites fr sorage. Two memory byte La. YE binary nub wi et to Le, 65536 combinations. Hal of te combinations are ullsed fr nopave valuee and the remaining ha of fo cembratens ar uilised for postive values slong Wh zero. Hence the ange of values wt be 22788 to 82767 ‘The sghed Int has go sme deta a tof he In. Thi i becauve ite rotting but lgned int, by feu, For unsigned int, a the 2 Le, 65536 comblnaone are wilted for non-negative values. Hence the ange of vetuo sO to 65535. ‘+The exlaaton for short int, signed short int and unsigned short nt remains areas that fhe Int elgned Int end unsigned int respectively, uw * The long Int requires four meray bytes for trage. Fou memary byes. 32 bnary number wl et into 2 combinations. Hat of the combinations are uslsod for negative valies and the Tenaiting bal of the combinatons are ue for site values slong with eo, Hence te rage cf values repreentd by lng nts ven a 2147489848 to 2447480647 7 "+ The signed tong it has got same delat ae that othe fong Int. This s because long Int nothing but sled long int, by detoutt *+ For unsigned long int. a the 2**combinatons are used fr non-negative values. Hence the ange of vals ie ‘ven as Oto 4204067208, +The Most, double and long double requtes 4,8 and 10 memory bye for storage respectively. Range of values, fora th tees determined by IEEE.TE4 forma (tule of Eloi end Eanes Engine’). 1.25 Constants — the he The constants nGH se cassted as folows. Constants in G++ tert ‘Symbolic ] i f char] nwoer][ toa aoutc || Svng Decimal }[ "Octal ][” Hoxadecimel Literal Constante rater o ‘Tho character constants re nothing but al he valid ASC charac, The character constant when usedin a program ibe enclosed ino siglo quotes Le, singe epostonhes. Foreg, phabete > Beene? Digits > we. Soma Otter Charsclers a ae coy tor 7 7 ee oe (CPs Notes : Prepared by Samir Lele 118Kulkarn!’s Classes, Dombtvit FE/CP-1 ow ne ine (2 tne feed ie cariageretun) “0 rulenaraer e i w ockepace e cariage return form 0d w beckslash ” singe quote ” double quote 7 ‘e ‘tenon (ep Ara) Decin mo ‘+The cecinalitagar constants sr iiogernunbererecreserted in decimal number syetsm. {These constants are sequence of igs ftom te 8 which maybe preceded by lust) sgn or mins) sn. 4+ These coetanis may end up wth aftr Lot 0 fate lng value. {No other special character re slowed. The decinel pointer exponert sgn are lo nt atowed Valid einaietogr constants = o 0 0 “8 2108 eras 000. ‘val decimal rte constarts wih he reasons of Iva = 3128 > Conmais netatowed 10 > Evenife valu ofthis umber se. nega, the way the numbers ‘rapresenied. isnot Be vl oie! Integer consi. This is becauee, the ocrma point rot allowed Tes02 > The-va ofthis menber ls 7X 10" Le 700 which anirtogor. However, the ray the nbs reprsecte, fot he valid doc integer constant. This [sbecaute, the exponet sign he @ not lowes ‘Qo inter Constants = “The ctl integer constants are tego: number represented in acta number stom, “These constants are sequence of its rom DoT which re not rece by ny sin. ‘© Those constants are preceded by 20:00). ‘+ These constants may end up wih eller L aro indcat ong value. ‘+ Nowe special characters ae alowed. The decimal point or exponent sign are alsa not allowed. ‘Voli ot nteges constant = o ors 0238 own perm. a indedea! 00.128 > Commas not slowed oe > The digit ie not atowod andthe compiler wil eauso an ear inceating Ut ‘is val octal constant. oe > Invate oct constant as the number isnot precoded wih zero(0), However, ‘the compiler wil not cause ary ene. THs ls because, the compior wil ost this nurbor a vad decimal itoger constant. ; ‘o7gesc2 > Tha dacimal pont and exponent sion are nt sone, 0128 Thepiua(s) sgn ian alowed om > Thominus() ents rot alowed. ‘CPA Notes : Propared by Samir Leleald xadecial integer ccnstants = % 0023 ORTAB «| OKM wad OXTAGROMTRFEFRL (33.128 Cammalsntalowed OXTAFH > —Thoetor snot towed an te compar il cause an err indicatin tha le valid hexadecimal constant us > vai hoxadectnal constant atthe nebo preceded wth Oxf BK However, the copier wt not couse any err. This is bocaus, the compl ‘wl Wea tis numbers vai decal ager conan. A > imate exadsinal constant asthe number not precadd wth Oxor OX “The comple wil cause an ener. Thi ie bacaute, the compiler wl tet the ‘unber 2s decimal integer constant and the unber it nota ak decimal Integer constant. O17 er02 > The decima point and exponen sin rere owed, +0%5203 Tho pus¥) lon is not allowed, Kutkarnt's Classes, Dombivit FE/GP.1 - ‘Hexadecimal Integer Constants - + The hexadecimal nage constants ae itegr numbers repretantadinhaxadecimal number eyto, + Those constants aw soquence of digs tom @ 10 O and leer rrr fo For ato Thaoe constants ee rot receded ty any sgn + These constants are preceded by Ox 0X, ‘These constants may end up wih alee Lor ndcate long value. ‘+ Nother spec charactars are alowed. The dacnal palate axponeet ign ae alone lowed Oath} Themirun) sgn ie ret slowed Even the value of 7.0 i 7 Le. integer, te number 7.0 fea valle Roaing pal constant Because uses decimal poi. Even te vale of Te¥02 i 700, rege, tho number 72402 avai ating ptt constant. This Is because uses exponent gn ol at and out conan = 7 r Tew 12mse “The decimal pont must be prseat between the two dis. “Te decers pint must be prosert between te two ages “Te decteal pont must be present betwen the two cigs ‘Te comma rot lowed. weed ‘oat and Double oe Constants ~ 1+ The feat anc coube ype constants are the numbers made up of gt 009 long wah ether «deck point or exponent sign or both ‘+ Nooter spect characters are awed ‘+The oa and dove type constants may got precede by pls(+) or mina) gn val ‘ 00 423 7218 HH0sT¢ ©— 7D Teton -27is2EW02 +2.1403008 ‘The sbovedescapéen, slang wih he exampiessepoteate tat ype at wel as double type constants. +The aerence between the to is that float ype constant lkes 4 mamarybyles and he double type contens eke 8 memory bytes for storage. 7 ‘+ The citer atferonca isthe range of value, The range of float ype constants is, #24410 tos24 x10" The range of doube ype constaieis, #47210 wt. 7 x10. ‘CP. Notes : Prepared by Samir LeleKulkam?’s Classes, Dombivil FE/ CPt ————__Matharnis Glasses, Dombivil FE/CPY ‘Stina Constants ‘+The sting constants noting but soquence of val ASC! characters enclosed witn coube quotes 1. couble poston (**). +The sting constants ae atematcaly terninaid wih special character caled as rf characte (0) When the sting onsiant is toed in memory han tis character becores useful ioinccae the ee oe stig, atid sina constants = “eo 123, Wetcome” “AN23.297, abe, 6, Dombi?” “C++ appears single" “cresoeear “PHY, Welcome a Hello > “Tha opening and cosing dole quotes are missing. Welcomst > The opening deube qucte ie missing. a > ‘Te closing double uot i missing Note ~ Tho’ ane “A" are eee am each che. The A’ character constan and it requrs one memory ofr storage. The A" easing conetan nd Krequls wo memory byte or storage, ae fo the‘ andthe ‘ober forthe null character. 40, le = + InGrs, tho symboe consents can be obtained wih vee erent methods = 9) Using he keyword called as const ) Using enumerated dat Ypes 8) Using pre-proceste drecbves 2) sna te herd cated as const = + The symbeko constnts canbe decared using the keyword called as const *+ Once these sybase constanis ar declared inthe program, fn thelr values can not be changed but ha veuee ‘can bo used wherever equted i the program, ‘+ When use symbole conetant na program than & wi be replaced by “+ Conaier he following example saute vate Gener Syne, Kiron renin @Art datatype idehtfr mane » value » versa | elem 28 ere ry x 200 11 navcte tote compitation excor re 4.0y 1/ Rasutts Ante compilation error + In the ebove exemple, we have dectared a symbolic constant called 9s X whose equivalent valie is 100 and we have iso cedar a sybole constant called at Pl wha aquvelent value e314 + In te furor tre satomerts the values of ese synbolecorstans are ule K means that X and Pw be replaced by 100 ane 3.14 espace. ‘+ Inthe fst to statements we ave making en stompt of changing te values cf ymbote constants, whch snot ‘atned and hence wil veut camplaton once. : + The advantage of docarng @ symbole constant canbe given at we use the syibol PI meny tes i the rogram an later on we deckie to change the oquivelent value from 2.14 fo 914180, thon jut a one change wher we hae delaras PIs good enough and at al ther place wheraver we have used Pt eviomataly (ets replaced by 3.14150 intend af 3.14, (CP4 Notes : Prepared by Samir Lele.Classes, Dombivil FE/CP-| ) Using enumerated deta = ‘+The symbole consants can be cectored wth ha hep of enumerates datatypes. The enumerates daa pe i one ‘ofthe usr deine daa types. 1+ Consider ne folowing amie. ©) enum erection (north, east, west, south}: Inthe above example, dection i the erumerted datatype with ts values at nonh, sat, west and south whose rtamal ves se, 1,2 and 3 respectively, z ‘The nal tc is we have decir for amboc contacts named as Cath eae wes! and south wh el eouisent vales 01,2 and 8 stpctve. ©) enum woke fam mont, the) nb ator sven, wenn numeri dla pe wt aes 2 un mo, tun with hance woe eaten 12 86 8am Bree, Then ft: wo ne ceed tan sole cote hea unc, Ya th. fiandsst wi ey ec a 1.2.5.4 Sand Sees ©) enum cards spade, heat, cub, damond j In the sbove example, cards is the enumerated date type wih ts valves cub and dlamond whoea intra vaoe ae 0, 3,2, nd 3 eapecivey. The fo dimond wah tes exelent values 01,2 and 3 respectively ‘ { sede,tean, | 9 enum cooref{ re, oe nk, green orangor3t, magenta Inte sore xan, color to erunaratd data ype wht veo as vd us, pink, ‘en, orange and magenta wows ioral lus sre 0, 10,1, 12, 0 and 3t respec ‘The alate we have desired si mba conse named 2s cee, ps cen, ©) Usinapearocaesar drectves = + The symbetc constant ca also be defined wth tho hop of pre proestor recive nad at #éetne, + Consider the folowing example fine P1a.s6180 The elect ofthe above proprecessor dhoctve is that we ae defning a symboke constant called es PI whose utvalent vale i 3.14159, Lalr on fa the program wherever the Ps used i wil be replaced by its equivalent val Lo. 3.14358, ‘elem. Aatatype variable name datatype variable mame, variable mam62y nono Variable name aad tx: Inthe above statement, we are declaring a varate x of typo Int. In reiponse to his cecaraton, te cele wl locate |e. reserve a memory space of two byes and wil nae tha pace as X, tht afer we can use tat x Inthe progam, (CPA Notes : Prepared by Samir Leleaig Kulkarnt's Glasses, Dombivil 2g2 —itprcs miata; Inthe shove staiemant, we re deciring four vratios P,C, Mm and total of type Int. In respons to hs ‘ecto, the compli wil aipeate Le. eserva a ramon space of fWO byes ach an wil nae tat space wi respective variable rams. Once hee yeles ae declared, eer we can use them in be progr. ead Inthe sbove stalénts, weer declaring toe variables y andz cf ype It, float and char respostvy. In respon fo these detratiots, thecompler wil locate |e. reserve a memory space of two byes fr x, fOUr yes fry end one bye for. fotet~ In language lhe varias tal you are ging use in a program must be Geclareat he begining ofthe program Note 2~ In Cre, is possible to delare the vars anywhare i he program wit the nly ration hat the variables must be decared before they are uted. ‘+ Inaleaion whe ‘Conse the atoning oxarpio, Intcount; Duo to tie decoration, the compler wl locate a memory space of two bys and wil name tha space 3 ‘count Howoyer tho valua ofthis spce le not guarantee. tan be amjwhce betneon 32786 to 32767 Honcat |s cd tha the valu ofthe count wl be garbage. ‘Suppose In ou appicaen we want that nal value of count o be zero and fot the garbage then we mut Ina te value of count ozo at rete of deciaton oi. I canbe easy obainec flv Incount=0; Tei vl needa vas so Ran be ny ald ae aecngtsh aplton Fores vox 2s; font y= chart 4.2.7 Operators = ‘tn operator red inca ohan aft wath ho precaeng and asa. et priory” ‘Operators es ‘Associativity | Ps Cokie ; ao = [aie plant pic~ = vay any any une Ce) set new dee [| Right a EB Left Right : oto Pe See ot ge roo = af Right z Leto Ript et Ri Lei Leto ‘otto rane ‘et Rare ‘eno rare ; Let RAL 2ST = =e RiptLat Lett to Right GP: Notes : Prepared by Samir LeleKutkarnl's Classes, Dombivil FE/CP-1 as Paxpone am Ration Subecion Mugieaton, 7 ‘Dion | % ‘Modis apa give romain Beams | 14594 10%5 90 347 96 547 95 48%5 3-3 34535 BHs 35 13535 | 1 Operators = ass J coe tar Equal : | a q eonnnnaa-anemanape eee ee 2-9 eee 2 = ee ‘Assignment Oparater ‘+The asionment operators usd io form assignment statement 1+ Tho general syntax of he stsignment statement i givon ae flown, variable = expression ‘The expression a the rit hand sot solved frst orsut to a single value nd hat vale wt be assigns to "he vail presto the left hen ste. The previous Valeo the vataie wil be overwriten by new valve, gat wtxy.z: ways ‘The values ofy& zi be aod andthe answer of adaion willbe arsignd othe varabie x. The preva value ‘of xl be ovrwrten bythe ney atigned vale, The vee of y and z wal romain unchanged. 282 nteount ‘ve tothe above assimontstelemen, one wil be adcod wth te valu ofthe count and he ans of adeton wl be assigned back he variable coun. The netfee hat, the value of curt i neromered by 4. SSE ECT ESE GP-1 Notes : Prepared by Samir Lote 44Kulkam!’s Glasses, Dombivii FE/CP-1 Bitwise Operators — Operator Purpose 1 a Bitwise AND ra ‘Biwise OR * Bitwice EX-OR [=e Bivise NOT (one's complement = Biwise Left Sift > Biwise Right Shit ‘To understand the bitwise operator, consider the ftowing examples. Int&= 18, y= 26,2: ‘ex y. oTolofol [oToyoloy [oyoyofi] Jopoyits [xi ofofotol tofofotol fojofo}1| |1}ol1 | 0 lyezi, olotefol fefofoto} fofololt] folols[olz=xay=t, Qeexly ofo[ctol jefoleloy [oloye[s] [opol1]i fre, otalofol felelofol [ojolol1 +fo[+ = ofetefol Tololofo} jojolo}s tho tat feexty=2re Brorasn Ee ; ofoltotol Jolololol Joyoyoyr OPO Ta | 4 xis | ofototol| folofolo| [olololr [0 [4 {0 ly=26e otetefot—fotololol [olololol [3 lolol: lz=x*yets | Gaze FER D—H signed 6 65516, Head os unaigned i olojoyet feyetofo| [ofofo[r| folol1]s [x=t¥ 4 ht TEI 1 ot 4 | faaeae : ofofoyo] jo coats tot OrexXt 2 ofolofo| Lofopopol| popojofr CLO Li] 1 [xis oF FL oF | OA oF of 04 | oF 07) 171 0. 17) 17 0 Lzeecet 36, "Beak | [naeKes; i ofoTofoT ToTovofoy TofofTofs], TolTots Ts [x= i ©0000 0000 $00 { 1 0 0 0 Baxdezetny i (oToToToT TofoTofoT TrloToTsT T1ToTo To [zxces=1820 ] DYESS : i oTo[o;oy Joyoloyo] Joyojoyt Te [To ofolofo} [ofolofo| lolololo| [1{:lol4 eR (oToToToT TeToTotoyT Tototots| TrTo[sTo Ty=280 i (oleTeToT ToTotofet TotoTolTol Tofols Ts [zep>aste | Note! the binary number is shifted toleftby numberof positon. then its value gets mulled by 2°. Noted Ifthe binary number is shifted to right by a! number of positions, then ts value gol civded by 2 CPA Notes : Prepared by Samir Lele 4142Kulkam''s Classes, Dombivil FE/CP.1 Updating Assianment Operstors— Following ae the diferent updating assignment operators use in C+ a ® “= ‘The effect ofthe above operators can be undarstood from the folowing exemples Operation Equivalent Operation Xe X=X+4 Y=2, YaY=2, 23: Wied; Um 5, AaB; ARB: aa Consider the folowing example, Xeeyvez; voy Nena Xaxeyez; Xex"(Y9Z); {nthe above example, the statement using the updating assignment operation is shawn and to understand ts effect ‘wo possiole options ere shown. The option atthe left hand side is incorect whereas the option shown at right is correct. The justification is given as folows, tustfieation - When we use any Updating Assianment Operator then the expression at the right hand sie Is solved frat to resuit into @ single value. The variable at the left hand side is then updated with this value. The type of the update is decided by the basle operation nt Operator (+4 + The increment opertor (+) s used to neroment te vale of avaiable by 1 *+ The increment opertor i ether use ae pre neremen! operator or ost-neemnent operator. Consider the folowing example. Pre-incromant Postincrament x=3; x=3; tox; xy Due to presincrement operator the vaiue of x willbe | Due to postincremant operetor the value of x wil be inoremented by 1 and it will become 4. incremented by 1 and twit become 4 From the above example, it seems like that there is no diference between pre-increment and post-inerement operator. However, that isnot the realty. To understand the difference between the two consider the folowing example. CP.1 Notes : Prepared by Samir LeleKulkamt’s Classes, Dombivil FE/CP-1 Presincrement ost inerement x83; x=3; yates vax In the above statement there are two operations, one tnorement and the other is asslanmerd. Since the increment operator is used as pre-increment ‘operator, the value of x willbe incremented frst, 60 that ‘twill become 4 Thon the incremented value of x Le. 4 is assigned to y ‘and hence value of y wil become 4, Thus, the aseignment statement, y = ++ x¢ wil be equivalent to, xextty yex Inthe above statement there are two operations, one is increment andthe other Is assianment. Since the inerement operator is used as postinerement | operator te assignment wll be done frst and increment wil be done later. Hence the existing value of x 1. 31s ‘ageigned to y and hence the value of y wil become 3 ‘Than the value of x wil be incremented by 1 and x wi become 4 Thus, the assignment statement, y =x 4+ ; wil be ‘equivalent to, ya waxed: ‘+The decrement operator "+ The decrement operator is used to decrement the value of variable by 1. ter used as pre-decrement operaor or posi-decromen! operator Ki Due to pre-decremant operator the value of x wil be decremented by and twill tome 2. ‘Consider the folowing example. Predecrement Postdecrement xeS E35 Due to post-decrament operetor the value of x wil be decremented by 1 and itil become 2 From the above example, lt seems lke that there is no difference between pre-decrement and post-decrement operator. However, that is not the really, To understand the dfference between the two consider the folowing In the above statement there are two operations, on sdectement ad the other is assignment. ‘Since the decrement operator is used 6s pre-decrement ‘operator, the value of x wi be decremented first, so thet Itwil bacome 2, ‘Than the dooremented value of x Le. 2 1s assigned to y ‘and henoe value of y wll become 2. Thus, the assignment statement, y = - x; wil be equivalent to, xex-dy yes example. Predecroment Postalocroment xe3; xE3; yeexs yax- Ine above statment tere reo opertns, one decrement and the other is essianment ' Shoot decrement operaloris usd as postdecrement porate ecelgrenet wil be cone fat and decreret wl be done later. Hence the existing value of x Le. 9's assigned to y and hence the value of y wl become 3 “Then the value of x wil be decremented by 1 and x wil become 2 ‘Thus, the assignmant-statement, y= x - = ; wil be equivalent to, yoni weet CP.1 Notes : Prepared by Samir Lele oa CoE ae 4114Kulkamis Classes, Dombivii Exercise ~ ‘n each ofthe following exemples, determine the value of x andy. axeig yea x220_yaid xe x81; y= YERers wolf yets sox yats Fow more operators are yet to be discussed but those willbe covered in the futher text wherever appropriate, We wi ddscuss three terms before we proceed to next topic. XN Unary Operators ~ The operators thet operate witha single operand are called as unaty operators. Til the point we hhave ished four unary operators and those are: ! - ey a ‘Binary Operators - The operators that operate with two operands are called as binary operators. Except the above discussed four unary operators, all the operators thal we have finished il the point ae binary operators. Temary Operators - Tho opertors that operate wih wee operands ae called as ternary opertors. There is only ‘one emary operator Le. 7: (yet o be decussed). ssions — in ‘+ The expressions are formed with the help of operands and operators, ‘+ The wo broad catagories ofthe exprossions are given as follows a) Mathematical expressions 1) Logical expressions + The mathematical expression wil result into a value which wil be any valid integer numbar o Naat type number et ‘ouble type number. ‘+ The logical expression can result only nto two values, ether ue or false. Exercise — aes ite the expressions forthe following statements, ~ 1) as equal 30 and bis not equal to 10. Ans: A==30 dh bl=Io 2}, ‘The produto y and 21 added wth the val ofx From that ane of ation the ws being subiracod and thenetaneweris asgnedtoR. el zw Ans: planes : Rex 3}, Whte the expression forthe folowng, Vo (+ x/Q +/('49))) ue sat Liwheg.e)) 4) Wie the expression whose value will be tue with the folowing constions. A student must clear MECHANICS and should cear any one subject cut of BEE and CP. nw: eemades if am >= 40 be (mme240 |; (Koassain-Memantcs~ Scb—-f peter) mb>=40)) 7 Pr ePA Notes Prepared by Samir Lele 4145 eyKulkarn!'s Classes, Dombivil FE/CP-1 1.28 7 ‘+ The pre-processor direcives are the directions given to the compiler to cary out specie task even before the ‘compiation ofthe program starts. “+ Since we are directing the comer lo cary out specie task before the complation process starts i's referred pre-processor directives, +The pre-processor directives are not he statements of te language. These drecives stat wih #. “+The pre-processor directives never end with semicolon. + Following ere the common used pre-processor directives. a) define ~ Thepres ine lo. ‘Consider the following example. define PI3.14189 Inthe above example, we define @ symbolic constant named as PI whose equivalent value willbe 9.14180, With this dvective we have informed the compiler thatthe Pl is 2 symbolic constant wit its own value. Once the ccompiation ofthe program star's, wherever the Pl occurs inthe program, i willbe replaced by ts equivelet val. by # include — The se is fe spect es wit am ‘Thece are many facies avaliable inthe coro of C++ language, However, thre are many mre faites which are avalable outside of te core of C++, These facies are evalable In epecif fs, These files are cals 3s header files and ore also called as library files. Consider the following example, 4) Tose the mathematical facies euch as sin(), cos(,tan( , lop). sat) etc. a fle called as math.h must be Inclided. The corresponding pre-processor ciractve wil be given as folove, Include
‘Due tothe above pre-processor directive, we inform Lo, we dlrect the compile to include a fla called as math-h, 0 that # we use any of the above discussed facies, the coniptation error wil not occur and the feelitios wil become accessible. 2) The scant) and print() ar the functions for reading and displaying the deta. To use these functions, we have to include a fie called as Stdio.h:The corresponding pre-processor crectve wil be given as folows, include
‘The sido. refers to the standard input output heasr file. Once we inclde the fle Stdio.h, we can use scant) ‘ane print in our programs. 13) The cin and cout are the objects which are used for reacing end displaying the data, Fo use these objec, we have to neice fle caled as lostream.h.The corresponding pre-processor direcive wil be ven as follows. # include
“Tho itoam.h refers othe inut outout stream header fle, Once we inciude te fe fostream.h, we can use ci and goutn our programs. “There are few more preprocessor drecives used In C++, Those are liste as follows, ait tel #olif fendi — ifdef lind ‘GP-I Notes : Prepared by Samir Lolo 4116 SG eee. : Re Crete ea ore is : ‘ ‘ ee Hoag teens ae * sy
You might also like
UNIT-1_PSTC
PDF
No ratings yet
UNIT-1_PSTC
25 pages
Bhavya 28th January 2023 Notes
PDF
No ratings yet
Bhavya 28th January 2023 Notes
13 pages
C Programming Notes Part 1
PDF
No ratings yet
C Programming Notes Part 1
24 pages
CCP Set 3
PDF
No ratings yet
CCP Set 3
21 pages
New ?
PDF
No ratings yet
New ?
25 pages
C Programming
PDF
No ratings yet
C Programming
42 pages
C Programming and Data Structures Notes Sample Compressed
PDF
No ratings yet
C Programming and Data Structures Notes Sample Compressed
8 pages
Character Set & Identifiers
PDF
No ratings yet
Character Set & Identifiers
30 pages
C Programming and Data Structures Notes Sample Compressed
PDF
No ratings yet
C Programming and Data Structures Notes Sample Compressed
8 pages
New C BALU
PDF
No ratings yet
New C BALU
214 pages
Exercises C++
PDF
No ratings yet
Exercises C++
37 pages
Apnotes PDF
PDF
No ratings yet
Apnotes PDF
63 pages
Lecture3 Week 2
PDF
No ratings yet
Lecture3 Week 2
21 pages
Oodp Unit 1
PDF
No ratings yet
Oodp Unit 1
38 pages
OOPS
PDF
No ratings yet
OOPS
53 pages
5 Lec Datatypes
PDF
No ratings yet
5 Lec Datatypes
23 pages
Constants Variables Datatypes
PDF
100% (1)
Constants Variables Datatypes
44 pages
Computer Programming 2024-2025
PDF
No ratings yet
Computer Programming 2024-2025
98 pages
Lecture 02 Prog
PDF
No ratings yet
Lecture 02 Prog
21 pages
Imgtopdf 2909221401056
PDF
No ratings yet
Imgtopdf 2909221401056
39 pages
Teaching Slide DAY 01
PDF
No ratings yet
Teaching Slide DAY 01
31 pages
Conceptofcdatatypes 090925045031 Phpapp02
PDF
No ratings yet
Conceptofcdatatypes 090925045031 Phpapp02
30 pages
Course Notes
PDF
No ratings yet
Course Notes
74 pages
Summer Training Report
PDF
No ratings yet
Summer Training Report
15 pages
C++ Notes FULL - Compressed
PDF
No ratings yet
C++ Notes FULL - Compressed
176 pages
Esterel Language v7 Ref Man
PDF
No ratings yet
Esterel Language v7 Ref Man
207 pages
C++ Notes: LIX, Ecole Polytechnique
PDF
No ratings yet
C++ Notes: LIX, Ecole Polytechnique
35 pages
Reference Manual
PDF
No ratings yet
Reference Manual
61 pages
1fp2023
PDF
No ratings yet
1fp2023
68 pages
Foundations of Programming: ENGI 3891
PDF
No ratings yet
Foundations of Programming: ENGI 3891
29 pages
Unit 2 (Elements of C)
PDF
No ratings yet
Unit 2 (Elements of C)
39 pages
CS205-2020 Spring - Lecture 2 PDF
PDF
No ratings yet
CS205-2020 Spring - Lecture 2 PDF
54 pages
Unit - 1
PDF
No ratings yet
Unit - 1
58 pages
C++ Unit 1
PDF
No ratings yet
C++ Unit 1
26 pages
Lecture - 02-Basics of C++
PDF
No ratings yet
Lecture - 02-Basics of C++
33 pages
c programing 1st unit introduction to programming
PDF
No ratings yet
c programing 1st unit introduction to programming
11 pages
Assignment
PDF
No ratings yet
Assignment
33 pages
CPP Notes - 01
PDF
No ratings yet
CPP Notes - 01
30 pages
C - Programming - COM 121
PDF
No ratings yet
C - Programming - COM 121
32 pages
C - ch-3 Consts Varibls
PDF
No ratings yet
C - ch-3 Consts Varibls
42 pages
Research Work
PDF
No ratings yet
Research Work
9 pages
04 C++ Programming 4 Competitions - DataTypes and Variables-1
PDF
No ratings yet
04 C++ Programming 4 Competitions - DataTypes and Variables-1
26 pages
PART 1
PDF
No ratings yet
PART 1
9 pages
MIterms
PDF
No ratings yet
MIterms
13 pages
Leecture Notes On CPP For Java Programmers PDF
PDF
No ratings yet
Leecture Notes On CPP For Java Programmers PDF
289 pages
Lecture Notes On C++ For Java Programmers
PDF
No ratings yet
Lecture Notes On C++ For Java Programmers
289 pages
Cpp4java
PDF
No ratings yet
Cpp4java
289 pages
U2
PDF
No ratings yet
U2
94 pages
C++ Overview of C++: Object-Oriented Programming
PDF
No ratings yet
C++ Overview of C++: Object-Oriented Programming
35 pages
Programming Fundamentals
PDF
No ratings yet
Programming Fundamentals
169 pages
C Programming
PDF
No ratings yet
C Programming
33 pages
C
PDF
No ratings yet
C
83 pages
CPP I-II BSC
PDF
No ratings yet
CPP I-II BSC
244 pages
Characteristics of C++
PDF
No ratings yet
Characteristics of C++
13 pages
C Language {Unit 2(Part 1)}[1]
PDF
No ratings yet
C Language {Unit 2(Part 1)}[1]
20 pages