SlideShare a Scribd company logo
INTRODUCTION:
A structure is a collection of elements of different types of data.
Ex: consider the student information roll number, gender, age,
height and weight of different types.
main()
{ struct student                            rno                gender
                                        2                  1
   {
       int rno;                             age       ht            wt
                                    2             4             4
       char gender;
       int age;                 13 bytes of memory is allocated in s1
13 bytes of memory is allocated to s2

 float ht;                                   age
                                                            gender
 float wt;                               2              1
 };                                          age       ht        wt
                                         2         4         4
 struct student s1,s2;
 }

When all these data items are grouped under on single variable
name, we can get some meaningful information.
struct is a keyword used to create a new user defined data type.
In some other high level programming languages the structures
are named as records
DEFINING A STRUCTURE:
syntax:
                                         Example:
          struct user defined datatype    struct student
                                           {
          {                                  int rno;
               datatype member1;             int age;
                                             char gender;
               datatype member2;              float ht;
                  …………….                      float wt;
                                         };
                   …………
               datatype membern:
          };
In the given syntax struct is keyword used to create new user defined
data type.
An user defined data type name may be any valid ‘c’ identifier ( user
defined name).
The data type may be a valid simple data type or compound data type.
The member names may be any valid ‘C’ identifiers .in the given
example student is a new user defined data type name.
The variable rno, age, gender, ht, wt, are the structure members.
All these structure members must be enclosed within a pair of curly
braces.
The structure definition should be terminated with semicolon.
DECLARING STRUCTURE VARIABLE:
        Once a new user defined datatype is created by using the
keyboard struct then we can create any no. of structure variables of that
type.
syntax:
      struct user defined_data type name
          structure var1, structure var2,……….. Struct varn;
Above statement is called declarative statement of structure variables
and it allocates memory space to these variables.
We can also declare structure variables immediately after structure
definition.
ACCESSING STRUCTURE MEMBERS:

          .          Structure member accessing operator
          
                                    S1.gender=‘m’; s1.age=25;
Structure
          S1.rno=100                S1.ht=5.5;    s1.wt=60.2;
variable
           Structure member

 •Two operators are used to access member of structure. The structure
 member operator(.) also called dot operator and the structure pointer
 operator () also called the arrow operator.
 •The structure member operator accesses a structure member via structure
 variable name.
syntax:
 Ex: s1.rno, s1.age, s1.gender, s1.ht, s1.wt
 S1.rno=100; s1.gender=M; s1.age=25; s1.ht=5.5; s1.wt=60.2

            s1                                 s2
      rno         gender                     rno        gender
     100           M
   age      ht      wt                 age         ht      wt
   25       5.5     60.2

ASSIGNING VALUES TO STRUCTURE MEMBERS:
By using the assignment operator(=) we can assign values to all
structure members of a structure variable.
        Syntax: structure variable.member = value;
         Ex: s1.rno= 100; s1.age=25
INITIALIZING A STRUCTURE VARIABLE:
Structures can be initialized using initialize lists as with arrays. To
initialize a structure follow the variable name in the structure
declaration with an equal sign and brace enclosed comma separated
list of initializes.
Ex: struct student s1={100, 25,’M’, 5.5,65.2};
     int x = 10;
     int a[10]={ 10,20,30};
READING AND DISPLAYING THE STRUCTURE VARIABLES:
The ‘C’ will not read or write an entire structure as a single command. It
will read or write the members of a structure as follows:
 ex: scanf(“ %d, %d, %c, %f” ,&s1.rno,&s1.age,&s1.gender,&s1.ht);
     printf(“ %d %d %c %f”, s1.rno, s1.age, s1.gender, s1.ht);
PROGRAM USING STRUCTURES:
 Reads the details of 2 students and calculate total and average
