SlideShare a Scribd company logo
•STRUCTURE
•UNIONS
1. INTRODUCTION
 C’ Supports a constructed data type known
as STRUCTURE, Which is a method of
packing data of different types.
WHAT IS STRUCTURE ?
 A Structure is a convenient tool for handling
a group of logically related data items.
 i.e. It can be used to represent a set of
attributes, such as : student_name , roll_no
A structure defination creates a
formet that may be used to declare
structure variables.
i.e. Consider a book database
consisting of a book name, Author,
Number of pages and price.
We can define a structure to hold this
information as follows:
Struct tag_name
{
data_type member1;
data_type member2;
… …
……… …..
};
1. The template terminated with a semicolon
2. While the entire declarationn considered as a
satement, each member is declared
indepandently for its name and type in a
separate statement inside the teplate.
3. The tag name such as book_bank can be
used to declare structure variables of its
type,letter in the program.
Struct book_bank
{
Char title[20];
Char author[15];
Int pages;
Float price;
};
 The keyword struct declares a structure to
hold the details of four fields, namely
title,author,pages and price.
 These fields are called structure elements or
members and each member belong to
different type of data.
 Book_bank is the name of the structure and
also called ‘STRUCTURE TAG’.
title
author
pages
price
Array of 15
characters
integer
float
Array of 20 characters
 The link between a member and variable is
established using the member operator ‘.’
which is also known as ‘dot operator’ or
‘period operator’.
 i.e.
book1.price
 Is the variable represnting the price of book1
and can be treated like any other ordinary
variable.
 Here is how we would assign values to the
members of book1:
strcpy(book1.title, “COMPUTER”);
strcpy(book1.author, “XYZ”);
book1.pages=250;
book1.price=29.99;
 We can also use scanf to give the values
through keyboard.
 A Structure must be declared as static if it is
to be initialized inside a function.
 main()
{
static struct
{
int weight;
float height;
}
student = (60,180.75);
…..
}
 If there are fewer initialization than that of
member variables in the structure. The
remaining member variables are initialized to
zero.
 i.e. if we don’t know the number of pages in
book:
struct book b1={“let us
C”,”kanetkar”,0,150.50};
 We use structure todescribe the format of a
number related variables.
 In such cases, we may declare array of
structures,each element of an array represent
a structure variable
 i.e. struct class student[100]
 This defines an array called student , that
consists of 100 element.
 Each element is defined to be of the type
struct class.
 An array of structure is stored inside the
memory in the same way as a multi-
dimensional array.
 C permits the use of array as a structure
members.
 We can use single or multi-dimensional array
of type int or float.
 i.e. Struct marks
{
int number;
float subject[3];
} student[2];
 The main philosophy of c language is the use
of functions. C supports the passing of
structure values as arguments to function.
 There are 3 methods by which the values of a
structure can be transfferd from one function
to another:
1. To pass each member of the structure as an
argument of function call.
2. Passing of a copy of the entire structure to
the called function
3. Pointers to pass the structure as an
argument.
 General formet of sending a copy of a
structure to thr called function:
data_type function name(st_name)
srtuct_type st_name;
{
…
return(expression);
}
 Unions are a concept borrowed from
structures and therefore follow the same
syntax as structures.
 Major diffferance in terms of Storage:
In structures each member has its
own storage location
In unions all members use the same
location
 Union may contain many members of
different type but can handle only one
member at a time.
 It can be declared using keyword union as
follows:
 union item
{
int m;
float x;
char c;
} code;
 Union union_name
{
data_type member1;
data_type mrmber2;
… … .. …..
} var1, var2, .. ;
Union book;
{
char title[15];
char *author;
int pages;
float price;
} b1, b2, b3;
 A union variable can be assigned to another
union variable.
 Address of the union variable is obtained
using the address of ‘&’ operator.
 It is to pass a union to function and a
function can return a union.
 We can use pointer to unions and within
unions.
 All members share the same storage area in
computers memory.

More Related Content

What's hot

