SlideShare uma empresa Scribd logo
1 de 8
[object Object],[object Object],[object Object],[object Object],Derived Types Function Type Structure Type Array Type Pointer Type Union Type Array  –  Collection of one or more related variables of similar  data type grouped under a single name Structure – Collection of one or more related variables of different  data types, grouped under a single name  In a Library, each book is an  object , and its  characteristics  like title, author, no of pages, price are grouped and represented by one  record . The characteristics are different types and grouped under a aggregate variable of different types. A  record  is group of  fields  and each field represents one characteristic.  In C, a record is implemented with a derived data type called  structure . The characteristics of record are called the  members  of the structure.
book bookid title author pages price STRUCTURE- BOOK struct  book  { int  book_id ; char title[50] ;  char author[40] ;  int pages ; float price ; }; Book-1 BookID: 1211 Title : C Primer Plus Author : Stephen Prata Pages : 984 Price : Rs. 585.00 Book-2 BookID: 1212 Title : The ANSI C Programming Author : Dennis Ritchie Pages : 214 Price : Rs. 125.00 Book-3 BookID: 1213 Title : C By Example Author :  Greg Perry Pages : 498 Price : Rs. 305.00 Structure tag integer book_id Array of 50 characters title Array of 40 characters author integer pages float price 2 bytes 50 bytes 40 bytes 2 bytes 4 bytes struct  < structure_tag_name >  { data type < member 1 > data type < member 2 > … .  ….  ….  …. data type < member N > } ; Memory occupied by a Structure variable
Initialization of structure  Initialization of structure variable while declaration : struct  student  s2 =  {  1001, “ K.Avinash ”, 87.25 } ; Initialization  of structure members individually :  s1. roll_no = 1111; strcpy ( s1. name , “ B. Kishore “ ) ; s1.percentage = 78.5 ;  Declaring a Structure Type struct student { int roll_no; char name[30]; float percentage; }; Declaring a Structure Variable  struct student s1,s2,s3; (or) struct student { int roll_no; char name[30]; float percentage; }s1,s2,s3; Reading values to members at runtime: struct student s3; printf(“Enter the roll no”); scanf(“%d”,&s3.roll_no); printf(“Enter the name”); scanf(“%s”,s3.name); printf(“Enter the percentage”); scanf(“%f”,&s3.percentage); membership operator
struct employee { int empid; char name[35]; int age; float salary; }; int main()  { struct employee emp1,emp2 ; struct employee emp3 = { 1213 , ” S.Murali ” , 31 , 32000.00 } ; emp1.empid=1211; strcpy(emp1.name, “K.Ravi”); emp1.age = 27; emp1.salary=30000.00; printf(“Enter the details of employee 2”); scanf(“%d %s %d %f “ , &emp2.empid, emp2.name, &emp2.age, &emp2.salary); if(emp1.age > emp2.age)  printf( “ Employee1 is senior than Employee2” ); else  printf(“Employee1 is junior than Employee2”); printf(“Emp ID:%d  Name:%s  Age:%d  Salary:%f”,  emp1.empid,emp1.name,emp1.age,emp1.salary); } Implementing a Structure  Declaration of Structure Type  Declaration of Structure variables Declaration and initialization of Structure variable Initialization of Structure members individually  Reading values to members of Structure Accessing members of Structure
Nesting  of  structures struct date { int day ; int month ; int year ; } ; struct  person {  char  name[40]; int  age ; struct  date  b_day ;  }; int  main( )  { struct  person  p1; strcpy ( p1.name , “S. Ramesh “ ) ; p1. age =  32 ; p1.b_day.day  = 25 ; p1.b_day. month = 8 ; p1.b_day. year = 1978 ; } Arrays  And structures struct student { int sub[3] ; int total ; } ; int  main( )  { struct student s[3]; int i,j; for(i=0;i<3;i++) { printf(“Enter student %d marks:”,i+1); for(j=0;j<3;j++) { scanf(“%d”,&s[i].sub[j]); } } for(i=0;i<3;i++) { s[i].total =0; for(j=0;j<3;j++) { s[i].total +=s[i].sub[j]; } printf(“Total marks of student %d is: %d”, i+1,s[i].total ); }  } OUTPUT: Enter student 1 marks: 60 60 60 Enter student 2 marks: 70 70 70 Enter student 3 marks: 90 90 90 Total marks of  student 1 is: 180 Total marks of  student 2 is: 240 Total marks of  student 3 is: 270 Outer Structure  Inner Structure  Accessing Inner Structure members
struct  fraction  { int numerator ; int denominator ; }; void  show ( struct fraction f  ) { printf ( “ %d / %d “, f.numerator,  f.denominator ) ; } int  main ( )  { struct fraction f1  =  {  7, 12 } ; show  ( f1 )  ; } OUTPUT: 7 / 12 structures and functions Self referential structures struct student_node  { int roll_no ; char  name [25] ; struct student_node  *next ; } ; int  main( )  { struct  student_node  s1 ; struct  student_node  s2 = { 1111, “B.Mahesh”, NULL } ; s1. roll_no  = 1234 ;  strcpy ( s1.name , “P.Kiran “ ) ;  s1. next  =  & s2 ; printf ( “ %s “, s1. name  ) ; printf ( “ %s “ , s1.next - > name  ) ;  } A self referential structure is one that includes at least one member which is a pointer to the same structure type. With self referential structures, we can create very useful data structures such as linked -lists, trees and graphs . s2 node is linked to s1 node Prints P.Kiran Prints B.Mahesh
Pointer to a structure  Accessing  structure members through pointer : i) Using  .  ( dot ) operator : ( *ptr ) . prodid  =  111 ; strcpy ( ( *ptr ) . Name, “Pen”) ; ii) Using  - > ( arrow ) operator : ptr - > prodid =  111 ; strcpy( ptr - > name , “Pencil”) ; struct product  { int prodid; char name[20]; }; int main() { struct product inventory[3]; struct product  *ptr; printf(“Read Product Details : &quot;); for(ptr = inventory;ptr<inventory +3;ptr++) { scanf(&quot;%d %s&quot;, &ptr->prodid, ptr->name); } printf(&quot;output&quot;); for(ptr=inventory;ptr<inventory+3;ptr++) { printf(&quot;Product ID :%5d&quot;,ptr->prodid); printf(&quot;Name :  %s&quot;,ptr->name);  } } Read Product Details : 111 Pen 112 Pencil 113 Book Print Product Details : Product ID : 111 Name : Pen Product ID : 112 Name : Pencil Product ID : 113 Name : Book
A  union is a structure all of whose members share the same memory  Union  is a variable, which is similar to the  structure  and contains number of members like structure. In the structure each member has its own memory location whereas, members of union share the same memory. The amount of storage allocated to a union is sufficient to hold its largest member. struct  student  { int  rollno; float  avg ; char  grade ; }; union  pupil {  int  rollno; float  avg ; char  grade; } ; int main()  { struct  student  s1 ; union pupil  p1; printf ( “ %d bytes “,  sizeof ( struct student ) ) ; printf ( “ %d bytes “, sizeof ( union pupil ) ) ;  } Output : 7 bytes  4 bytes Memory allotted to structure student  Address  5000  5001  5002  5003  5004  5005  5006   rollno avg grade Total memory occupied  :  7  bytes Memory allotted to union pupil  rollno avg grade Total memory occupied  :  4  bytes Address  5000  5001  5002  5003

