SlideShare uma empresa Scribd logo
1 de 10
C Data Types:
Primary data types                       Derived
Derived data types                        Types
User-defined data types



    Function                                Pointer            Structure
                     Array Type                                                  Union Type
      Type                                   Type                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-1                      Book-2                               Book-3
BookID: 1211                BookID: 1212                         BookID: 1213
Title : C Primer Plus       Title : The ANSI C Programming       Title : C By Example
Author : Stephen Prata      Author : Dennis Ritchie              Author : Greg Perry
Pages : 984                 Pages : 214                          Pages : 498
Price : Rs. 585.00          Price : Rs. 125.00                   Price : Rs. 305.00

   book                        book_id        integer        2 bytes
                  bookid
                                 title        Array of 50 characters                    50 bytes
                    title
                                 author       Array of 40 characters            40 bytes
                  author
                                 pages        integer         2 bytes
                  pages
                   price         price        float                      4 bytes

                                         Memory occupied by a Structure variable

               STRUCTURE- BOOK                        struct < structure_tag_name >
struct book {                                         {
                            Structure tag                   data type < member 1 >
      int book_id ;
      char title[50] ;                                      data type < member 2 >
                                                               …. …. …. ….
      char author[40] ;
                                                            data type < member N >
      int pages ;                                     };
      float price ;
};
Declaring a Structure Type                   Declaring a Structure Variable

 struct student                               struct student s1,s2,s3;
 {                                                      (or)
           int roll_no;                       struct student
           char name[30];                     {
           float percentage;                            int roll_no;
 };                                                     char name[30];
                                                        float percentage;
                                              }s1,s2,s3;

      Initialization of structure                       Reading values to members at
                                                        runtime:
Initialization of structure variable while
declaration :                                           struct student s3;
   struct student s2 = { 1001, “ K.Avinash ”,           printf(“nEnter the roll no”);
                  87.25 } ;                             scanf(“%d”,&s3.roll_no);
Initialization of structure members individually :      printf(“nEnter the name”);
   s1. roll_no = 1111;                                  scanf(“%s”,s3.name);
   strcpy ( s1. name , “ B. Kishore “ ) ;               printf(“nEnter the percentage”);
   s1.percentage = 78.5 ;                               scanf(“%f”,&s3.percentage);

                      membership operator
Implementing a Structure
struct employee {
     int empid;
     char name[35];
     int age;                   Declaration of Structure Type
     float salary;
};
                                          Declaration of Structure variables
