0% found this document useful (0 votes)
69 views

C Programming & Data Structure Sample

Programming in C

Uploaded by

NaWin NK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
69 views

C Programming & Data Structure Sample

Programming in C

Uploaded by

NaWin NK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 8
PROGRAMM i onto ca MF 20s initially developed by Denis Ritchie tr te yearitn, at the Bell Telephone — Laboratories to develop the UNIX sand system C programming is considered as the base for the othes Programming danguages, that's wohy ib is known as mothers donguage + iS C danguage is the system arene donquage because it can be used to do tbow- devel sammiing « Tt ts genesally used to create hasdwave devices, Operating system, dsivers, Kkesnels ete. ‘The main features of the C daonguage Includes ow - devel memory access, a simple set of Keywords & a clean style. Tt ts used tn dot of scientific computing Like ALIML weather wecasting ete DE cle++ code ‘. very faster than a@ code toritten tn qova, python. oe it C tokens ase the basic buflding blocks tn C dang. C token ave the smallest see units. © keywords @ Identifiers © Constants @ Operators @ Special Symbols ie Regwords ase predefined & seserve words used in progsrammb that have special meanings to compiler Programming is gs P (nt money; Hese, int ts keyword and money is vartable- Keywords axe auto. break, chat, Continue, default ete These ase keywords in C Language WG Tentigtys vefers to name given to entities Such as variables, functions , structures ete. Tdentifiess must be unique , as me ave createcl to give a unique name to an entity to identify i during the execution hele Tdentifives names must be difjevevit from keywords. @& int money j Here money 4 accountbalance ave Wenti- double accountbalance ; -fiers- (Constants) WA constant is a value that “anitbe changed tn the program. 35) Dectmal constant - 10, 20, uso ete. Chasacter constant, ‘a’ ‘bh’ ete, Octal constant - 021,038, o16 ete. (Operators) mt a, operator cs simply a mbol that is used to pesfoxm operations. There can be many types Of operations dike artthmetic, dogical, bitwise etc. eo. . Operators [+,-, *, / ] Relational Opexatovs [< , ¢ Logical Operators [ 22 , Il, J J is In programming danguage, the special symbols have some Special mean ie and they Coun not be used for othes purposes. OP 1 348k ease cete { €xclamation mark — Underscore = Colon + Number stan + plus sign > semicolon “le Pexcent stgn > comma "Quotation mask & Ampersand / slash ? Question mask * Aste visk = Equal to sign * Period. 3 Sess W& A © program basically consist Mellelisey lida ¢ of the following pasts — tf include @ Psepsocessos Commands int maine) 4 ® Functions I"fixst program “/ ® Variables printf" Hello , World }\n"); ® Statements & Expressions veturn 0% ® Comments det us take Q took at the various pasts of the above “Hello, World!" Program — The first Line of the Program #Hindude fs a pre-processor command which tells a ¢ compiler to (nclude stdio-h file before going to actual _comptlation- The next Une int mainc) ts the main function uh- -ere the program execation begins. M& Te net dine It -----. *[ ell be ignored by the comp. -tles, so such Lfves ase called comments in the programe NGF The next Lime printi--) is another function ushich causes the message “Hello, World!” to be displayed on scxeen. HG Te next tne veturno; terminates the matn function & returns the value 0. 1& data types wefers fo an extensive system used for dedoving variables ot functions of different types: “The type of a varlable determines houd much space tt ocu- “pies ln storage. Different data types have _ddtperent anges to store nos. KE Basically data types Qse of different types — @ Primasy Data Type (char, Hoat , Int ) @ User defined Data Type ( Enum , Typedef ) © Desived Data Type ( Pointers . Axvays » Stwuctures » Union ) known as fundamental datafef types because they ave presi Bio le) y 1 lag to 127 float | 4 _(12€-2e to 3UE +: 8 |236-s00to nr 4909 AF defined in C tanguage. At i Prsimasy data ty pes in C {2| chav (3 ase of Htypes + tnt , chav, E E M int data, fype is Used fo shore integev values. Ran Writ fan be signed oo un signed Signed tnt— Wt tas generally 32 bits (4 bytesh | Unsigned tnt-[B eeer is signecl- The char dato type stese the § characters~ WF chasacters must be _insid. single uotes: Bett usualy 4 ie cone: Ulheneves we entex a characles t pe variable, the chara- ~chee is stoved as tn we {Pe V The float cata type ts used to Stove the geen point numbers. The numbers that have a fractional past are callecl ating point numbers. Range: [ ti +38 or has generally 4 bytes « ™ These can xepresent @ much dager and colder vange of Atgtts as compares to integer data types = The double dota type is used to stove floating numbers « Tk occupies twice as much memos: Mart has genesally @ bytes Range: int - [0 20, 30, 100, 1000, 586 ete ges value in the Oddvess Location as float data ohare = saline hk tn ist ix! ORI ek” ORL Seale clabe Hoat — . 07.,0-33.,.-@/21.,. €.43.,- lovo.29.,.. 562.01 etc. double — 32.334000 , 144.4698300 ete: ration Data Typ WU Enumeration Cenum ) bs Q user defined data type- PEhuwr data sty pe! Tt ts mainly used to assign # Include names to integral constants. int maint) f Value assignec! must be tn Wange) Chum detter {a.b, dP}, of signed tnt enum detter fede Syntoxs enum enumname 4 35 printf ("La 4); Bea | enum enumnames retusnd; 3 ronversion” Specifies | BG The conversion spectfter chavacter Spectfies whether to Inespret the Cowsesponding chavacter . a stsi Qn integer or a Ky DPPLLLIL signed int uu Unsigned int cbh{ | shost signed: int chu short unsigned tnt arg ument as @ Potntex String ° 1X | Hexa decimal shlu Unsignect bong int stl unsigned Long long tnt | «ko | ecto, Integer BO A variable ts a name given to storage area that ous programs can manipulate. AEG) (iaiglikiees BEF Tivo main Concepts of variable) void main() © Declavation int a © Lnitialization & Usage Q= 10, Vastable name stasts with Jowes A>; Ov Undesscore (_)- tnt abcd; ~» declorin multiple variables tn singe line (nt ass: tnt b-s; prigeaaning 4 (vilializing variables. (Ctonstants | se A constant” is a value ee can't be Changed Cn the case program: @ Chas > '#', 9 she ROS ap Types + chav, stsing » integer | ‘abc’ > X Alot a char eal valued + ro Sea tmpty can't be @ String> "GATE", “Book”, chat “India is my Country” a > X Not valid. must “Meuton Desk ” be in single quotes- OPERATORS = >, opevatoy is a symbol that tells the compiler te_perform spectHe _mathem étions. ee RSS ee Descstption’ int maine) § cS See Se | Int a=n ,b24; | 7 Adds troo operands. printf ("Sums %edl\n", ath); thd\n", a-b); a jeompatl pelt C" Dip. print C" Quotient = edn” , lb); printt C" Remainders 7/-d\n", acleb) Divtoles de-nums printf Casved\n" 4a): L a See retun 0; of after an integer dvision: _| s} Op: r+ Inexement operator increases the. | Pavartt feger value by one. aie vator clecreases |b value by one. | RELATIONAL OPERATORS _|-7— Gereple op. Description Foe (ee [Checks 4 the values of tu 0 ands 4 —-f La> b) awe equal or not. Lf ves Es i print ‘eel ESgreatnthansied \n's Ab); —Londition telas checks if the values of ttoo opesards peintt (eye equal or not. T} alo, then the itlaj=b) =a ib becomes Stetitiont ( printflskd ts not equat te e value of deft operand is grea: { P ae ter than the value of right operand veel NN, Gee bl “The value of let operand is | vetusn 0; (ess than the value ot right epertund. the vi value of He dept operanel is greates than or equal to the value of { aight opevand- The value of deft operand ts less | <=) than or equal to the value ot dirigne sperand: el ts equat to-/ed\n/"ab); LOGICAL OPERATORS Desestption Logfcal AND I¢ both the operands are non zero then Cond{tions becomes true. i NOTE ff Toue +L ; Falsero ] 2 | Shovt circuit thease of! 4k Ub there ts @ condlition | Oy where in ex pression that — | retus' t fi Logical oR > Tp any of the © cil ae dena U Il twe eperands ts non zero, Rehcde (ase oF ITE | | then cond* becomes true. | Bence ts a cond” any woh. Logical NOT-> It Cs used to ere fn expression that yetusn ! reverse the Logical state of BUC then rest of the conditions Us operand. Jatter that coil not be evaluates, ean - : BITWISE OPERATORS Ol == See] aS rutse eters a ae agg Opes. “iption ePinpiststet ie pee “g | Blrary AND-—> St copies a pte Bint | o. ° 2 to the result Y U ext fh o.-|-+ Oo aid hn Ss beth operands. fia \ : |Binasy OR > Tt coples a Bt Y | ; ; !& est tn efther operands . eh ak e Binany XoR-> Dt copies the bit of UF Us set th only On€ operand. Binasy Le} shift >The value is =| Binary One's complement» Tt has the effect of fippjng bits. movecl left by the numberof UB specifies by right operand. Blade Right shift —> The de} operanal ds moved sight by the no. of bits speciHesl: Descxiption ° copes. Description A “Assignment op > Assigns value! qe [ADDL assignment opts | from right bo left operand. || ~~ | rt aclde aight operands x Subtract ancl assignment opt» || Mi as nse Tt cubsteacts the xight opesany | * = (i multiply ee yb and assign t Left operand: || operand & assign to Lefet~ __ Divide ancl Assignment opts Modulus and. Assiqnament opt '= Teaivides the Lett operand yj. Te takes modulus using tuo with the sisht operands operands & assigns the result passigns’ ope apacoa to left pine K= Left shift and assignment op ar= Right shift and. assignment opr | £= | Bttvise and assignment opr.'|n= |Bitwise Ex-0R £ assignment opr: |= Bitwise oR & assignment opt MISCELLANEOUS OPERATOR LIZZ Returns the addyecs of variable. Re “Pointer to a varlable- ?: | Conditional expressfon- Sizeof OPERATOR [size oh OJ Jar ae SizeoFt) operator com- ~putes the size of vasiable Cogte)- siueokt) Returns the size of variable 2 a& Tt (s a unasy operator. BG For float values use dike this Le lo2F atheswise tt wlll be treatecl as doubleCio2) os use typecasting fox float and clout For chasactes data type te chay values” use typecacting or dfrectly use datatype oy variable- Operands can be variable , constant data type. (ERD Stee of cx); , shaeof lint); , sizeoPs); (yee casteNg yg Tt refers to changing an variable of one dala type tnto another. BE re compiles uwatll automatically change one type of data tnte another [Ff [tt make sense. Types “EMPLECET “TYPE fERPLECE TESTE} ® When the type conversion is perfor-/ ® The type conversion performed -med automatically by the compiler by the pot mmex bs posing the without Programmer's Intesvention data type of expression of spechHe Such type of vonversion is Known type ts known as expltett type as implicit type eonversion or type 7 conversion. int, Fox (x=97; X€= 122; X44) promotion. & tntx;, for (X=913 xc=122; x44) Fr ¢ oe rint? Unc", (chav) x); Ip 3 print# Coc; x);

You might also like