Mais conteúdo relacionado

Mais procurados

Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C ProgrammingQazi Shahzad Ali
 
self_refrential_structures.pptx
self_refrential_structures.pptxself_refrential_structures.pptx
self_refrential_structures.pptxAshishNayyar12
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmigAppili Vamsi Krishna
 
C Pointers
C PointersC Pointers
C Pointersomukhtar
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
3 data-types-in-c
3 data-types-in-c3 data-types-in-c
3 data-types-in-cteach4uin
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in CSahithi Naraparaju
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in CArpana shree
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c languagetanmaymodi4
 
File handling in c
File handling in cFile handling in c
File handling in caakanksha s
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures topu93
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 

Mais procurados (20)

Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
self_refrential_structures.pptx
self_refrential_structures.pptxself_refrential_structures.pptx
self_refrential_structures.pptx
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
 
C Pointers
C PointersC Pointers
C Pointers
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
3 data-types-in-c
3 data-types-in-c3 data-types-in-c
3 data-types-in-c
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
 
Structure in c
Structure in cStructure in c
Structure in c
 
pointers
pointerspointers
pointers
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Structure and union
Structure and unionStructure and union
Structure and union
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
C functions
C functionsC functions
C functions
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 

Destaque

Diccionario de ingles español2 (reparado)
Diccionario de ingles español2 (reparado)Diccionario de ingles español2 (reparado)
Diccionario de ingles español2 (reparado)Laura Gálvez
 