int main() {
    struct employee emp1,emp2 ;      Declaration and initialization of Structure variable

   struct employee emp3 = { 1213 , ” S.Murali ” , 31 , 32000.00 } ;
   emp1.empid=1211;
   strcpy(emp1.name, “K.Ravi”);
   emp1.age = 27;                         Initialization of Structure members individually
   emp1.salary=30000.00;
   printf(“Enter the details of employee 2”);      Reading values to members of Structure
   scanf(“%d %s %d %f “ , &emp2.empid, emp2.name, &emp2.age, &emp2.salary);
   if(emp1.age > emp2.age)
        printf( “ Employee1 is senior than Employee2n” );
   else
        printf(“Employee1 is junior than Employee2n”);
                                                             Accessing members of Structure
  printf(“Emp ID:%dn Name:%sn Age:%dn Salary:%f”,
emp1.empid,emp1.name,emp1.age,emp1.salary);
}
Arrays And structures                               Nesting of structures
struct student                                        struct date {
{                                                         int day ;
   int sub[3] ;                                           int month ;
                                                                             Outer Structure
   int total ;                                            int year ;
};                                                    };
                                                      struct person {
                                                          char name[40];
int main( ) {                                             int age ;
  struct student s[3];                                    struct date b_day ;
  int i,j;                                            };
   for(i=0;i<3;i++) {                                 int main( ) {             Inner Structure
      printf(“nnEnter student %d marks:”,i+1);         struct person p1;
      for(j=0;j<3;j++) {                                 strcpy ( p1.name , “S. Ramesh “ ) ;
           scanf(“%d”,&s[i].sub[j]);                     p1. age = 32 ;
       }                                                 p1.b_day.day = 25 ;       Accessing Inner
    }                                                    p1.b_day. month = 8 ; Structure members
    for(i=0;i<3;i++) {                                   p1.b_day. year = 1978 ;
         s[i].total =0;                               }
         for(j=0;j<3;j++) {
               s[i].total +=s[i].sub[j];              OUTPUT:
       }                                              Enter student 1 marks: 60 60 60
       printf(“nTotal marks of student %d is: %d”,   Enter student 2 marks: 70 70 70
                          i+1,s[i].total );           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
structures and functions                           Self referential structures
struct fraction {                      struct student_node {
    int numerator ;                        int roll_no ;
    int denominator ;                      char name [25] ;
};                                         struct student_node *next ;
                                       };
void show ( struct fraction f )        int main( )
{                                       {
  printf ( “ %d / %d “, f.numerator,      struct student_node s1 ;
                                          struct student_node s2 = { 1111, “B.Mahesh”, NULL } ;
                f.denominator ) ;         s1. roll_no = 1234 ;
}                                         strcpy ( s1.name , “P.Kiran “ ) ;
int main ( ) {                             s1. next = & s2 ;       s2 node is linked to s1 node
    struct fraction f1 = { 7, 12 } ;
    show ( f1 ) ;                          printf ( “ %s “, s1. name ) ;
}                                                                            Prints P.Kiran
                                           printf ( “ %s “ , s1.next - > name ) ;   Prints B.Mahesh
OUTPUT:                                }
           7 / 12



         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.
Pointer to a structure

struct product                                     Accessing structure members through
{                                                  pointer :
   int prodid;
   char name[20];                                  i) Using . ( dot ) operator :
};                                                      ( *ptr ) . prodid = 111 ;
                                                        strcpy ( ( *ptr ) . Name, “Pen”) ;
int main()
{                                                  ii) Using - > ( arrow ) operator :
   struct product inventory[3];                          ptr - > prodid = 111 ;
   struct product *ptr;                                  strcpy( ptr - > name , “Pencil”) ;
   printf(“Read Product Details : n");
   for(ptr = inventory;ptr<inventory +3;ptr++) {
     scanf("%d %s", &ptr->prodid, ptr->name);      Read Product Details :
   }
                                                   111 Pen
   printf("noutputn");
                                                   112 Pencil
   for(ptr=inventory;ptr<inventory+3;ptr++)        113 Book
   {
     printf("nnProduct ID :%5d",ptr->prodid);    Print Product Details :
     printf("nName : %s",ptr->name);
   }                                               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;                              Memory allotted to structure student
    float avg ;
    char grade ;                     Address 5000     5001     5002    5003    5004 5005  5006
};
union pupil {
    int rollno;
    float avg ;                                  rollno                    avg           grade
    char grade;                                     Total memory occupied : 7 bytes
};
int main() {
    struct student s1 ;                           Memory allotted to union pupil
    union pupil p1;
    printf ( “ %d bytes “,            Address 5000        5001    5002    5003
       sizeof ( struct student ) ) ;
     printf ( “ %d bytes “,
        sizeof ( union pupil ) ) ;
}                                                  rollno
Output :                                                     avg
   7 bytes 4 bytes                             grade
                                              Total memory occupied : 4 bytes
www.jntuworld.com
• For More Materials, Text Books, Previous
  Papers & Mobile updates of B.TECH,
  B.PHARMACY, MBA, MCA of JNTU-HYD,JNTU-
  KAKINADA & JNTU-ANANTAPUR visit
  www.jntuworld.com
www.jntuworld.com
• For More Materials, Text Books, Previous
  Papers & Mobile updates of B.TECH,
  B.PHARMACY, MBA, MCA of JNTU-HYD,JNTU-
  KAKINADA & JNTU-ANANTAPUR visit
  www.jntuworld.com

Mais conteúdo relacionado

Mais procurados

PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDBFitz Agard
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)MongoSF
 
Jazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipseJazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipsePeter Friese
 
Intoduction to structure
Intoduction to structureIntoduction to structure
Intoduction to structureUtsav276
 