marks of 2 students.
                  #include<stdio.h>
                  #include<conio.h>
                  void main()
                  { /* defining a structure */
                    struct student
                   { int rno;
                       char name[30];
                       float m1,m2,m3;
                       float tot, avg;
                  };
/* 2. declaration of structure var*/
struct student s1,s2; (1st executed)
/* 3.reading 1st student details*/
printf(“ enter rno,name,m1,m2,m3 of first student n”);
scanf(“ %d %s %f %f %f ”,
&s1.rno,&s1.name,&s1.m1,&s1.m2,&s1.m3);
/* 4. reading 2nd student details*/
printf(“ enter rno, name, m1, m2, m3,of second student n);
scanf(“ %d %s%f %f %f”, &s2.rno,
&s2.name,&s2.m1,&s2.m2,&s2.m3);
/* calculate total and avg of first student marks*/
   s1.tot= s1.m1+s1.m2+s1.m3;
    s1.avg = s1.tot/3;
/* 6.calculate total and avg of first student marks*/
   s2.tot= s2.m1+s2.m2+s2.m3;
    s2.avg = s2.tot/3;
/* displaying first student details*/
printf(“ first student details are n”);
printf( “roll no:%dn, name:%s n, m1: %f n. m2:%f, m3:%f n”, s1.rno,
s1.name, s1.m1, s1.m2, s1.m3);
printf(“ total :%f n , average: %f n”, s1.tot, s1.avg);
/* 8. displaying second student details*/
printf(“ second student details are:n);
printf( “roll no:%dn, name:%s n, m1: %f n. m2:%f, m3:%f n”,
s2.rno, s2.name, s2.m1, s2.m2, s2.m3);
printf(“ total :%f n , average: %f n”, s2.tot, s2.avg);
}
Array of Structures:
          Perhaps the most common usage of structures is an array of
structures.
->To declare an array of structures you must first define a structure
and then declare an array variable of that type.
For example to declare a 100 element array of structures of type
“student” write
struct student
{
       int rno;
       int m1,m2,m3;
       int tot,avg;
}
struct student s[100];-Structure Variable Declaration
DEMONSTRATING ARRAY OF STRUCTURES:
    #include<stdio.h>
    #include <conio.h>
