SlideShare ist ein Scribd-Unternehmen logo
1 von 8
Structure:
A structure is a collection of one or more variables of different data
types.grouped together under a single name.
Declaration:
The declaration of structure is:
struct struct_name
{
type variable1;
type variable2;
----------------
}
Where “struct” is the keyword to create a structure variables tag-name
identifies the particular structure and its type.
The declaration has not declared any variables .It simply describes a format
called “template “ to represent information as shown
struct book
{
char title[20];
char name[15];
int pages;
float price;
};
The structure declaration is enclosed with in a pair of curly braces.
The fields are called structure elements or members
Eg:
struct stu
{
char name[20];
int rno;
}
struct stu s={“jhon”,43};
Here the name john is assigned to s.name and 43 to s.rno.
The period() sign is used to accesss the structure members.
The link between member and a variable is established using the member
operator . Which is known as dot or period operator.
Eg:s.sname
struct stu s={“aa”,2};
struct stu s1={“bb”,3};
struct s2={“cc”,4};
WRITE A PROGRAM ILLUSTRATING to accept the day month and year and
display it by using structures
void main()
{
struct date
{
int day,month,year;
};
struct date d;
printf(“enter day,month,year”);
scanf(“%d%d%d”,&d.day,&d.month,&d.year);
printf(“day=%d,month=%d,year=%d”,d.day,d.month,d.year);
getch();
}
Output: 01 02 2008
Day 1 month 02 year 2008
WRITE A PROGRAM ILLUSTRATING to initialize the members of a structure
student as roll number,name,weight display the content
void main ()
{
int no;
int height, weight;
char name [20];
};
structure student s={3,167,65,”aa”};
printf(“%d%d%d%s”,s.rno,s.height,s.weight,s.name};
getch();
}
Output:
3 167 65 aa
Structure with in a structure:
We can take any data type for declaring structure members like int, float
,char etc.
In the same way we can also take object of one structure as member in
another structure.
Thus,structure with in structure can be used to create complExamle data
applications.
The syntax of the structure within the structure is
struct time
{
int second;
int minute;
int hour;
};
struct t
{
int num;
struct time st;
struct time ct;
};
WRITE A PROGRAM ILLUSTRATING structure with in a structure
Array of structures
As we know array is a collection of similar data types.In the same way we
can also define array of structures.
In such type of array every element is of structure type array of structure
can be declared as
struct time
{
int second;
int minute;
int hour;
}t[3];
In this t[3] is an array of 3 elemrnts containing 3 objects or time structure .
Each element of t[3] has structure of time with 3 members that are second
,minute and hour.
Examle program
Array within structures:
C permits the use of arrays as structure members We can use single or multi
dimensional arrays of type int or float.
Examle: struct marks
{
int number;
flaot subject[3];
}
student[2];
Here the member subject contains 3 elements
subject[0],subject[1],subject[2];
These elements can be accessed using appropriate subscripts.
Example:
Pointer to structure:
Pointer is a variable that holds the address of another data variable. The
variable may be of any data type i.e int,float or double. Starting address of
the member variable can be accessed by using structure pointers.
struct book
{
char name[25];
char author[25];
int pages;
};
struct book *ptr;
*ptr is a pointer to structure book.The syntax for using pointer with member
is as given
Ptr->name
Structure and fuctions:
User defined datatypes:
There are two user defined datatypes
1.Enumerated datatype
2. Typedef
Enum:
Enum is a keyword .It is used for declaring enumeration types.
- The programmer can create his own datatype and define what values
the variables of these datatypes can hold.
- This enumeration datatype helps in reading the program.
EG: enum month(jan,feb,mar,april,may}
This statement creates a user defined datatype the keyword enum is
followed by the tagname month .enumerators jan,feb,…. And so on are
Identifiers Jan refer to 0,feb to 1 and so on.
The identifiers are not to be enclosed within quotation marks.
-Integer constants are not permitted.
Eg
Type def:
C provides the type def keyword that allows you to specify a new name
for a datatype already provided in the C programming language.
So the typedef keyword to specify an identifier for an Examleisting
datatype.
The declaration for the typedef keyword is:
Typedef datatype new name
This datatype represents the Examleisting datatype for which you want to
specify an identifier and new name refer to that identifier.
Examle: typedef int num;
WRITE A PROGRAM ILLUSTRATING for typedef
int main(void)
{
typedef int num;
num a,b,add;
a=10;
b=20;
add=0;
add=a+b;
clrscr();
printf(“the sum of %d and %d is %d”,a,b,add);
getch();
return 0;
}

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
 
cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
C functions
C functionsC functions
C functions
 
2D Array
2D Array 2D Array
2D Array
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
String functions in C
String functions in CString functions in C
String functions in C
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Break and continue
Break and continueBreak and continue
Break and continue
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdfSTRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
 

Andere mochten auch

c and data structures first unit notes (jntuh syllabus)
c and data structures first unit notes (jntuh syllabus)c and data structures first unit notes (jntuh syllabus)
c and data structures first unit notes (jntuh syllabus)Acad
 
Union from C and Data Strutures
Union from C and Data StruturesUnion from C and Data Strutures
Union from C and Data StruturesAcad
 
Data retrieval in sensor networks
Data retrieval in sensor networksData retrieval in sensor networks
Data retrieval in sensor networksAcad
 
Tiny os
Tiny osTiny os
Tiny osAcad
 
Branch and bound
Branch and boundBranch and bound
Branch and boundAcad
 
Classification and prediction
Classification and predictionClassification and prediction
Classification and predictionAcad
 
Cluster analysis
Cluster analysisCluster analysis
Cluster analysisAcad
 
pipeline and vector processing
pipeline and vector processingpipeline and vector processing
pipeline and vector processingAcad
 
input output Organization
input output Organizationinput output Organization
input output OrganizationAcad
 
Prim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmPrim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmAcad
 
Memory Organization
Memory OrganizationMemory Organization
Memory OrganizationAcad
 
Association rule mining
Association rule miningAssociation rule mining
Association rule miningAcad
 

Andere mochten auch (12)

c and data structures first unit notes (jntuh syllabus)
c and data structures first unit notes (jntuh syllabus)c and data structures first unit notes (jntuh syllabus)
c and data structures first unit notes (jntuh syllabus)
 
Union from C and Data Strutures
Union from C and Data StruturesUnion from C and Data Strutures
Union from C and Data Strutures
 
Data retrieval in sensor networks
Data retrieval in sensor networksData retrieval in sensor networks
Data retrieval in sensor networks
 
Tiny os
Tiny osTiny os
Tiny os
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Classification and prediction
Classification and predictionClassification and prediction
Classification and prediction
 
Cluster analysis
Cluster analysisCluster analysis
Cluster analysis
 
pipeline and vector processing
pipeline and vector processingpipeline and vector processing
pipeline and vector processing
 
input output Organization
input output Organizationinput output Organization
input output Organization
 
Prim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmPrim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithm
 
Memory Organization
Memory OrganizationMemory Organization
Memory Organization
 
Association rule mining
Association rule miningAssociation rule mining
Association rule mining
 

Ähnlich wie Structure and Typedef

Ähnlich wie Structure and Typedef (20)

Str
StrStr
Str
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
 
Unit 4 qba
Unit 4 qbaUnit 4 qba
Unit 4 qba
 
C structure and union
C structure and unionC structure and union
C structure and union
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
9.structure & union
9.structure & union9.structure & union
9.structure & union
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And Unions
 
Unit4 (2)
Unit4 (2)Unit4 (2)
Unit4 (2)
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
 
Structure & union
Structure & unionStructure & union
Structure & union
 
structures_v1.ppt
structures_v1.pptstructures_v1.ppt
structures_v1.ppt
 