C# Summer course - Lecture 3
C# Summer course - Lecture 3C# Summer course - Lecture 3
C# Summer course - Lecture 3mohamedsamyali
 
4-Code-Jugalbandi-destructuring-patternmatching-healthycode#apr2015
4-Code-Jugalbandi-destructuring-patternmatching-healthycode#apr20154-Code-Jugalbandi-destructuring-patternmatching-healthycode#apr2015
4-Code-Jugalbandi-destructuring-patternmatching-healthycode#apr2015Dhaval Dalal
 
C# Summer course - Lecture 4
C# Summer course - Lecture 4C# Summer course - Lecture 4
C# Summer course - Lecture 4mohamedsamyali
 
Linear algebra review
Linear algebra reviewLinear algebra review
Linear algebra reviewvevin1986
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc csKALAISELVI P
 
Php Map Script Class Reference
Php Map Script Class ReferencePhp Map Script Class Reference
Php Map Script Class ReferenceJoel Mamani Lopez
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptJulie Iskander
 

Mais procurados (12)

PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDB
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)
 
Jazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipseJazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with Eclipse
 
Structures and Unions
Structures and UnionsStructures and Unions
Structures and Unions
 
Intoduction to structure
Intoduction to structureIntoduction to structure
Intoduction to structure
 
C# Summer course - Lecture 3
C# Summer course - Lecture 3C# Summer course - Lecture 3
C# Summer course - Lecture 3
 
4-Code-Jugalbandi-destructuring-patternmatching-healthycode#apr2015
4-Code-Jugalbandi-destructuring-patternmatching-healthycode#apr20154-Code-Jugalbandi-destructuring-patternmatching-healthycode#apr2015
4-Code-Jugalbandi-destructuring-patternmatching-healthycode#apr2015
 
C# Summer course - Lecture 4
C# Summer course - Lecture 4C# Summer course - Lecture 4
C# Summer course - Lecture 4
 
Linear algebra review
Linear algebra reviewLinear algebra review
Linear algebra review
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
 
Php Map Script Class Reference
Php Map Script Class ReferencePhp Map Script Class Reference
Php Map Script Class Reference
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 

Destaque

Presentation Influencing Factors
Presentation Influencing FactorsPresentation Influencing Factors
Presentation Influencing Factorstaco_dols
 
เมทริกซ์ระดับชั้นมัธยมปลาย(Matrix)
เมทริกซ์ระดับชั้นมัธยมปลาย(Matrix)เมทริกซ์ระดับชั้นมัธยมปลาย(Matrix)
เมทริกซ์ระดับชั้นมัธยมปลาย(Matrix)Thanuphong Ngoapm
 
Solving 2x2 systems using inverse matrix (December 12, 2013)
Solving 2x2 systems using inverse matrix (December 12, 2013)Solving 2x2 systems using inverse matrix (December 12, 2013)
Solving 2x2 systems using inverse matrix (December 12, 2013)Fei Ye YEW
 
Effective communication skills
Effective communication skillsEffective communication skills
Effective communication skillsSeyid Kadher
 
Application of derivatives
Application of derivatives Application of derivatives
Application of derivatives Seyid Kadher
 
Lecture 5 inverse of matrices - section 2-2 and 2-3
Lecture 5   inverse of matrices - section 2-2 and 2-3Lecture 5   inverse of matrices - section 2-2 and 2-3
Lecture 5 inverse of matrices - section 2-2 and 2-3njit-ronbrown
 
Communication system
Communication systemCommunication system
Communication systemSeyid Kadher
 
Presentation on inverse matrix
Presentation on inverse matrixPresentation on inverse matrix
Presentation on inverse matrixSyed Ahmed Zaki
 
Inverse Matrix & Determinants
Inverse Matrix & DeterminantsInverse Matrix & Determinants
Inverse Matrix & Determinantsitutor
 
Matrices And Application Of Matrices
Matrices And Application Of MatricesMatrices And Application Of Matrices
Matrices And Application Of Matricesmailrenuka
 
Various approaches to management
Various approaches to managementVarious approaches to management
Various approaches to managementGeorge Cherian
 