Structure in C language
Structure in C languageStructure in C language
Structure in C language
CGC Technical campus,Mohali
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
Kamal Acharya
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
Arpana shree
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
Ashim Lamichhane
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Jayanshu Gundaniya
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
Wingston
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 
Union In language C
Union In language CUnion In language C
Union In language C
Ravi Singh
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
Appili Vamsi Krishna
 
Let us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solutionLet us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solution
Hazrat Bilal
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
Dr-Dipali Meher
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
Vineeta Garg
 
Arrays in c
Arrays in cArrays in c
Arrays in c
Jeeva Nanthini
 
Let us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solutionLet us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solution
rohit kumar
 
Structure in c
Structure in cStructure in c
Structure in c
Prabhu Govind
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1
srmohan06
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 

What's hot (20)

Structure in C language
Structure in C languageStructure in C language
Structure in C language
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Union In language C
Union In language CUnion In language C
Union In language C
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Let us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solutionLet us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solution
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Let us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solutionLet us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solution
 
Structure in c
Structure in cStructure in c
Structure in c
 
Strings in C
Strings in CStrings in C
Strings in C
 
Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 

Viewers also liked

Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3
Akshay Nagpurkar
 
Principles of programming languages. Detail notes
Principles of programming languages. Detail notesPrinciples of programming languages. Detail notes
Principles of programming languages. Detail notes
VIKAS SINGH BHADOURIA
 
Unit 4
Unit 4Unit 4
Unit 5
Unit 5Unit 5
Unit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesUnit 2 Principles of Programming Languages
Unit 2 Principles of Programming Languages
Vasavi College of Engg
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
Vasavi College of Engg
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
Vasavi College of Engg
 
Standing waves
Standing wavesStanding waves
Standing waves
degaa
 
Beti hai to kal hai- july 2016
Beti hai to kal hai- july 2016Beti hai to kal hai- july 2016
Beti hai to kal hai- july 2016
Withs Technosolutions
 
TOOBEEZ Product Guide
TOOBEEZ Product GuideTOOBEEZ Product Guide
TOOBEEZ Product Guide
Chris Stummer
 
Vipra today november 16
Vipra today november 16Vipra today november 16
Vipra today november 16
Withs Technosolutions
 
Omar Hanafy (1)
Omar Hanafy (1)Omar Hanafy (1)
Omar Hanafy (1)
omar hanafy
 
CV NEW NEW (1)
CV NEW NEW (1)CV NEW NEW (1)
CV NEW NEW (1)
Patra Nona
 
NoSQL as Not Only SQL
NoSQL as Not Only SQLNoSQL as Not Only SQL
NoSQL as Not Only SQL
Stefanie Janine Stölting
 
Survey of Instruction Hotel Management Prof Godbe
Survey of Instruction Hotel Management Prof GodbeSurvey of Instruction Hotel Management Prof Godbe
Survey of Instruction Hotel Management Prof Godbe
Bill Godbe
 
Marcella Marletta - Vigilanza, sorveglianza del mercato e contraffazione
Marcella Marletta - Vigilanza, sorveglianza del mercato e contraffazioneMarcella Marletta - Vigilanza, sorveglianza del mercato e contraffazione
Marcella Marletta - Vigilanza, sorveglianza del mercato e contraffazione
Marcella Marletta
 
Good Manufacturing Practices Awareness Posters
Good Manufacturing Practices Awareness PostersGood Manufacturing Practices Awareness Posters
Good Manufacturing Practices Awareness Posters
Sachin Sarkhot
 
LawGeex gives you back your TIME.
LawGeex gives you back your TIME.LawGeex gives you back your TIME.
LawGeex gives you back your TIME.
Manson Ho
 

Viewers also liked (18)

Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3
 
Principles of programming languages. Detail notes
Principles of programming languages. Detail notesPrinciples of programming languages. Detail notes
Principles of programming languages. Detail notes
 
Unit 4
Unit 4Unit 4
Unit 4
 
Unit 5
Unit 5Unit 5
Unit 5
 
Unit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesUnit 2 Principles of Programming Languages
Unit 2 Principles of Programming Languages
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
 
Standing waves
Standing wavesStanding waves
Standing waves
 