structures_v1.ppt
structures_v1.pptstructures_v1.ppt
structures_v1.ppt
 
structure1.pdf
structure1.pdfstructure1.pdf
structure1.pdf
 
Structure prespentation
Structure prespentation Structure prespentation
Structure prespentation
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
Programming in C session 3
Programming in C session 3Programming in C session 3
Programming in C session 3
 
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
 

Mehr von Acad

routing alg.pptx
routing alg.pptxrouting alg.pptx
routing alg.pptxAcad
 
Network Layer design Issues.pptx
Network Layer design Issues.pptxNetwork Layer design Issues.pptx
Network Layer design Issues.pptxAcad
 
Computer Science basics
Computer Science basics Computer Science basics
Computer Science basics Acad
 
Union
UnionUnion
UnionAcad
 
Stacks
StacksStacks
StacksAcad
 
Functions
FunctionsFunctions
FunctionsAcad
 
File
FileFile
FileAcad
 
Ds
DsDs
DsAcad
 
Dma
DmaDma
DmaAcad
 
Botnet detection by Imitation method
Botnet detection  by Imitation methodBotnet detection  by Imitation method
Botnet detection by Imitation methodAcad
 
Bot net detection by using ssl encryption
Bot net detection by using ssl encryptionBot net detection by using ssl encryption
Bot net detection by using ssl encryptionAcad
 
An Aggregate Location Monitoring System Of Privacy Preserving In Authenticati...
An Aggregate Location Monitoring System Of Privacy Preserving In Authenticati...An Aggregate Location Monitoring System Of Privacy Preserving In Authenticati...
An Aggregate Location Monitoring System Of Privacy Preserving In Authenticati...Acad
 
Literature survey on peer to peer botnets
Literature survey on peer to peer botnetsLiterature survey on peer to peer botnets
Literature survey on peer to peer botnetsAcad
 
multi processors
multi processorsmulti processors
multi processorsAcad
 

Mehr von Acad (14)

routing alg.pptx
routing alg.pptxrouting alg.pptx
routing alg.pptx
 
Network Layer design Issues.pptx
Network Layer design Issues.pptxNetwork Layer design Issues.pptx
Network Layer design Issues.pptx
 
Computer Science basics
Computer Science basics Computer Science basics
Computer Science basics
 
Union
UnionUnion
Union
 
Stacks
StacksStacks
Stacks
 
Functions
FunctionsFunctions
Functions
 
File
FileFile
File
 
Ds
DsDs
Ds
 
Dma
DmaDma
Dma
 
Botnet detection by Imitation method
Botnet detection  by Imitation methodBotnet detection  by Imitation method
Botnet detection by Imitation method
 
Bot net detection by using ssl encryption
Bot net detection by using ssl encryptionBot net detection by using ssl encryption
Bot net detection by using ssl encryption
 
An Aggregate Location Monitoring System Of Privacy Preserving In Authenticati...
An Aggregate Location Monitoring System Of Privacy Preserving In Authenticati...An Aggregate Location Monitoring System Of Privacy Preserving In Authenticati...
An Aggregate Location Monitoring System Of Privacy Preserving In Authenticati...
 
Literature survey on peer to peer botnets
Literature survey on peer to peer botnetsLiterature survey on peer to peer botnets
Literature survey on peer to peer botnets
 
multi processors
multi processorsmulti processors
multi processors
 

Kürzlich hochgeladen

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Kürzlich hochgeladen (20)

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