EXPORT PROCEDURE & DOCUMENTATION
EXPORT PROCEDURE & DOCUMENTATIONEXPORT PROCEDURE & DOCUMENTATION
EXPORT PROCEDURE & DOCUMENTATIONvikas chauhan
 
EXPORT IMPORT
EXPORT IMPORTEXPORT IMPORT
EXPORT IMPORTRati Kaul
 

Destaque (20)

Unit i
Unit iUnit i
Unit i
 
Ses 2 matrix opt
Ses 2 matrix optSes 2 matrix opt
Ses 2 matrix opt
 
Pc 8.4 notes
Pc 8.4 notesPc 8.4 notes
Pc 8.4 notes
 
Presentation Influencing Factors
Presentation Influencing FactorsPresentation Influencing Factors
Presentation Influencing Factors
 
เมทริกซ์ระดับชั้นมัธยมปลาย(Matrix)
เมทริกซ์ระดับชั้นมัธยมปลาย(Matrix)เมทริกซ์ระดับชั้นมัธยมปลาย(Matrix)
เมทริกซ์ระดับชั้นมัธยมปลาย(Matrix)
 
Solving 2x2 systems using inverse matrix (December 12, 2013)
Solving 2x2 systems using inverse matrix (December 12, 2013)Solving 2x2 systems using inverse matrix (December 12, 2013)
Solving 2x2 systems using inverse matrix (December 12, 2013)
 
Attitude
AttitudeAttitude
Attitude
 
Effective communication skills
Effective communication skillsEffective communication skills
Effective communication skills
 
Determinants
DeterminantsDeterminants
Determinants
 
Application of derivatives
Application of derivatives Application of derivatives
Application of derivatives
 
Lecture 5 inverse of matrices - section 2-2 and 2-3
Lecture 5   inverse of matrices - section 2-2 and 2-3Lecture 5   inverse of matrices - section 2-2 and 2-3
Lecture 5 inverse of matrices - section 2-2 and 2-3
 
Determinants
DeterminantsDeterminants
Determinants
 
MATRICES
MATRICESMATRICES
MATRICES
 
Communication system
Communication systemCommunication system
Communication system
 
Presentation on inverse matrix
Presentation on inverse matrixPresentation on inverse matrix
Presentation on inverse matrix
 
Inverse Matrix & Determinants
Inverse Matrix & DeterminantsInverse Matrix & Determinants
Inverse Matrix & Determinants
 
Matrices And Application Of Matrices
Matrices And Application Of MatricesMatrices And Application Of Matrices
Matrices And Application Of Matrices
 
Various approaches to management
Various approaches to managementVarious approaches to management
Various approaches to management
 
EXPORT PROCEDURE & DOCUMENTATION
EXPORT PROCEDURE & DOCUMENTATIONEXPORT PROCEDURE & DOCUMENTATION
EXPORT PROCEDURE & DOCUMENTATION
 
EXPORT IMPORT
EXPORT IMPORTEXPORT IMPORT
EXPORT IMPORT
 

Semelhante a Unit4

CA2_CYS101_31184422012_Arvind-Shukla.pptx
CA2_CYS101_31184422012_Arvind-Shukla.pptxCA2_CYS101_31184422012_Arvind-Shukla.pptx
CA2_CYS101_31184422012_Arvind-Shukla.pptxArvindShukla81
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Smit Shah
 
Unit4 (2)
Unit4 (2)Unit4 (2)
Unit4 (2)mrecedu
 
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.pptshivani366010
 
STRUCTURES IN C PROGRAMMING
STRUCTURES IN C PROGRAMMING STRUCTURES IN C PROGRAMMING
STRUCTURES IN C PROGRAMMING Gurwinderkaur45
 
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.pdfsudhakargeruganti
 
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-7sumitbardhan
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing conceptskavitham66441
 
Presentation on structure,functions and classes
Presentation on structure,functions and classesPresentation on structure,functions and classes
Presentation on structure,functions and classesAlisha Korpal
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referentialbabuk110
 

Semelhante a Unit4 (20)