2. museo municipal de madrid
2.  museo municipal de madrid2.  museo municipal de madrid
2. museo municipal de madridchachoray
 
Neuromarketing POR CHRISTIAM MENDEZ
Neuromarketing POR CHRISTIAM MENDEZNeuromarketing POR CHRISTIAM MENDEZ
Neuromarketing POR CHRISTIAM MENDEZdinameq
 
Mobile AirPlan 1-pager
Mobile AirPlan 1-pagerMobile AirPlan 1-pager
Mobile AirPlan 1-pagerDMI
 
Ducray Champú Sensinol Cabello Sensible
Ducray Champú Sensinol Cabello Sensible Ducray Champú Sensinol Cabello Sensible
Ducray Champú Sensinol Cabello Sensible Farmacia Internacional
 
How Kraft Drives Email Engagement Using Native Advertising & Personalization
How Kraft Drives Email Engagement Using Native Advertising & PersonalizationHow Kraft Drives Email Engagement Using Native Advertising & Personalization
How Kraft Drives Email Engagement Using Native Advertising & PersonalizationSalesforce Marketing Cloud
 
Els Navegadors
Els NavegadorsEls Navegadors
Els Navegadorsjoswa
 
Informe del hogar la esperanza
Informe del hogar la esperanzaInforme del hogar la esperanza
Informe del hogar la esperanzaAngelito Engels
 
Guida Ecoidea 2 - La riduzione dei rifiuti all'acquisto
Guida Ecoidea 2 - La riduzione dei rifiuti all'acquistoGuida Ecoidea 2 - La riduzione dei rifiuti all'acquisto
Guida Ecoidea 2 - La riduzione dei rifiuti all'acquistoMarrài a Fura
 
Programa Segundo curso Diplomatura en Cinematografía 2016/2017
Programa  Segundo curso Diplomatura en Cinematografía  2016/2017Programa  Segundo curso Diplomatura en Cinematografía  2016/2017
Programa Segundo curso Diplomatura en Cinematografía 2016/2017Bande á Part Escuela de Cine
 
Sookman lsuc copyright_year_in_review_2013_final
Sookman lsuc copyright_year_in_review_2013_finalSookman lsuc copyright_year_in_review_2013_final
Sookman lsuc copyright_year_in_review_2013_finalbsookman
 
Historia del calor
Historia del calorHistoria del calor
Historia del caloralex mendoza
 
El talento, los trastornos emocionales y otros
El talento, los trastornos emocionales y otrosEl talento, los trastornos emocionales y otros
El talento, los trastornos emocionales y otrosDr Guillermo Cobos Z.
 
Bethabara . il battesimo di Gesù.
Bethabara . il battesimo di Gesù.Bethabara . il battesimo di Gesù.
Bethabara . il battesimo di Gesù.idrlivorno
 
Firebird 1.5-quick start-spanish
Firebird 1.5-quick start-spanishFirebird 1.5-quick start-spanish
Firebird 1.5-quick start-spanishJesus Chapo
 
Sådan laver du vellykket web-tv
Sådan laver du vellykket web-tvSådan laver du vellykket web-tv
Sådan laver du vellykket web-tvDan Hansen
 

Destaque (20)

Diccionario de ingles español2 (reparado)
Diccionario de ingles español2 (reparado)Diccionario de ingles español2 (reparado)
Diccionario de ingles español2 (reparado)
 
2. museo municipal de madrid
2.  museo municipal de madrid2.  museo municipal de madrid
2. museo municipal de madrid
 
Neuromarketing POR CHRISTIAM MENDEZ
Neuromarketing POR CHRISTIAM MENDEZNeuromarketing POR CHRISTIAM MENDEZ
Neuromarketing POR CHRISTIAM MENDEZ
 
Mobile AirPlan 1-pager
Mobile AirPlan 1-pagerMobile AirPlan 1-pager
Mobile AirPlan 1-pager
 
Ducray Champú Sensinol Cabello Sensible
Ducray Champú Sensinol Cabello Sensible Ducray Champú Sensinol Cabello Sensible
Ducray Champú Sensinol Cabello Sensible
 
Eobd
EobdEobd
Eobd
 
How Kraft Drives Email Engagement Using Native Advertising & Personalization
How Kraft Drives Email Engagement Using Native Advertising & PersonalizationHow Kraft Drives Email Engagement Using Native Advertising & Personalization
How Kraft Drives Email Engagement Using Native Advertising & Personalization
 
Els Navegadors
Els NavegadorsEls Navegadors
Els Navegadors
 
Informe del hogar la esperanza
Informe del hogar la esperanzaInforme del hogar la esperanza
Informe del hogar la esperanza
 
Arquímedes 1º
Arquímedes 1ºArquímedes 1º
Arquímedes 1º
 
Revista mandala literaria no.19
Revista mandala literaria no.19Revista mandala literaria no.19
Revista mandala literaria no.19
 
Guida Ecoidea 2 - La riduzione dei rifiuti all'acquisto
Guida Ecoidea 2 - La riduzione dei rifiuti all'acquistoGuida Ecoidea 2 - La riduzione dei rifiuti all'acquisto
Guida Ecoidea 2 - La riduzione dei rifiuti all'acquisto
 
Programa Segundo curso Diplomatura en Cinematografía 2016/2017
Programa  Segundo curso Diplomatura en Cinematografía  2016/2017Programa  Segundo curso Diplomatura en Cinematografía  2016/2017
Programa Segundo curso Diplomatura en Cinematografía 2016/2017
 
Sookman lsuc copyright_year_in_review_2013_final
Sookman lsuc copyright_year_in_review_2013_finalSookman lsuc copyright_year_in_review_2013_final
Sookman lsuc copyright_year_in_review_2013_final
 
Mobile learning for gender equality
Mobile learning for gender equalityMobile learning for gender equality
Mobile learning for gender equality
 
Historia del calor
Historia del calorHistoria del calor
Historia del calor
 
El talento, los trastornos emocionales y otros
El talento, los trastornos emocionales y otrosEl talento, los trastornos emocionales y otros
El talento, los trastornos emocionales y otros
 
Bethabara . il battesimo di Gesù.
Bethabara . il battesimo di Gesù.Bethabara . il battesimo di Gesù.
Bethabara . il battesimo di Gesù.
 
Firebird 1.5-quick start-spanish
Firebird 1.5-quick start-spanishFirebird 1.5-quick start-spanish
Firebird 1.5-quick start-spanish
 
Sådan laver du vellykket web-tv
Sådan laver du vellykket web-tvSådan laver du vellykket web-tv
Sådan laver du vellykket web-tv
 

Semelhante a Unit4 C

Semelhante a Unit4 C (20)

Unit4
Unit4Unit4
Unit4
 
C Language Unit-4
C Language Unit-4C Language Unit-4
C Language Unit-4
 
Intoduction to structure
Intoduction to structureIntoduction to structure
Intoduction to structure
 
Structures
StructuresStructures
Structures
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
 
CA2_CYS101_31184422012_Arvind-Shukla.pptx
CA2_CYS101_31184422012_Arvind-Shukla.pptxCA2_CYS101_31184422012_Arvind-Shukla.pptx
CA2_CYS101_31184422012_Arvind-Shukla.pptx
 
U5 SPC.pptx
U5 SPC.pptxU5 SPC.pptx
U5 SPC.pptx
 
U5 SPC.pptx
U5 SPC.pptxU5 SPC.pptx
U5 SPC.pptx
 
structures.ppt
structures.pptstructures.ppt
structures.ppt
 
