Partial preview of the text
Download C programming cheatsheet and more Cheat Sheet Computer science in PDF only on Docsity!
4 _ be Titro (oUStal ated) lh ia A“ general puc pose r, 09 02! 26 a oe Ritchie. 19°72. Bel Lbs jes Lond helps Us __Unolarstand Now [es Popular becausg it is Fost , Widlely _¢upporiad | uncer at hood procyrams” wo Ak ; Le closely comected tp UNIX LiL includs zstdio. A> z Li a os : | 3 || int man C) q 4 f thy | ih iy 5 | printf ("Hello World! \n") 3 ¢ return 03 : =|} Une S| aR include Zotdlo-h> » pireligsioao to neue @ heater i file (C-h Biles), This header File lets vs u Use input /ovlbur functions suct jas print F() 1 \ v Sid: +9 i Standard Storr Pie Jovtpyt i linet C jomores extra, ok hAgc. These ie ony _ysod Jo = make (ole readable. te | od line 3 maint) is a special _-Fynetion This is where The 5 fi UNO, +” everthing with es 8 pact cg) mata ©, hn Aon. ‘ ——— = og ee “Line Be prinkf() isi a Sa a | print kext ko iY LAC cor \SO\D ‘ ~ , Ove : ome | Ye oulpyt tn no _eonsola _s \__ po Wello World \ Ling 6 «I Cohen 0 ends Wwe manl). function Ond + onde a valve pack ke __ be opecating Sry stern. Rebrning 0 usually mwang “evecutnda worked A on ‘woulda Solent atthe Khe return staemont, tho comply considers ‘t- Bot ids stn concictorect a coding ethic to wre ke Bord\acs, Ea ‘ Warne. alistt C trikements : |S Computer _progvam js 0 \\SA> oh _nstroctions [| ? g d Wot oa. seomputer | friows | a fen - a on © ti : = is Tn Cy Hypce instructions are | Called otate ments Eg: > printf" Holla Worle); * rekurn 0: Zuery Statements in CC musk send HE S0op0 _Seqpenets i. Py5 of with a ° si 1onet Semi-con — : : a Cl yers : ord ok | dice hy Greneraly Used > hside Quotes.._or eras ———_————— | ene Pri aS a a ee ae Commants con Ine. _ etna Sing ao mola -ine | , ©) Single Ving comments —Singhe ing Commins = start: voi tuo | forward slaghog ff/ do: TNO) Wis 1s) 9+ tommunt og i v r a print FC“ Hallo lord \")3 Ovtpur: Hallo World| @) pring F (“This wit ron! )s. Howat CT his ait nt ron’), Out: | This will an i () Woe) mee Comments bat. i . tv, { - Pray _kex's _pokween fe ont "ak 7 weil wf ignoc bye Compiley £4: Ae Th, , Codd peony - below. wiry 3 pra Hato Woctsh\” \A_ tha Console a / print FC Heo wordt ); | & ae ae = eee Bees 1 ee ——r= ———= — Date “Types: “a Any Variabo or Fonckon ie} & must wv) es ! specitied data type, and you must clofing & | ae Use On format Specifer Rioidhy _print£C) function q i di : ; i ied fb, = ploss vary al Ce. | pe meats £9: inte _my Num = S | 4} wee hom ae | float my Float Num = 5-99, /l De amal Number | char my loter = ‘P': ||. nw ONeameser \| i | « v onal JAN", maytom)s If %% & is format spedfrer | ims 6) for Tnk& _pint{ (“eof \n") ei Plone wm’) rt is Oo orintt (“foc \n” , Pappstenee myLaler); Dato. Exypes cain 2 ———__|. Primikve Non= Primihve. Ueor ndefined to, Fioak, Pnckon, array, Structure unic®, iarey, alte by pe del cna pniare - ; o — fia ett. = i ee SS | ex | Bike my Trt z is. F\oat ney Flot my yusee: davlolt_My Dosbly 5 i ee chat mr Char s | oo \po o| my Bool. 4] | _puntt(" % zu \n" sige «CC mate) ) 3 \ es Lo LN orinbtC" AZUMV? , cizeok ( myCloar)’) prin bf" Y%oZu\n" , sizeof eo dot) 5 print EC%% 2uXn" , ct 200k ie Y; | | prink £C'% 2U\n “ Stz0@t Caybool)); » @ %otA AS eonat specifier i. used insteacl <4 OFs oth svalibyie lonids ere a expecas She Sizeok pperator +o ret _» Volo __ o\ swt, which 1 an unsigngct Coseage Cnoo— agave soheger byyo,) fype og Uv Saenclta Types 2 Qe ais Hag basic, fy pes Cit, Float, dovb©, chor) , C. also Ges US exbendad Key word Cshort, Long, si Wnsignad | —— Aspe Size Range (comments) i ee! wy VG as : r Pere... bynes ~32,169 to 422168 inn fl ' i mca wt is UHs\aned a ost 0 to §S,3 3S IL ine” 4 Youre oto 42m, 967,.295- fj =e Bs eee sac ea Ss | Jono, ink 4 bytes a) mare to 42. AMT x102 _ 4 TUB XN t 123 40> ae il isa oF € Youtes ie a \2 4-223 High i % —D-LL>HO__ to Aang lens, 3 bytes : wt | Long Q awe TEmolorrentario n dovole. Jor Sion put "more al | bytes ; Aovwe\s « ee | va { \oriolles 2- Voriobls cre conteinars for Sent storing Gato volves, Vike nombers anal Charade, mt OW nex @ Oo 7 ate, type VariotwNoma_= Valve; 22 int muNum = [5 We can also _daclare_ (ny Variable first anc assign tho valve jqter Su: ‘inks my Num 5 A Decleration thapement “tytn we lot tt Assigning Valve . ———- void main) int num = 10s if Coum>= 0) : if Crum t= ©) print £ C Mumbeec is Positive Ne else pant (} Numisee. iS Zero") tice 8 orinté C Womb je n2oarive\)s ——t TPabwelee ph . ve" ) betemenay H# Inch Stig -h> eed Noid man ine tim 2.5 DE printf C" Enter len behwern 0 402359) + Scan a YA", & tima)s if (_ time >=_0 ke Gme <\200)t priatt CS aeracl. Morning! an Veise, if Ctime >=r200 Cal. time < 1900) f ociatk s -Givod_fifternoen }” oe ~ || Write Ov Peogrom to clisplan intone ae, ; = Fe A\ncldR —< Stig. n> am (nt main) t tory e vot te wrt C“ Eater Or YROC iy a scant Gwe a) Biyeor i y | v£ (( year fe 400==0)\| (eee BK ypar%\00l = =0)) : ~ printe C" 4. Ma “Load yoo " uvac)s 0) | ee fact k= aga A I I NU Mason L— o | : printt ie ho factorial Nee Hie faut Fac, 5 sas eee a ee cewrn Op —===—— aa ee ae eee —————_—== | \ » | _-Pe-Iie doog pong Vv TVnk phon vhig loop is a4 Voridnt of the vohie Loo. This \noe sw execute he, code Dlock onc, T bofore cNeckinn if ne condition true, paiva! (eplar “os looy as rendition is bruce. FO) » - Write Leo 5 exe pubes tne Looe Body -ablooss once wolike the others. - Syntax? TaiWaliZanon do 4 II Loop Body i St Sacemun Seem, % while (Ccondite a) S, z — LOeps 3 The, inthialiZatien stolement is eae org v : pace, Wyn ne hee hea i pe ale ale ne test expression \s_ evaluated +o Fulce, Mar Soc oop 1S komnared, i eu eicincied 95 However, if tho test expression 1 a Pega brve, statemuntS ysiclo ne pode of te Poe - | | \ovP are executed - Again test expression | r ¥ 4 otk ‘1s eVawated am —— | ris gross _g.nes__on yori) lest expression | | | | | 1 false — teak Wht eg aie iene oe also Uso a. | —_ lreak andi jump wt Sy We loop sco pe “fy, | + ‘irloae. Renae int main () | ike is i | i 1 | | _for_C i=@ 5 eq jae) i i f = 4 it . - | ie (12a | | break >: | | 4 { print fF ( *d\n" , : ! ; | ¥eturn 0: TT 7 | 3 | i | Output: be | 6 ee | g 3 wi 4 ' —* | ee ya | ees é Ontinue 1] The continue _stakernint’” breaks a LEeratioy and woes to the next _ikecaityy UME a SCAuOM of Pho Leo i op FA tndudt 540g > oid moan for Gm iz05 1<104 ite) O MmCiesuh \ Coninve ; -printt ("4d Aw 5 ye i Ov Naw o ] 2 3 S 6 7 g Ks a SSS Z a a