Unit4 C
Unit4 C Unit4 C
Unit4 C
 
CA2_CYS101_31184422012_Arvind-Shukla.pptx
CA2_CYS101_31184422012_Arvind-Shukla.pptxCA2_CYS101_31184422012_Arvind-Shukla.pptx
CA2_CYS101_31184422012_Arvind-Shukla.pptx
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
 
Unit4 (2)
Unit4 (2)Unit4 (2)
Unit4 (2)
 
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.ppt
structure.pptstructure.ppt
structure.ppt
 
1. structure
1. structure1. structure
1. structure
 
Structure in C
Structure in CStructure in C
Structure in C
 
Structures
StructuresStructures
Structures
 
637225564198396290.pdf
637225564198396290.pdf637225564198396290.pdf
637225564198396290.pdf
 
STRUCTURES IN C PROGRAMMING
STRUCTURES IN C PROGRAMMING STRUCTURES IN C PROGRAMMING
STRUCTURES IN C PROGRAMMING
 
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
 
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
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
 
Presentation on structure,functions and classes
Presentation on structure,functions and classesPresentation on structure,functions and classes
Presentation on structure,functions and classes
 
structure
structurestructure
structure
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
 

Mais de mrecedu

Brochure final
Brochure finalBrochure final
Brochure finalmrecedu
 
Filters unit iii
Filters unit iiiFilters unit iii
Filters unit iiimrecedu
 
Attenuator unit iv
Attenuator unit ivAttenuator unit iv
Attenuator unit ivmrecedu
 
Two port networks unit ii
Two port networks unit iiTwo port networks unit ii
Two port networks unit iimrecedu
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)mrecedu
 
Unit6 jwfiles
Unit6 jwfilesUnit6 jwfiles
Unit6 jwfilesmrecedu
 
Unit2 jwfiles
Unit2 jwfilesUnit2 jwfiles
Unit2 jwfilesmrecedu
 
Unit1 jwfiles
Unit1 jwfilesUnit1 jwfiles
Unit1 jwfilesmrecedu
 
Unit7 jwfiles
Unit7 jwfilesUnit7 jwfiles
Unit7 jwfilesmrecedu
 
M1 unit vi-jntuworld
M1 unit vi-jntuworldM1 unit vi-jntuworld
M1 unit vi-jntuworldmrecedu
 
M1 unit v-jntuworld
M1 unit v-jntuworldM1 unit v-jntuworld
M1 unit v-jntuworldmrecedu
 
M1 unit iv-jntuworld
M1 unit iv-jntuworldM1 unit iv-jntuworld
M1 unit iv-jntuworldmrecedu
 
M1 unit iii-jntuworld
M1 unit iii-jntuworldM1 unit iii-jntuworld
M1 unit iii-jntuworldmrecedu
 
M1 unit ii-jntuworld
M1 unit ii-jntuworldM1 unit ii-jntuworld
M1 unit ii-jntuworldmrecedu
 
M1 unit i-jntuworld
M1 unit i-jntuworldM1 unit i-jntuworld
M1 unit i-jntuworldmrecedu
 
M1 unit viii-jntuworld
M1 unit viii-jntuworldM1 unit viii-jntuworld
M1 unit viii-jntuworldmrecedu
 
M1 unit vii-jntuworld
M1 unit vii-jntuworldM1 unit vii-jntuworld
M1 unit vii-jntuworldmrecedu
 

Mais de mrecedu (20)

Brochure final
Brochure finalBrochure final
Brochure final
 
Unit i
Unit iUnit i
Unit i
 
Filters unit iii
Filters unit iiiFilters unit iii
Filters unit iii
 
Attenuator unit iv
Attenuator unit ivAttenuator unit iv
Attenuator unit iv
 
Two port networks unit ii
Two port networks unit iiTwo port networks unit ii
Two port networks unit ii
 
Unit 8
Unit 8Unit 8
Unit 8
 
Unit5
Unit5Unit5
Unit5
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)
 
Unit6 jwfiles
Unit6 jwfilesUnit6 jwfiles
Unit6 jwfiles
 
