You are on page 1of 20
S+1 Onit= EL Roe oe Liles Seas Tabvaduchan ~ teed Por eine brit ruta llercbin ~ with a Mrattine — UNI — Preprns Steuchtes ame unfors — Ss, ie Oe Ss eprrewrary ll Yeipves Dnbaduthe: 2 Arreyy on te used fe Tefrreserd ® grap Ob talerreteted dole tera of ea bypes onclen Gama neme » tnt aL =% % 273,45, 6 7,9,9, ray Chey aCah= FA ‘ it La aT ey ' ae | il Bhi Ynteins ome 8 pire Hema a Ua bye in wheel Vidal lament, tur Alien in type . =A oe At tuchew mey Grtein — int z aly. amd cha Aimer ebe. ’ The Ircbvictual — olimapla on, nla remo TF hey werd “Shree 4, Stick Sivactuu name S4nibevne : Struck ~ element ty Shuehe — ebemwat 2, strwtprre elirrant 2, 4 ya Stratk Shrechou— name Viz 02... va; eeu pe ' Skrutt Stud int voddno; > Shnu oo chat name rely A fat mek; 4; ot Sheatalrte VAP” shuct stud 7 a. Tt access dhictuhe members SeTellpe “Seflame — S-rtahe oars «hefner Reve aed Stench At eA Chat ig > Array, bw Gllechen PR Shnthoe tA tallehyn t simile daletyes B Assyratan ete hypas DP Arrey 4 olewed >it ww a vserdiine pe. dolatrpe - > The Strochne wernberd Gn be nities vorg Vericubatle. PR Gn nMera cor bike novmal vote, wh th pesitim. = Da — pepcagien fo print valu trom Streatéroue 7 / Abin duds Hindu Zanwoh> Stead std i int a; 43 Stuck std x; Vad mado O) Mas 5S, ronté/» 5 #0" he Falew of A 64 vd", a) Setbad + The valos ae Must ba bmn apes Sirathtu Vabrakd an as Vorable wth — elot CA! Catal Cn ewpll = At Steuchoe with Taifalizaton dttincluck tincudls sean font { “printh[™in Med \rit Yas! adgAA ols eA onde sheng) printf{"Enter the student details: 4.3; it seenf(“2%s" fi aie): 3 . prinef("Enter 3 marks"), camfl "2d Seed sea sm2yfee{ sb m3): sf] totab>sfi) aml sft]. 2+]: sfi]avg=sff}xotal3; isfi].ave=40) ‘sfil.grade=D'; else iffs{i].0vg60) s{i].grade=C, ep else i be sf grmten'a’ printit"\n Details a"); see \t Mark2 \t Mark3 Mt Total \t Average \t Grade"), font lsicensint) uae", e[f].rolino ef], name, ral s{i-m2, ourrur ccoter number of students:3 Enter the student details: | Enter the roi! number 101 Enter the name RAVI Enter 3 marks 70 80-0 Enter the student details: 2 Enter the rofl number 102 Emter the name GOPI Enter 3 srarks 80 60:70 Enter the studeit details: 3 Enter the rofl nurberl03 Epter the name DAMU Enter 3 marks 80 20-40 Details Rollno Name Markl Mark? Mark3"\._ Tot 10 RAVE 70 80 102 Gori 80 o 103 DAMU 80 20 De 20 70.0, Oe 140 Avernge Grade 80,0000 A 770, 000000 46.000000 ED PROGRAM (10:2) EMPLOYEE RECORD USING STRUCTURE*/ inelde int'enter number of employees:"); Fant" en), for(i Bic=mi-=) ( 5 Ente the salary"); scan"¥6f", efi] sal); ye ) 4 print a Detail in"); ‘printfi"\n ID no '¢ Name Mt Salary”); foe(i=Ti<—estr=) printit"\n Yod ‘e Marit efi} idno,e(] name,e[' oureur enter pumber of employces:2 Enter the employee details; | Enter be ce TL Enter the name XAVIR Enter the salary 50000 Enter the employee details: 2 Enicr the «d number 112 Eater the same MAHESH Enter the salary 90000 Details ID 9 Name ‘Salary 111 XAVIR. —50000.00000 112. MAHIESH — 90000.000000 oa GD Apo egy me Shruchou (Need Shuchte) : Str. coltlen > Strucnre wvilFen in Gole anol Shruchowe 5 eked 04 ot bwa Abruchows - > WMedped Struchius are allowed in CP prony We an Wife on Sirncher Vosthe orotic Abruchix aA Mimbo of onotitr tH rnchity, eon Soares Stewed Evople yea Cha ena €203/° nt Sy} Pleat Salad! Strat debe i int dake. int ron th, ioe Yeas J: 4 dei emp iy Bok Aecedinns) Mud ACeormny month hecextn| hoy Aecewnsy Year members 19 abaye eroug le: + emplede}, month 4 ewople de}. doy . % Mpledey. yen. example . we ilan Sbewcdibd FY Pepegene wage SENAY ead opie: wre) 7 /*Nested structure example program*/ include struct Employee { ehar oname [20]; ant ssn; float salary: struct date t ! int date; ant month; int year; jdoas femp = {"Pritesh™, 1000; TORO, (22,6,1990) by ant main() { printf ("\nEmployee Name : $s",emp.ename) > printf ("\nEmployeesssn > $d",emp.ssn) 7 printé ("\nEmployee Salary : #£",emp.salary); printf ("\nEmpl5yee DOJ ; ta/ea/sa", \ emp. doj . date, emp.doj.month,emp-doj. year); return 1; + Output: Employee Name Pritesh Employee SSN 1000 1000. 500000 22/6/1990 Employee Salary Employee DOJ ° Union nan rahe x Te Unie te declared jut tne Adriehte, but only Keyes) — oleffperua . © the dtlftiunce behwoun union & Strath 44 in terms of @ Stovege. Xi stadien eich peniay fad Tapodayy Mrepe detahoy , wheru abs all prembern “ unio hea Aame Leafy tA Stating, Sp tae Uni -Unwn—nams, i Union menben 1,” VAIO renmbet 2 Umea Une — Vesvable able, ee ee Ge) ohanapdt Unig Tesnde i . ink madiks Float wg 5 / chen a ede; 3 std ; wa union sey 4 Se os Qradse Char Negte) reeks ae) | << SSe D Rote: at a time UMLy om member Grte neta a foun witha =o of rremory Dikte@ecnee behverrn Stucke & Oh a ee oe X Cvery rember has Hes x All munbens vse come Men memory Apate memory Space - hey cord Strud muad |v key wird Ulm 64 cad. © An Y Pani be? Gr be ag ene Ot anytnas with ly erily evs rite rad Asc Gun be ated Wi frart AS ale. t ge "Ik an be Fntbuled with \* Btonly Fhe frrgé reardens au Fhe Splerabeoae ie ee hake n PROGRAM 5-13 /*{Ex 10.3) STUDENT DETAILS USING UNION*/ #inchude union stud { int rolling; char name{50}: int ml ,m2,m3,total; Bout avg; chur grade; }a(50}; void maing) f ‘nt bm, Printfi"erter number of stucients:"); seanit"ad" An), Bax(inl;iemir*) t Fetes Yar Balin a eerie a janarafi}.m3; iMfs|i).0e<40) ; priti"n Details", rien) enn Mt Mark2 \t Mark3 \t Total 't Average \t Grade"), po) pntiT™An Med We Mosier dirrecmicrenete ai alee grade); print Enter the student dette: 9}; scans) Hote" si. FOlln6 si] name, sf]. ml si}. m2, Enter the student details: 1 Emer the roll number 101 Enter the name AAA Enter 3 marks 22 55 6 Enter the student details: 2 Enter the soll nimber 102 Enter the name BBB Enter 3 mari s88 we 8 Enter the student details: 3 Ester the roll number 103, Enter the name CCC Enter 3 marks 66 99 35 Details * Roll po Name Mark! Marke Total Average Grade 6 Bee ee co 6s yeetwnsee 8 or C of 67 67 Gi “ssO0mse oC oT Cc 6 67 67 67) S&op0256 C 4 Storage classes in C programming: (16 mark) In€ language, each variable has storage class which decides seope, ‘visibility and lifetime of that variable, The following storage classes are most oftenly used in C programming. 1.Amtomatic variables (auto) 2.External variables: 3-Static variables. Register variables = Avarlable declared inside a function without any storage class specification, is by default an automatic variable. + ‘They ave created when a function is called and are destroyed automatically when the function exits «Automatic variables can also be called local variables because they @re local to a function. «By default they are assigned garbage value by the compiler, Example: void main() 4 int details or quto int detail; //Both are Same y ‘A variable that is déclaréd outside any funetion is a Global variable. + Global variables remain available throughout the entire program. + One important thing to remember about global variable fs that their values can be changed by any function in the program. Example: int sumber? woid main() number=105 + ont mumber=207 } tun2() extern keyword “The extern keyword is used before a variable ta inform the compiler that this variable is declared somewhere else. The extern declaration does not allocate storage for variables. file2.c inchde “filet.c” : ee) ‘extern Int a3 fun() ' globo wovible rm one le can Bud nother ng extern eyed Problem when extern is not used: /fertor, cannotefind variable 3 printe("ea"ya)z , * Example Using extern in same fille maint) { Qxtern Ant x} //Tolle compiter thet it in defines someunare xm 107, pebne ("ed") 7 + ist x; //Global variable x pew “get ») att a.Static variables ‘+ Astatic variable tells the compiler to persist the variable until the end of program. ‘+ Instead of creating and destroying a variable every time when iteomes into and goes out of scope, static is initialized only once and remains into existence till the end of program. + Astatic variable can elther be internal or extemal depending upon the place of declaraction, * Scope of internal static variable remains inside the function in whieh itis defined. * External static variables remain restricted to seope of file in each they are declared. ‘They are assigned © (ero) as default value by the compiler. void test(); | //Punction declaration (discussed if next) topic) maing) void teet() + static Int a = 0; JPStatic Wariable as arly printf ("sd\t",a); } output + ig 3 aBegister variable + Register variable inform the compiler to stove the variable in cpu register instead of RAM inemory. «Register variable has faster access than normal variable. «© Frequently used variables are kept in register. * Only few variables can be placed inside register. ‘Syntax: Yegister int numbert exemple: inc ludecstdio.h> void main) register int a=10; print€("The value of a ie td",a)) ? Hun SAS » wd PREPROCESSOR DIRECTIVES IN C It is the program that processes our source program before compilation. ‘The preprosressor operutes under the following preprocessor directives Example: #include include “filename h™ filename h is the name of the file, that cam be included in our souree program. New 6X) Example: #includecstdio. > +#include “stdio,h* 2. Macro Substitution: ‘+ This is used to define symbolic constants in the souree program. + The identifier or string or integer defined Is replaced by rhacro substitution, ‘Symtans ‘Adeline identifier stringlimteger. 2.1.Simple Macros: + Its commonly used w define symbolic constants. Example: define age 20 define CITY “CHENNAT™ define eS define A 10 Here #define A 10: macro substitutes:'A’ with 10 in all occurrencens in the source program. Example program: include afin PL 3.142 ‘void main() t impedes. ler he enti at trad ead); ‘The area of circle is 78.5500 2.2.Argumented! macros +. ‘The Argumented macrosare used to define more complex and useful form of ‘teplacements in the source program. ‘Symtaxz define identifier (v1 v2 vS.......\4) stringineger Example: define maint. ¥) (OX) < CY) ? XD: OD) New 5.20 23.Nested macros: + ‘The macros defined within another maeto called iested macros, Example: fidetine AS adefine BA+2 3.Conditional Inclusion: ‘+ These are used to control the preprocessor with conditional statements ‘define op P min() { ifdef P printf(~Pemium”); else printf{"CELERON"); endif } ‘The other preprocessor directives are! Directive: Function Finciade sed to inchado w ile ele aed to spectiy alornatve tw MESSE [Randel «Yn to nit —

You might also like