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)
69 views
C Programming & Data Structure Sample
Programming in C
Uploaded by
NaWin NK
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save C Programming & data structure sample For Later
Download
Save
Save C Programming & data structure sample For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
69 views
C Programming & Data Structure Sample
Programming in C
Uploaded by
NaWin NK
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save C Programming & data structure sample For Later
Carousel Previous
Carousel Next
Save
Save C Programming & data structure sample For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 8
Search
Fullscreen
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 Symbolsie 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
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6125)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (932)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8214)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2922)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Tóibín
3.5/5 (2061)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2530)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Steve Jobs
From Everand
Steve Jobs
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Yes Please
From Everand
Yes Please
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel