SlideShare una empresa de 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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
 
Pointers
PointersPointers
Pointers
 
detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
C Programming
C ProgrammingC Programming
C Programming
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Storage classes in c++
Storage classes in c++Storage classes in c++
Storage classes in c++
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Constructor and Destructor in c++
Constructor  and Destructor in c++Constructor  and Destructor in c++
Constructor and Destructor in c++
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Array in c++
Array in c++Array in c++
Array in c++
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
File in C language
File in C languageFile in C language
File in C language
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 

Destacado

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
 

Destacado (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
 

Similar a Unit4 C

Similar 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
 

Más 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

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Último (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

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