Unit2 jwfiles
Unit2 jwfilesUnit2 jwfiles
Unit2 jwfiles
 
Unit1 jwfiles
Unit1 jwfilesUnit1 jwfiles
Unit1 jwfiles
 
Unit7 jwfiles
Unit7 jwfilesUnit7 jwfiles
Unit7 jwfiles
 
M1 unit vi-jntuworld
M1 unit vi-jntuworldM1 unit vi-jntuworld
M1 unit vi-jntuworld
 
M1 unit v-jntuworld
M1 unit v-jntuworldM1 unit v-jntuworld
M1 unit v-jntuworld
 
M1 unit iv-jntuworld
M1 unit iv-jntuworldM1 unit iv-jntuworld
M1 unit iv-jntuworld
 
M1 unit iii-jntuworld
M1 unit iii-jntuworldM1 unit iii-jntuworld
M1 unit iii-jntuworld
 
M1 unit ii-jntuworld
M1 unit ii-jntuworldM1 unit ii-jntuworld
M1 unit ii-jntuworld
 
M1 unit i-jntuworld
M1 unit i-jntuworldM1 unit i-jntuworld
M1 unit i-jntuworld
 
M1 unit viii-jntuworld
M1 unit viii-jntuworldM1 unit viii-jntuworld
M1 unit viii-jntuworld
 
M1 unit vii-jntuworld
M1 unit vii-jntuworldM1 unit vii-jntuworld
M1 unit vii-jntuworld
 