Beti hai to kal hai- july 2016
Beti hai to kal hai- july 2016Beti hai to kal hai- july 2016
Beti hai to kal hai- july 2016
 
TOOBEEZ Product Guide
TOOBEEZ Product GuideTOOBEEZ Product Guide
TOOBEEZ Product Guide
 
Vipra today november 16
Vipra today november 16Vipra today november 16
Vipra today november 16
 
Omar Hanafy (1)
Omar Hanafy (1)Omar Hanafy (1)
Omar Hanafy (1)
 
CV NEW NEW (1)
CV NEW NEW (1)CV NEW NEW (1)
CV NEW NEW (1)
 
NoSQL as Not Only SQL
NoSQL as Not Only SQLNoSQL as Not Only SQL
NoSQL as Not Only SQL
 
Survey of Instruction Hotel Management Prof Godbe
Survey of Instruction Hotel Management Prof GodbeSurvey of Instruction Hotel Management Prof Godbe
Survey of Instruction Hotel Management Prof Godbe
 
Marcella Marletta - Vigilanza, sorveglianza del mercato e contraffazione
Marcella Marletta - Vigilanza, sorveglianza del mercato e contraffazioneMarcella Marletta - Vigilanza, sorveglianza del mercato e contraffazione
Marcella Marletta - Vigilanza, sorveglianza del mercato e contraffazione
 
Good Manufacturing Practices Awareness Posters
Good Manufacturing Practices Awareness PostersGood Manufacturing Practices Awareness Posters
Good Manufacturing Practices Awareness Posters
 
LawGeex gives you back your TIME.
LawGeex gives you back your TIME.LawGeex gives you back your TIME.
LawGeex gives you back your TIME.
 

Similar to CPU : Structures And Unions

structure and union1.pdf
structure and union1.pdfstructure and union1.pdf
structure and union1.pdf
HMCollegeInfo
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
Mehul Desai
 
Lecture 19 - Struct and Union
Lecture 19 - Struct and UnionLecture 19 - Struct and Union
Lecture 19 - Struct and Union
Md. Imran Hossain Showrov
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
Tanmay Modi
 
Unit 4 qba
Unit 4 qbaUnit 4 qba
Unit 4 qba
Sowri Rajan
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
Swarup Boro
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
Swarup Kumar Boro
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
Krishna Nanda
 
Programming in C
Programming in CProgramming in C
Programming in C
MalathiNagarajan20
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9
patcha535
 
C structure and union
C structure and unionC structure and union
C structure and union
Thesis Scientist Private Limited
 
Structure & union
Structure & unionStructure & union
Structure & union
lalithambiga kamaraj
 
9.structure & union
9.structure & union9.structure & union
9.structure & union
Shankar Gangaju
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
Acad
 
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
Rajeshkumar Reddy
 
Str
StrStr
Str
Acad
 
Definition, Declaration of Structures in C.pptx
Definition, Declaration of Structures in C.pptxDefinition, Declaration of Structures in C.pptx
Definition, Declaration of Structures in C.pptx
AnithaTAssistantProf
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
Manisha Keim
 
Programming in C session 3
Programming in C session 3Programming in C session 3
Programming in C session 3
Prerna Sharma
 
Structures in c programming
Structures in c programmingStructures in c programming
Structures in c programming
Kousalya M
 

Similar to CPU : Structures And Unions (20)

structure and union1.pdf
structure and union1.pdfstructure and union1.pdf
structure and union1.pdf
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
 
Lecture 19 - Struct and Union
Lecture 19 - Struct and UnionLecture 19 - Struct and Union
Lecture 19 - Struct and Union
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Unit 4 qba
Unit 4 qbaUnit 4 qba
Unit 4 qba
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9
 
C structure and union
C structure and unionC structure and union
C structure and union
 
Structure & union
Structure & unionStructure & union
Structure & union
 
9.structure & union
9.structure & union9.structure & union
9.structure & union
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
 
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
 
Str
StrStr
Str
 
Definition, Declaration of Structures in C.pptx
Definition, Declaration of Structures in C.pptxDefinition, Declaration of Structures in C.pptx
Definition, Declaration of Structures in C.pptx
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
 