void main()
{
      /*1.Defining an array of structures*/
      struct student
      {
           int rno;
           int m1,m2,m3;
           int tot,avg;
      };
/*2.Creating an array of Structures*/
struct student s[100];
int i,n;
clrscr();
printf(“Enter n valuen”);
/*3.Read total no.of students to n*/
scanf(“%d”,&n);
/*4.Reading student details*/
for(i=0;i<n;i++)
{
           printf(“Enter details of %d studentn”,i+1);
           scanf(“%d”,&s[i].rno);
scanf(“%d%d%d”,&s[i].m1,&s[i].m1,&s[i].m2,&s[i].m3);
/*5.Calculate tot,avg marks */
for(i=0;i<n;i++)
{
        s[i].tot=s[i].m1+s[i].m2+s[i].m3;
        s[i].avg=s[i].tot/3;
}
/*6.Display the student details*/
for(i=0;i<n;i++)
{
        printf(“The following are the %d student detailsn”,i+1);
        printf(“Rollno:%dn”,s[i].rno);
printf(“M1:%dn”,s[i].m1);
printf(“M2:%dn”,s[i].m2);
printf(“M3:%dn”,s[i].m3);
printf(“Total:%dn”,s[i].tot);
printf(“Average:%dn”,s[i].avg);
}
}
Arrays with in Structures:
           A member of a structure may be either a simple or compound type.
simple member is one that is of any of the built-in datatypes such as integer or
character.
->The compound datatypes include one dimensional and multidimensional
arrays of other datatypes and structures.
For example consider this Structure:
    struct x
    {
           int rno;
           int m[3];/* An Array is described as a structure member*/
           int tot,avg;
}
Nested Structures:
     when a structure variable is a member of another structure, it is
called a Nested structure.
->In the below example structure variable ‘z’ is declared as structure
Member to another structure.
EX:struct Test
 {
    int a;
    int b;
};
Struct Exam
{
     int x;
     int y;
     struct Test z;
};
Structures and Function:
        A Structure can be passed to a function as a one variable or
as an individual member. The scope of a structure declaration should
be external storage class whenever a function in the main().
Program Using a Structure datatype:
#include<stdio.h>
/*Defining a Structure*/
struct Test
{
       int a;
       int b;
};
/*Prototype*/
struct Test Modify(struct Test s2);
void main()
{
    struct Test T1={10,20};
    T1=Modify(T1);
    printf(“After calling modifyn”);
    printf(“T1.a=%dn”,T1.a);
    printf(“T1.b=%dn”,T1.b);
}
Stuct Test Modify(struct Test s2)
{
     s2.a=s2.a+10;
S2.b=s2.b+10;
return s2;
}
                     a       b
    a           b    10      20
    10          20
      1              10+10   20+10
    200         30   =20     =30
Union:
Union is another datatype with two or more members,similar to
structure.But in this case all the members share a common
memory location.The members of a union can be refered by using
dot operator as in the case of structure.
The size of union can contain only one type of member at any
one time.
The size of union corresponds to the length of the longest
member.
Syntax:
Union Userdefined_datatype
{
         datatype member 1;
         datatype member n;};
Union Test
{
       char a;
       int b;
       float c;
};
We may have structures with unions and unions with in structures.
Unions may also be intialized like structures.However,Since only
one member can be active at a time,Usually the assigned value will
go to the 1st member of union.

More Related Content

What's hot

Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
Ashim Lamichhane
 
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
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
CGC Technical campus,Mohali
 
Structure in C
Structure in CStructure in C
Structure in C
Kamal Acharya
 
Programming in C session 3
Programming in C session 3Programming in C session 3
Programming in C session 3
Prerna Sharma
 
Structure and union
Structure and unionStructure and union
Structure and union
Samsil Arefin
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
sangrampatil81
 
Structure in C
Structure in CStructure in C
Structure in C
Fazle Rabbi Ador
 
JAVA Data Types - Part 1
JAVA Data Types - Part 1JAVA Data Types - Part 1
JAVA Data Types - Part 1Ashok Asn
 
Structure & union
Structure & unionStructure & union
Structure & union
Rupesh Mishra
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
Krishna Nanda
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
Rai University
 
Cs1123 12 structures
Cs1123 12 structuresCs1123 12 structures
Cs1123 12 structuresTAlha MAlik
 
Structure in c#
Structure in c#Structure in c#
Structure in c#
Dr.Neeraj Kumar Pandey
 
C structure and union
C structure and unionC structure and union
C structure and union
Thesis Scientist Private Limited
 

What's hot (20)

Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
 
Structure in c sharp
Structure in c sharpStructure in c sharp
Structure in c sharp
 
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
 
Structure in C
Structure in CStructure in C
Structure in C
 
Programming in C session 3
Programming in C session 3Programming in C session 3
Programming in C session 3
 
Structure and union
Structure and unionStructure and union
Structure and union
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
 
Structure in C
Structure in CStructure in C
Structure in C
 
JAVA Data Types - Part 1
JAVA Data Types - Part 1JAVA Data Types - Part 1
JAVA Data Types - Part 1
 
Structure & union
Structure & unionStructure & union
Structure & union
 
C++ assignment
C++ assignmentC++ assignment
C++ assignment
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
 
Structure in c
Structure in cStructure in c
Structure in c
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Cs1123 12 structures
Cs1123 12 structuresCs1123 12 structures
Cs1123 12 structures
 
Structure in c#
Structure in c#Structure in c#
Structure in c#
 
C structure and union
C structure and unionC structure and union
C structure and union
 
Ch7 structures
Ch7 structuresCh7 structures
Ch7 structures
 

Similar to Unit4 (2)

Chapter15 structure
Chapter15 structureChapter15 structure
Chapter15 structureDeepak Singh
 
Structures
StructuresStructures
Structures
DrJasmineBeulahG
 
03 structures
03 structures03 structures
03 structures
Rajan Gautam
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9patcha535
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
kavitham66441
 
Str
StrStr
Str
Acad
 
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
sudhakargeruganti
 
C UNIT-4 PREPARED BY M V BRAHMANANDA RE
C UNIT-4 PREPARED BY M V BRAHMANANDA REC UNIT-4 PREPARED BY M V BRAHMANANDA RE
C UNIT-4 PREPARED BY M V BRAHMANANDA RERajeshkumar Reddy
 
Structure In C
Structure In CStructure In C
Structure In C
yndaravind
 
structure.ppt
structure.pptstructure.ppt
structure.ppt
Sheik Mohideen
 
structures.ppt
structures.pptstructures.ppt
structures.ppt
RamyaR163211
 
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
shivani366010
 
637225564198396290.pdf
637225564198396290.pdf637225564198396290.pdf
637225564198396290.pdf
SureshKalirawna
 
Structure & union
Structure & unionStructure & union
Structure & union
lalithambiga kamaraj
 
Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++
Deepak Singh
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
Acad
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
psaravanan1985
 
structure1.pdf
structure1.pdfstructure1.pdf
structure1.pdf
AbhimanyuKumarYadav3
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4
YOGESH SINGH
 

Similar to Unit4 (2) (20)

Chapter15 structure
Chapter15 structureChapter15 structure
Chapter15 structure
 
Structures
StructuresStructures
Structures
 
03 structures
03 structures03 structures
03 structures
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
 
Str
StrStr
Str
 
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
 
C UNIT-4 PREPARED BY M V BRAHMANANDA RE
C UNIT-4 PREPARED BY M V BRAHMANANDA REC UNIT-4 PREPARED BY M V BRAHMANANDA RE
C UNIT-4 PREPARED BY M V BRAHMANANDA RE
 
Structure In C
Structure In CStructure In C
Structure In C
 
Chap 10(structure and unions)
Chap 10(structure and unions)Chap 10(structure and unions)
Chap 10(structure and unions)
 
structure.ppt
structure.pptstructure.ppt
structure.ppt
 
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
 
637225564198396290.pdf
637225564198396290.pdf637225564198396290.pdf
637225564198396290.pdf
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
 
structure1.pdf
structure1.pdfstructure1.pdf
structure1.pdf
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4
 

More from 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
 
Unit3 jwfiles
Unit3 jwfilesUnit3 jwfiles
Unit3 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
 

More from 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
 
Unit4
Unit4Unit4
Unit4
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)
 