Último

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
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
 
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
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
[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
 
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
 

Último (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
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
 
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
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
[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
 
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
 

Unit4

  • 1. C Data Types: Primary data types Derived Derived data types Types User-defined data types Function Pointer Structure Array Type Union Type Type Type 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.
  • 2. Book-1 Book-2 Book-3 BookID: 1211 BookID: 1212 BookID: 1213 Title : C Primer Plus Title : The ANSI C Programming Title : C By Example Author : Stephen Prata Author : Dennis Ritchie Author : Greg Perry Pages : 984 Pages : 214 Pages : 498 Price : Rs. 585.00 Price : Rs. 125.00 Price : Rs. 305.00 book book_id integer 2 bytes bookid title Array of 50 characters 50 bytes title author Array of 40 characters 40 bytes author pages integer 2 bytes pages price price float 4 bytes Memory occupied by a Structure variable STRUCTURE- BOOK struct < structure_tag_name > struct book { { Structure tag data type < member 1 > int book_id ; char title[50] ; data type < member 2 > …. …. …. …. char author[40] ; data type < member N > int pages ; }; float price ; };
  • 3. Declaring a Structure Type Declaring a Structure Variable struct student struct student s1,s2,s3; { (or) int roll_no; struct student char name[30]; { float percentage; int roll_no; }; char name[30]; float percentage; }s1,s2,s3; Initialization of structure Reading values to members at runtime: Initialization of structure variable while declaration : struct student s3; struct student s2 = { 1001, “ K.Avinash ”, printf(“nEnter the roll no”); 87.25 } ; scanf(“%d”,&s3.roll_no); Initialization of structure members individually : printf(“nEnter the name”); s1. roll_no = 1111; scanf(“%s”,s3.name); strcpy ( s1. name , “ B. Kishore “ ) ; printf(“nEnter the percentage”); s1.percentage = 78.5 ; scanf(“%f”,&s3.percentage); membership operator
  • 4. Implementing a Structure struct employee { int empid; char name[35]; int age; Declaration of Structure Type float salary; }; Declaration of Structure variables int main() { struct employee emp1,emp2 ; Declaration and initialization of Structure variable struct employee emp3 = { 1213 , ” S.Murali ” , 31 , 32000.00 } ; emp1.empid=1211; strcpy(emp1.name, “K.Ravi”); emp1.age = 27; Initialization of Structure members individually emp1.salary=30000.00; printf(“Enter the details of employee 2”); Reading values to members of Structure scanf(“%d %s %d %f “ , &emp2.empid, emp2.name, &emp2.age, &emp2.salary); if(emp1.age > emp2.age) printf( “ Employee1 is senior than Employee2n” ); else printf(“Employee1 is junior than Employee2n”); Accessing members of Structure printf(“Emp ID:%dn Name:%sn Age:%dn Salary:%f”, emp1.empid,emp1.name,emp1.age,emp1.salary); }
  • 5. Arrays And structures Nesting of structures struct student struct date { { int day ; int sub[3] ; int month ; Outer Structure int total ; int year ; }; }; struct person { char name[40]; int main( ) { int age ; struct student s[3]; struct date b_day ; int i,j; }; for(i=0;i<3;i++) { int main( ) { Inner Structure printf(“nnEnter student %d marks:”,i+1); struct person p1; for(j=0;j<3;j++) { strcpy ( p1.name , “S. Ramesh “ ) ; scanf(“%d”,&s[i].sub[j]); p1. age = 32 ; } p1.b_day.day = 25 ; Accessing Inner } p1.b_day. month = 8 ; Structure members for(i=0;i<3;i++) { p1.b_day. year = 1978 ; s[i].total =0; } for(j=0;j<3;j++) { s[i].total +=s[i].sub[j]; OUTPUT: } Enter student 1 marks: 60 60 60 printf(“nTotal marks of student %d is: %d”, Enter student 2 marks: 70 70 70 i+1,s[i].total ); 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
  • 6. structures and functions Self referential structures struct fraction { struct student_node { int numerator ; int roll_no ; int denominator ; char name [25] ; }; struct student_node *next ; }; void show ( struct fraction f ) int main( ) { { printf ( “ %d / %d “, f.numerator, struct student_node s1 ; struct student_node s2 = { 1111, “B.Mahesh”, NULL } ; f.denominator ) ; s1. roll_no = 1234 ; } strcpy ( s1.name , “P.Kiran “ ) ; int main ( ) { s1. next = & s2 ; s2 node is linked to s1 node struct fraction f1 = { 7, 12 } ; show ( f1 ) ; printf ( “ %s “, s1. name ) ; } Prints P.Kiran printf ( “ %s “ , s1.next - > name ) ; Prints B.Mahesh OUTPUT: } 7 / 12 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.
  • 7. Pointer to a structure struct product Accessing structure members through { pointer : int prodid; char name[20]; i) Using . ( dot ) operator : }; ( *ptr ) . prodid = 111 ; strcpy ( ( *ptr ) . Name, “Pen”) ; int main() { ii) Using - > ( arrow ) operator : struct product inventory[3]; ptr - > prodid = 111 ; struct product *ptr; strcpy( ptr - > name , “Pencil”) ; printf(“Read Product Details : n"); for(ptr = inventory;ptr<inventory +3;ptr++) { scanf("%d %s", &ptr->prodid, ptr->name); Read Product Details : } 111 Pen printf("noutputn"); 112 Pencil for(ptr=inventory;ptr<inventory+3;ptr++) 113 Book { printf("nnProduct ID :%5d",ptr->prodid); Print Product Details : printf("nName : %s",ptr->name); } 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; Memory allotted to structure student float avg ; char grade ; Address 5000 5001 5002 5003 5004 5005 5006 }; union pupil { int rollno; float avg ; rollno avg grade char grade; Total memory occupied : 7 bytes }; int main() { struct student s1 ; Memory allotted to union pupil union pupil p1; printf ( “ %d bytes “, Address 5000 5001 5002 5003 sizeof ( struct student ) ) ; printf ( “ %d bytes “, sizeof ( union pupil ) ) ; } rollno Output : avg 7 bytes 4 bytes grade Total memory occupied : 4 bytes
  • 9. www.jntuworld.com • For More Materials, Text Books, Previous Papers & Mobile updates of B.TECH, B.PHARMACY, MBA, MCA of JNTU-HYD,JNTU- KAKINADA & JNTU-ANANTAPUR visit www.jntuworld.com
  • 10. www.jntuworld.com • For More Materials, Text Books, Previous Papers & Mobile updates of B.TECH, B.PHARMACY, MBA, MCA of JNTU-HYD,JNTU- KAKINADA & JNTU-ANANTAPUR visit www.jntuworld.com