Programming in C session 3
Programming in C session 3Programming in C session 3
Programming in C session 3
 
Structures in c programming
Structures in c programmingStructures in c programming
Structures in c programming
 

Recently uploaded

Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 

Recently uploaded (20)

Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 

CPU : Structures And Unions

  • 2. 1. INTRODUCTION  C’ Supports a constructed data type known as STRUCTURE, Which is a method of packing data of different types. WHAT IS STRUCTURE ?  A Structure is a convenient tool for handling a group of logically related data items.  i.e. It can be used to represent a set of attributes, such as : student_name , roll_no
  • 3. A structure defination creates a formet that may be used to declare structure variables. i.e. Consider a book database consisting of a book name, Author, Number of pages and price. We can define a structure to hold this information as follows:
  • 4. Struct tag_name { data_type member1; data_type member2; … … ……… ….. };
  • 5. 1. The template terminated with a semicolon 2. While the entire declarationn considered as a satement, each member is declared indepandently for its name and type in a separate statement inside the teplate. 3. The tag name such as book_bank can be used to declare structure variables of its type,letter in the program.
  • 6. Struct book_bank { Char title[20]; Char author[15]; Int pages; Float price; };
  • 7.  The keyword struct declares a structure to hold the details of four fields, namely title,author,pages and price.  These fields are called structure elements or members and each member belong to different type of data.  Book_bank is the name of the structure and also called ‘STRUCTURE TAG’.
  • 9.  The link between a member and variable is established using the member operator ‘.’ which is also known as ‘dot operator’ or ‘period operator’.  i.e. book1.price  Is the variable represnting the price of book1 and can be treated like any other ordinary variable.
  • 10.  Here is how we would assign values to the members of book1: strcpy(book1.title, “COMPUTER”); strcpy(book1.author, “XYZ”); book1.pages=250; book1.price=29.99;  We can also use scanf to give the values through keyboard.
  • 11.  A Structure must be declared as static if it is to be initialized inside a function.  main() { static struct { int weight; float height; } student = (60,180.75); ….. }
  • 12.  If there are fewer initialization than that of member variables in the structure. The remaining member variables are initialized to zero.  i.e. if we don’t know the number of pages in book: struct book b1={“let us C”,”kanetkar”,0,150.50};
  • 13.  We use structure todescribe the format of a number related variables.  In such cases, we may declare array of structures,each element of an array represent a structure variable  i.e. struct class student[100]  This defines an array called student , that consists of 100 element.
  • 14.  Each element is defined to be of the type struct class.  An array of structure is stored inside the memory in the same way as a multi- dimensional array.
  • 15.  C permits the use of array as a structure members.  We can use single or multi-dimensional array of type int or float.  i.e. Struct marks { int number; float subject[3]; } student[2];
  • 16.  The main philosophy of c language is the use of functions. C supports the passing of structure values as arguments to function.  There are 3 methods by which the values of a structure can be transfferd from one function to another: 1. To pass each member of the structure as an argument of function call.
  • 17. 2. Passing of a copy of the entire structure to the called function 3. Pointers to pass the structure as an argument.  General formet of sending a copy of a structure to thr called function: data_type function name(st_name) srtuct_type st_name; { … return(expression); }
  • 18.  Unions are a concept borrowed from structures and therefore follow the same syntax as structures.  Major diffferance in terms of Storage: In structures each member has its own storage location In unions all members use the same location
  • 19.  Union may contain many members of different type but can handle only one member at a time.  It can be declared using keyword union as follows:  union item { int m; float x; char c; } code;
  • 20.  Union union_name { data_type member1; data_type mrmber2; … … .. ….. } var1, var2, .. ;
  • 21. Union book; { char title[15]; char *author; int pages; float price; } b1, b2, b3;
  • 22.  A union variable can be assigned to another union variable.  Address of the union variable is obtained using the address of ‘&’ operator.  It is to pass a union to function and a function can return a union.  We can use pointer to unions and within unions.
  • 23.  All members share the same storage area in computers memory.