Introduction to structures in c lang.ppt
Introduction to structures in c lang.pptIntroduction to structures in c lang.ppt
Introduction to structures in c lang.ppt
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdfEasy Understanding of Structure Union Typedef Enum in C Language.pdf
Easy Understanding of Structure Union Typedef Enum in C Language.pdf
 
Presentation on structure,functions and classes
Presentation on structure,functions and classesPresentation on structure,functions and classes
Presentation on structure,functions and classes
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
 
structure,pointerandstring
structure,pointerandstringstructure,pointerandstring
structure,pointerandstring
 
structure.ppt
structure.pptstructure.ppt
structure.ppt
 
Unit4 (2)
Unit4 (2)Unit4 (2)
Unit4 (2)
 
STRUCTURES IN C PROGRAMMING
STRUCTURES IN C PROGRAMMING STRUCTURES IN C PROGRAMMING
STRUCTURES IN C PROGRAMMING
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7
 

Mais de arnold 7490 (20)

Les14
Les14Les14
Les14
 
Les13
Les13Les13
Les13
 
Les11
Les11Les11
Les11
 
Les10
Les10Les10
Les10
 
Les09
Les09Les09
Les09
 
Les07
Les07Les07
Les07
 
Les06
Les06Les06
Les06
 
Les05
Les05Les05
Les05
 
Les04
Les04Les04
Les04
 
Les03
Les03Les03
Les03
 
Les02
Les02Les02
Les02
 
Les01
Les01Les01
Les01
 
Les12
Les12Les12
Les12
 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
 
Unit 5 Java
Unit 5 JavaUnit 5 Java
Unit 5 Java
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 

Último

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 