Structure and Typedef

  • 1. Structure: A structure is a collection of one or more variables of different data types.grouped together under a single name. Declaration: The declaration of structure is: struct struct_name { type variable1; type variable2; ---------------- } Where “struct” is the keyword to create a structure variables tag-name identifies the particular structure and its type. The declaration has not declared any variables .It simply describes a format called “template “ to represent information as shown struct book { char title[20]; char name[15]; int pages; float price;
  • 2. }; The structure declaration is enclosed with in a pair of curly braces. The fields are called structure elements or members Eg: struct stu { char name[20]; int rno; } struct stu s={“jhon”,43}; Here the name john is assigned to s.name and 43 to s.rno. The period() sign is used to accesss the structure members. The link between member and a variable is established using the member operator . Which is known as dot or period operator. Eg:s.sname struct stu s={“aa”,2}; struct stu s1={“bb”,3}; struct s2={“cc”,4}; WRITE A PROGRAM ILLUSTRATING to accept the day month and year and display it by using structures void main() { struct date
  • 3. { int day,month,year; }; struct date d; printf(“enter day,month,year”); scanf(“%d%d%d”,&d.day,&d.month,&d.year); printf(“day=%d,month=%d,year=%d”,d.day,d.month,d.year); getch(); } Output: 01 02 2008 Day 1 month 02 year 2008 WRITE A PROGRAM ILLUSTRATING to initialize the members of a structure student as roll number,name,weight display the content void main () { int no; int height, weight; char name [20]; }; structure student s={3,167,65,”aa”}; printf(“%d%d%d%s”,s.rno,s.height,s.weight,s.name}; getch(); } Output:
  • 4. 3 167 65 aa Structure with in a structure: We can take any data type for declaring structure members like int, float ,char etc. In the same way we can also take object of one structure as member in another structure. Thus,structure with in structure can be used to create complExamle data applications. The syntax of the structure within the structure is struct time { int second; int minute; int hour; }; struct t { int num; struct time st; struct time ct; };
  • 5. WRITE A PROGRAM ILLUSTRATING structure with in a structure Array of structures As we know array is a collection of similar data types.In the same way we can also define array of structures. In such type of array every element is of structure type array of structure can be declared as struct time { int second; int minute; int hour; }t[3]; In this t[3] is an array of 3 elemrnts containing 3 objects or time structure . Each element of t[3] has structure of time with 3 members that are second ,minute and hour. Examle program Array within structures: C permits the use of arrays as structure members We can use single or multi dimensional arrays of type int or float. Examle: struct marks { int number;
  • 6. flaot subject[3]; } student[2]; Here the member subject contains 3 elements subject[0],subject[1],subject[2]; These elements can be accessed using appropriate subscripts. Example: Pointer to structure: Pointer is a variable that holds the address of another data variable. The variable may be of any data type i.e int,float or double. Starting address of the member variable can be accessed by using structure pointers. struct book { char name[25]; char author[25]; int pages; }; struct book *ptr; *ptr is a pointer to structure book.The syntax for using pointer with member is as given Ptr->name Structure and fuctions: User defined datatypes: There are two user defined datatypes
  • 7. 1.Enumerated datatype 2. Typedef Enum: Enum is a keyword .It is used for declaring enumeration types. - The programmer can create his own datatype and define what values the variables of these datatypes can hold. - This enumeration datatype helps in reading the program. EG: enum month(jan,feb,mar,april,may} This statement creates a user defined datatype the keyword enum is followed by the tagname month .enumerators jan,feb,…. And so on are Identifiers Jan refer to 0,feb to 1 and so on. The identifiers are not to be enclosed within quotation marks. -Integer constants are not permitted. Eg Type def: C provides the type def keyword that allows you to specify a new name for a datatype already provided in the C programming language. So the typedef keyword to specify an identifier for an Examleisting datatype. The declaration for the typedef keyword is: Typedef datatype new name This datatype represents the Examleisting datatype for which you want to specify an identifier and new name refer to that identifier. Examle: typedef int num;
  • 8. WRITE A PROGRAM ILLUSTRATING for typedef int main(void) { typedef int num; num a,b,add; a=10; b=20; add=0; add=a+b; clrscr(); printf(“the sum of %d and %d is %d”,a,b,add); getch(); return 0; }