SlideShare a Scribd company logo
STRUCTURE
•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 ?

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
i.e. Consider a book database
consisting of a book name, Author,
Numbe of pages and price.
We can define a structure to hold this
information as follows:
Struct tag_name
{
data_type
data_type
…
member1;
member2;
…
…
………
…
…..
};
1. The template terminated with a semicolon
2. While the entire declarationn considered as
satement, each member is declared
indepandently for its name and type in a
a
indepandently for its name and type in a
separate statement inside the teplate.
3. The tag name such as book can be used to
declare structure variable later in the program
Struct book
{
Char title[20];
Char author[15];
Int pages;
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
members and each member belong to
different type of data.
Book is the name of the structure and
also called ‘STRUCTURE TAG’.
title
author
pages
price
Array of 20 characters
Array of 15
characters
integer
float
Declaring structure variable
After defining structure format we can declare variable
of data type. Structure variable declaration is similar to the
declaration of variables of any other data type.
It includes the following element.
The keyword struct.
Structure big-name
List of variable names separated by commas.
List of variable names separated by commas.
Terminating semicolon (;)
Eg: the statement
Struct book a,b,c;
Declare a,b,c as variables of type struct book. Each one of
these variables has 4 members as specified in the
definition complete declaration
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.
Accessing structure Members
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
members of book1:
strcpy(book1.title, “COMPUTER”);
strcpy(book1.author, “XYZ”);
the
strcpy(book1.author, “XYZ”);
book1.pages=250;
book1.price=29.99;
We can also use scanf to give the
values
through keyboard.

More Related Content

PPTX
C Structures and Unions
PPTX
CPU : Structures And Unions
PPTX
Definition, Declaration of Structures in C.pptx
PDF
Lk module4 structures
PDF
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
PPTX
Unit-V.pptx
PPT
Lecture number three Structures (1).ppt
PPT
Structures-in-C programming with examples
C Structures and Unions
CPU : Structures And Unions
Definition, Declaration of Structures in C.pptx
Lk module4 structures
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
Unit-V.pptx
Lecture number three Structures (1).ppt
Structures-in-C programming with examples

Similar to structure and union1.pdf (20)

PPTX
U5 SPC.pptx
PPTX
Structure & union
PPTX
Structures.pptx
PPTX
Structure prespentation
PPTX
Structures in c language
PPTX
Structures in c language
PDF
Chapter 13.1.9
PPTX
Structures
PPTX
ECE2102-Week13 - 14-Strhhhhhhhjjjucts.pptx
PDF
Unit 4 qba
PPTX
Chapter 2 part II array and structure.pptx
DOCX
C programming structures & union
PPTX
Data Structures and Algorithms_Updated.pptx
PDF
unit 5.pdf structure pdf is here you can do this
PPTX
vkvkhkdflaksjdlfjalkjfaljklajskldjaklsjdklajsdkljaklsjdklajskdljaklsdjklaj
PPTX
Unit 9. Structure and Unions
PPT
C Language_PPS_3110003_unit 8ClassPPT.ppt
DOCX
Structure and Typedef
PDF
Unit 3
U5 SPC.pptx
Structure & union
Structures.pptx
Structure prespentation
Structures in c language
Structures in c language
Chapter 13.1.9
Structures
ECE2102-Week13 - 14-Strhhhhhhhjjjucts.pptx
Unit 4 qba
Chapter 2 part II array and structure.pptx
C programming structures & union
Data Structures and Algorithms_Updated.pptx
unit 5.pdf structure pdf is here you can do this
vkvkhkdflaksjdlfjalkjfaljklajskldjaklsjdklajsdkljaklsjdklajskdljaklsdjklaj
Unit 9. Structure and Unions
C Language_PPS_3110003_unit 8ClassPPT.ppt
Structure and Typedef
Unit 3

Recently uploaded (20)

PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
medical staffing services at VALiNTRY
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
ai tools demonstartion for schools and inter college
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
top salesforce developer skills in 2025.pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
System and Network Administraation Chapter 3
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Digital Strategies for Manufacturing Companies
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
CHAPTER 2 - PM Management and IT Context
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Wondershare Filmora 15 Crack With Activation Key [2025
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
medical staffing services at VALiNTRY
Understanding Forklifts - TECH EHS Solution
ai tools demonstartion for schools and inter college
2025 Textile ERP Trends: SAP, Odoo & Oracle
top salesforce developer skills in 2025.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
System and Network Administraation Chapter 3
Reimagine Home Health with the Power of Agentic AI​
Odoo Companies in India – Driving Business Transformation.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Digital Strategies for Manufacturing Companies
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
VVF-Customer-Presentation2025-Ver1.9.pptx
Operating system designcfffgfgggggggvggggggggg

structure and union1.pdf

  • 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 ?  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 i.e. Consider a book database consisting of a book name, Author, Numbe of pages and price. We can define a structure to hold this information as follows:
  • 5. 1. The template terminated with a semicolon 2. While the entire declarationn considered as satement, each member is declared indepandently for its name and type in a a indepandently for its name and type in a separate statement inside the teplate. 3. The tag name such as book can be used to declare structure variable later in the program
  • 6. Struct book { Char title[20]; Char author[15]; Int pages; 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 members and each member belong to different type of data. Book is the name of the structure and also called ‘STRUCTURE TAG’.
  • 8. title author pages price Array of 20 characters Array of 15 characters integer float
  • 9. Declaring structure variable After defining structure format we can declare variable of data type. Structure variable declaration is similar to the declaration of variables of any other data type. It includes the following element. The keyword struct. Structure big-name List of variable names separated by commas. List of variable names separated by commas. Terminating semicolon (;) Eg: the statement Struct book a,b,c; Declare a,b,c as variables of type struct book. Each one of these variables has 4 members as specified in the definition complete declaration
  • 10. 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. Accessing structure Members i.e. book1.price Is the variable represnting the price of book1 and can be treated like any other ordinary variable.
  • 11. Here is how we would assign values to members of book1: strcpy(book1.title, “COMPUTER”); strcpy(book1.author, “XYZ”); the strcpy(book1.author, “XYZ”); book1.pages=250; book1.price=29.99; We can also use scanf to give the values through keyboard.