Unit4 C

  • 1.
  • 2. book bookid title author pages price STRUCTURE- BOOK struct book { int book_id ; char title[50] ; char author[40] ; int pages ; float price ; }; Book-1 BookID: 1211 Title : C Primer Plus Author : Stephen Prata Pages : 984 Price : Rs. 585.00 Book-2 BookID: 1212 Title : The ANSI C Programming Author : Dennis Ritchie Pages : 214 Price : Rs. 125.00 Book-3 BookID: 1213 Title : C By Example Author : Greg Perry Pages : 498 Price : Rs. 305.00 Structure tag integer book_id Array of 50 characters title Array of 40 characters author integer pages float price 2 bytes 50 bytes 40 bytes 2 bytes 4 bytes struct < structure_tag_name > { data type < member 1 > data type < member 2 > … . …. …. …. data type < member N > } ; Memory occupied by a Structure variable
  • 3. Initialization of structure Initialization of structure variable while declaration : struct student s2 = { 1001, “ K.Avinash ”, 87.25 } ; Initialization of structure members individually : s1. roll_no = 1111; strcpy ( s1. name , “ B. Kishore “ ) ; s1.percentage = 78.5 ; Declaring a Structure Type struct student { int roll_no; char name[30]; float percentage; }; Declaring a Structure Variable struct student s1,s2,s3; (or) struct student { int roll_no; char name[30]; float percentage; }s1,s2,s3; Reading values to members at runtime: struct student s3; printf(“Enter the roll no”); scanf(“%d”,&s3.roll_no); printf(“Enter the name”); scanf(“%s”,s3.name); printf(“Enter the percentage”); scanf(“%f”,&s3.percentage); membership operator
  • 4. struct employee { int empid; char name[35]; int age; float salary; }; int main() { struct employee emp1,emp2 ; struct employee emp3 = { 1213 , ” S.Murali ” , 31 , 32000.00 } ; emp1.empid=1211; strcpy(emp1.name, “K.Ravi”); emp1.age = 27; emp1.salary=30000.00; printf(“Enter the details of employee 2”); scanf(“%d %s %d %f “ , &emp2.empid, emp2.name, &emp2.age, &emp2.salary); if(emp1.age > emp2.age) printf( “ Employee1 is senior than Employee2” ); else printf(“Employee1 is junior than Employee2”); printf(“Emp ID:%d Name:%s Age:%d Salary:%f”, emp1.empid,emp1.name,emp1.age,emp1.salary); } Implementing a Structure Declaration of Structure Type Declaration of Structure variables Declaration and initialization of Structure variable Initialization of Structure members individually Reading values to members of Structure Accessing members of Structure
  • 5. Nesting of structures struct date { int day ; int month ; int year ; } ; struct person { char name[40]; int age ; struct date b_day ; }; int main( ) { struct person p1; strcpy ( p1.name , “S. Ramesh “ ) ; p1. age = 32 ; p1.b_day.day = 25 ; p1.b_day. month = 8 ; p1.b_day. year = 1978 ; } Arrays And structures struct student { int sub[3] ; int total ; } ; int main( ) { struct student s[3]; int i,j; for(i=0;i<3;i++) { printf(“Enter student %d marks:”,i+1); for(j=0;j<3;j++) { scanf(“%d”,&s[i].sub[j]); } } for(i=0;i<3;i++) { s[i].total =0; for(j=0;j<3;j++) { s[i].total +=s[i].sub[j]; } printf(“Total marks of student %d is: %d”, i+1,s[i].total ); } } OUTPUT: Enter student 1 marks: 60 60 60 Enter student 2 marks: 70 70 70 Enter student 3 marks: 90 90 90 Total marks of student 1 is: 180 Total marks of student 2 is: 240 Total marks of student 3 is: 270 Outer Structure Inner Structure Accessing Inner Structure members
  • 6. struct fraction { int numerator ; int denominator ; }; void show ( struct fraction f ) { printf ( “ %d / %d “, f.numerator, f.denominator ) ; } int main ( ) { struct fraction f1 = { 7, 12 } ; show ( f1 ) ; } OUTPUT: 7 / 12 structures and functions Self referential structures struct student_node { int roll_no ; char name [25] ; struct student_node *next ; } ; int main( ) { struct student_node s1 ; struct student_node s2 = { 1111, “B.Mahesh”, NULL } ; s1. roll_no = 1234 ; strcpy ( s1.name , “P.Kiran “ ) ; s1. next = & s2 ; printf ( “ %s “, s1. name ) ; printf ( “ %s “ , s1.next - > name ) ; } A self referential structure is one that includes at least one member which is a pointer to the same structure type. With self referential structures, we can create very useful data structures such as linked -lists, trees and graphs . s2 node is linked to s1 node Prints P.Kiran Prints B.Mahesh
  • 7. Pointer to a structure Accessing structure members through pointer : i) Using . ( dot ) operator : ( *ptr ) . prodid = 111 ; strcpy ( ( *ptr ) . Name, “Pen”) ; ii) Using - > ( arrow ) operator : ptr - > prodid = 111 ; strcpy( ptr - > name , “Pencil”) ; struct product { int prodid; char name[20]; }; int main() { struct product inventory[3]; struct product *ptr; printf(“Read Product Details : &quot;); for(ptr = inventory;ptr<inventory +3;ptr++) { scanf(&quot;%d %s&quot;, &ptr->prodid, ptr->name); } printf(&quot;output&quot;); for(ptr=inventory;ptr<inventory+3;ptr++) { printf(&quot;Product ID :%5d&quot;,ptr->prodid); printf(&quot;Name : %s&quot;,ptr->name); } } Read Product Details : 111 Pen 112 Pencil 113 Book Print Product Details : Product ID : 111 Name : Pen Product ID : 112 Name : Pencil Product ID : 113 Name : Book
  • 8. A union is a structure all of whose members share the same memory Union is a variable, which is similar to the structure and contains number of members like structure. In the structure each member has its own memory location whereas, members of union share the same memory. The amount of storage allocated to a union is sufficient to hold its largest member. struct student { int rollno; float avg ; char grade ; }; union pupil { int rollno; float avg ; char grade; } ; int main() { struct student s1 ; union pupil p1; printf ( “ %d bytes “, sizeof ( struct student ) ) ; printf ( “ %d bytes “, sizeof ( union pupil ) ) ; } Output : 7 bytes 4 bytes Memory allotted to structure student Address 5000 5001 5002 5003 5004 5005 5006 rollno avg grade Total memory occupied : 7 bytes Memory allotted to union pupil rollno avg grade Total memory occupied : 4 bytes Address 5000 5001 5002 5003