Unit6 jwfiles
Unit6 jwfilesUnit6 jwfiles
Unit6 jwfiles
 
Unit3 jwfiles
Unit3 jwfilesUnit3 jwfiles
Unit3 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
 

Recently uploaded

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 

Recently uploaded (20)

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 

Unit4 (2)

  • 1. INTRODUCTION: A structure is a collection of elements of different types of data. Ex: consider the student information roll number, gender, age, height and weight of different types. main() { struct student rno gender 2 1 { int rno; age ht wt 2 4 4 char gender; int age; 13 bytes of memory is allocated in s1
  • 2. 13 bytes of memory is allocated to s2 float ht; age gender float wt; 2 1 }; age ht wt 2 4 4 struct student s1,s2; } When all these data items are grouped under on single variable name, we can get some meaningful information. struct is a keyword used to create a new user defined data type. In some other high level programming languages the structures are named as records
  • 3. DEFINING A STRUCTURE: syntax: Example: struct user defined datatype struct student { { int rno; datatype member1; int age; char gender; datatype member2; float ht; ……………. float wt; }; ………… datatype membern: };
  • 4. In the given syntax struct is keyword used to create new user defined data type. An user defined data type name may be any valid ‘c’ identifier ( user defined name). The data type may be a valid simple data type or compound data type. The member names may be any valid ‘C’ identifiers .in the given example student is a new user defined data type name. The variable rno, age, gender, ht, wt, are the structure members. All these structure members must be enclosed within a pair of curly braces. The structure definition should be terminated with semicolon.
  • 5. DECLARING STRUCTURE VARIABLE: Once a new user defined datatype is created by using the keyboard struct then we can create any no. of structure variables of that type. syntax: struct user defined_data type name structure var1, structure var2,……….. Struct varn; Above statement is called declarative statement of structure variables and it allocates memory space to these variables. We can also declare structure variables immediately after structure definition.
  • 6. ACCESSING STRUCTURE MEMBERS: . Structure member accessing operator  S1.gender=‘m’; s1.age=25; Structure S1.rno=100 S1.ht=5.5; s1.wt=60.2; variable Structure member •Two operators are used to access member of structure. The structure member operator(.) also called dot operator and the structure pointer operator () also called the arrow operator. •The structure member operator accesses a structure member via structure variable name.
  • 7. syntax: Ex: s1.rno, s1.age, s1.gender, s1.ht, s1.wt S1.rno=100; s1.gender=M; s1.age=25; s1.ht=5.5; s1.wt=60.2 s1 s2 rno gender rno gender 100 M age ht wt age ht wt 25 5.5 60.2 ASSIGNING VALUES TO STRUCTURE MEMBERS: By using the assignment operator(=) we can assign values to all structure members of a structure variable. Syntax: structure variable.member = value; Ex: s1.rno= 100; s1.age=25
  • 8. INITIALIZING A STRUCTURE VARIABLE: Structures can be initialized using initialize lists as with arrays. To initialize a structure follow the variable name in the structure declaration with an equal sign and brace enclosed comma separated list of initializes. Ex: struct student s1={100, 25,’M’, 5.5,65.2}; int x = 10; int a[10]={ 10,20,30}; READING AND DISPLAYING THE STRUCTURE VARIABLES: The ‘C’ will not read or write an entire structure as a single command. It will read or write the members of a structure as follows: ex: scanf(“ %d, %d, %c, %f” ,&s1.rno,&s1.age,&s1.gender,&s1.ht); printf(“ %d %d %c %f”, s1.rno, s1.age, s1.gender, s1.ht);
  • 9. PROGRAM USING STRUCTURES:  Reads the details of 2 students and calculate total and average marks of 2 students. #include<stdio.h> #include<conio.h> void main() { /* defining a structure */ struct student { int rno; char name[30]; float m1,m2,m3; float tot, avg; };
  • 10. /* 2. declaration of structure var*/ struct student s1,s2; (1st executed) /* 3.reading 1st student details*/ printf(“ enter rno,name,m1,m2,m3 of first student n”); scanf(“ %d %s %f %f %f ”, &s1.rno,&s1.name,&s1.m1,&s1.m2,&s1.m3); /* 4. reading 2nd student details*/ printf(“ enter rno, name, m1, m2, m3,of second student n); scanf(“ %d %s%f %f %f”, &s2.rno, &s2.name,&s2.m1,&s2.m2,&s2.m3); /* calculate total and avg of first student marks*/ s1.tot= s1.m1+s1.m2+s1.m3; s1.avg = s1.tot/3;
  • 11. /* 6.calculate total and avg of first student marks*/ s2.tot= s2.m1+s2.m2+s2.m3; s2.avg = s2.tot/3; /* displaying first student details*/ printf(“ first student details are n”); printf( “roll no:%dn, name:%s n, m1: %f n. m2:%f, m3:%f n”, s1.rno, s1.name, s1.m1, s1.m2, s1.m3); printf(“ total :%f n , average: %f n”, s1.tot, s1.avg); /* 8. displaying second student details*/ printf(“ second student details are:n); printf( “roll no:%dn, name:%s n, m1: %f n. m2:%f, m3:%f n”, s2.rno, s2.name, s2.m1, s2.m2, s2.m3); printf(“ total :%f n , average: %f n”, s2.tot, s2.avg); }
  • 12. Array of Structures: Perhaps the most common usage of structures is an array of structures. ->To declare an array of structures you must first define a structure and then declare an array variable of that type. For example to declare a 100 element array of structures of type “student” write struct student { int rno; int m1,m2,m3; int tot,avg; } struct student s[100];-Structure Variable Declaration
  • 13. DEMONSTRATING ARRAY OF STRUCTURES: #include<stdio.h> #include <conio.h> void main() { /*1.Defining an array of structures*/ struct student { int rno; int m1,m2,m3; int tot,avg; };
  • 14. /*2.Creating an array of Structures*/ struct student s[100]; int i,n; clrscr(); printf(“Enter n valuen”); /*3.Read total no.of students to n*/ scanf(“%d”,&n); /*4.Reading student details*/ for(i=0;i<n;i++) { printf(“Enter details of %d studentn”,i+1); scanf(“%d”,&s[i].rno);
  • 15. scanf(“%d%d%d”,&s[i].m1,&s[i].m1,&s[i].m2,&s[i].m3); /*5.Calculate tot,avg marks */ for(i=0;i<n;i++) { s[i].tot=s[i].m1+s[i].m2+s[i].m3; s[i].avg=s[i].tot/3; } /*6.Display the student details*/ for(i=0;i<n;i++) { printf(“The following are the %d student detailsn”,i+1); printf(“Rollno:%dn”,s[i].rno);
  • 17. Arrays with in Structures: A member of a structure may be either a simple or compound type. simple member is one that is of any of the built-in datatypes such as integer or character. ->The compound datatypes include one dimensional and multidimensional arrays of other datatypes and structures. For example consider this Structure: struct x { int rno; int m[3];/* An Array is described as a structure member*/ int tot,avg; }
  • 18. Nested Structures: when a structure variable is a member of another structure, it is called a Nested structure. ->In the below example structure variable ‘z’ is declared as structure Member to another structure. EX:struct Test { int a; int b; }; Struct Exam { int x; int y; struct Test z; };
  • 19. Structures and Function: A Structure can be passed to a function as a one variable or as an individual member. The scope of a structure declaration should be external storage class whenever a function in the main(). Program Using a Structure datatype: #include<stdio.h> /*Defining a Structure*/ struct Test { int a; int b; }; /*Prototype*/
  • 20. struct Test Modify(struct Test s2); void main() { struct Test T1={10,20}; T1=Modify(T1); printf(“After calling modifyn”); printf(“T1.a=%dn”,T1.a); printf(“T1.b=%dn”,T1.b); } Stuct Test Modify(struct Test s2) { s2.a=s2.a+10;
  • 21. S2.b=s2.b+10; return s2; } a b a b 10 20 10 20 1 10+10 20+10 200 30 =20 =30
  • 22. Union: Union is another datatype with two or more members,similar to structure.But in this case all the members share a common memory location.The members of a union can be refered by using dot operator as in the case of structure. The size of union can contain only one type of member at any one time. The size of union corresponds to the length of the longest member. Syntax: Union Userdefined_datatype { datatype member 1; datatype member n;};
  • 23. Union Test { char a; int b; float c; }; We may have structures with unions and unions with in structures. Unions may also be intialized like structures.However,Since only one member can be active at a time,Usually the assigned value will go to the 1st member of union.