SlideShare a Scribd company logo
Structure is a group of variables
of different types known by a
single name
Syntax for defining the structure
struct struct_name
{
data type var1;
data type var2;
.
.
};
Struct_name provides a name of
structure.
It is a user defined name.
Members of structure are written in
curly {} braces.
The structure definition is terminated
by semicolon (;) symbol.
Above definition declares a
structure named as student, having
6 member variables.
Rollno and Age are integers,
while name, city, address and sex
is a character type variable.
EXAMPLE : For the student, we can
write the structure as shown below
struct student
{
int rollno;
char name[25];
char address[30];
char city[15];
char sex;
int age;
};
ACCESSING STRUCTURE MEMBERS
We can access the individual members of a
structure using the dot(.) operator.The dot(.)
operator is called as structure member operator
because it connects the structure variable and its
member variable.
The syntax is:
struct_var.struct_member;
Where,struct_var is a variable of structure
type,while struct_member is a name of a
member variable of structure……
For example,for the struct student with s1 and s2 as
variables,
S1.rollno=5;
S1.age=20;
S2.rollno=7;
S2.age=21;
S1.sex=‘m’;
S2.sex=‘f’;
Above code assigns student s1 rollno=5,age=20 and
sex=‘m’ while for student s2 rollno=7,age=21 and
sex=‘f’.
>> Write a program to input and print following
details of student using structure-roll
number,name,address,city,sex and age……
#include<stdio.h>
#include<conio.h>
Void main()
{
struct student
{
Int rollno;
Char name[20];
Char address[30];
Char city[20];
Char sex;
Int age;
};
Struct student s1;
Clrscr();
Printf(“Give roll numbern”);
Scanf(“%d”,&s1.rollno);
fflush(stdin);
Printf(“Give namen”);
Gets(s1.name);
Printf(“give addressn”);
Gets(s1.address);
Printf(“Give cityn”);
Gets(s1.city);
Printf(“give sex n”)
Scanf(“%c”,&s1.sex);
Printf(“give agen”);
Scanf(“%d”,&s1.age);
Printf(“roll number=%d, name=%s,
Address=%sn”,s1.rollno,
S1.name,s1.address);
Printf(“city=%s, sex=%c,
age=%dn”,s1.city,s1.sex,s1.age);
}
OUTPUT:-
Give roll number 1
Give name Vansh
Give address University road
Give city Patan
Give sex m
Give age 3
Roll number=1,Name=vansh,Address=University
road,City=patan,sex=m,age=3
ARRAY OF STRUCTURES
suppose we want to store details of 10 students do instead if
declaring 50 new variables to store details of 10 students we
can declare an array of size 10 to store the details.
For example,
Struct student
{
int rollno;
char name[25];
char adress[30];
char city[15];
}
Struct students s[10];
A program to calculate average marks of N for
three different subjects
#include<stdio.h>
#include<conio.h>
struct stud_exam
{
char name[20];
int m1;
int m2;
int m3;
float avg;
}
Void main( )
{
struct stud_exam st[10];
int I,n;
clrscr();
printf(“hoe many students?n’);
Scanf(“%d”,&n”);
for (i=0;i<n;i++)
printf(“give name :”);
scanf(“%s”,st[i],name);
printf(“n give marks of sub 1,2 and 3 ;”0;
scanf(“%d%d%d”,&st[i].m1,&st[i].m2,&st[i].m3);
st[i].avg={st[i].m1+st[i].m2+st[i].m3}/3;
}
printf(“name subject1 subject2 subject3 averagen”);
for(i=0;i<n;i++)
printf(“%-10s %7d %7d %7d %7.2fn
”,st[i].name,st[i].m1,st[i].m2,st[i].m3,st[i].avg);
getch( );
}
STRUCTURE INTTIALIZATION
As applicabale to basic data types, we can
also initialize the structure variable at the
time of creation of variables.for our student
structure example,it can written as:
Struct student:
{
Int rollno;
Char name[25];
Char address[30];
Char city[15];
Char sex;
Int age;
char age;
);
.
.
Struct student s1 = { 1, “vansh”
“universityroad” , “patan”, “m”, 3};
Struct student s2 = { 2, “saniya”, “krishna nagar”,
“ahemdabad”, 4);
In above codes, the two lines
Struct student s1 = { 1, “vansh”, “universityroad”,
“patan”, ‘m’,3};
Struct student s2 = { 2, “saniya”, “krishna nagar”,
“ahemdabad”,4);
Initializes the structure variables s1 and s2 with the
values written in
{} brackets
• If all the values in initialization are not
supplied,then rest of the member variables
will be initialized to zero fornumbers and null
to strings.
for examole,
Student s1 = { 1, “vansh”};
Will initialize only the rollno and name,while
other variables are initialized to zero or null
whichever is applicable.
Program about domanstarte initialization of
structure members…..
# include <stdio.h>
# include <conio.h>
Struct book
{
Char title[25];
Char author[20];
Char publisher[20];
Int page;
Float price;
};
Void main()
{
Struct book bk = { “c pograming”,
“xyz”, “abc”,441,275};
Clrscr ();
Getch();
}
• Output
title = c pograming, author name =xyz
Publisher = abc ltd
Pages =441, price = 275.0
Nestead structures:
When the member variable of a
structure itself is a structure, it is
called as nesting of structure. The
structure which is nested inside
other structure must be declared as
a structure before the structure in
which it is nested.
Suppose we want to include the birth date in stead of
age in student structure, we can first define a
structure for date as shown.
struct date
{
int day;
int month;
int year;
};
struct student
{
int rollno;
char name[25];
char address[30];
char city[15];
char sex;
struct date bdate;
} ;
here, in the definition of student structure, last
member bdate itself is a structure of type data. The
data structure is declared as having three parts namely:
day, month and year.
struct student s1;
s1.bdate.year = 1995;
s1.bdate.month=1;
s1.bdate.day =1;
In above declaration of date and student, we
can declare variables of date as well as
student type.
But if the above definition is written as:
stuct student
{
int rollno;
char name[25];
char address[30];
char city[15];
char sex;
struct date
{
int day;
int month;
int year;
} bdate;
} ;
continued….
Then we can create variables of student type
only. We can not create variables of data type.
so, effectively date structure is not global data
type, but it becomes local to student data
type.
if we have declared the variable s1 as
Struct student s1;
Then we can access day by statement:
s1.bdate.day;
Basic of Structure,Structure members,Accessing Structure member,Nested Structure….

More Related Content

What's hot

Union in C programming
Union in C programmingUnion in C programming
Union in C programming
Kamal Acharya
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
Dhrumil Panchal
 
Strings in c
Strings in cStrings in c
Strings in c
vampugani
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
Appili Vamsi Krishna
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
sangrampatil81
 
structure and union
structure and unionstructure and union
structure and unionstudent
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
Acad
 
C programming - String
C programming - StringC programming - String
C programming - String
Achyut Devkota
 
Constructor and Destructor in c++
Constructor  and Destructor in c++Constructor  and Destructor in c++
Constructor and Destructor in c++
aleenaguen
 
Structure c
Structure cStructure c
Structure c
thirumalaikumar3
 
C string
C stringC string
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
topu93
 
Structures
StructuresStructures
Structures
archikabhatia
 
Types of function call
Types of function callTypes of function call
Types of function call
ArijitDhali
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
Smit Parikh
 
arrays of structures
arrays of structuresarrays of structures
arrays of structures
arushi bhatnagar
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++Fahim Adil
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
 
Data types
Data typesData types
Data types
Nokesh Prabhakar
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 

What's hot (20)

Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Strings in c
Strings in cStrings in c
Strings in c
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
 
structure and union
structure and unionstructure and union
structure and union
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
 
C programming - String
C programming - StringC programming - String
C programming - String
 
Constructor and Destructor in c++
Constructor  and Destructor in c++Constructor  and Destructor in c++
Constructor and Destructor in c++
 
Structure c
Structure cStructure c
Structure c
 
C string
C stringC string
C string
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Structures
StructuresStructures
Structures
 
Types of function call
Types of function callTypes of function call
Types of function call
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
 
arrays of structures
arrays of structuresarrays of structures
arrays of structures
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
 
Data types
Data typesData types
Data types
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 

Similar to Basic of Structure,Structure members,Accessing Structure member,Nested Structure….

Structures
StructuresStructures
Structures
DrJasmineBeulahG
 
STRUCTURES IN C PROGRAMMING
STRUCTURES IN C PROGRAMMING STRUCTURES IN C PROGRAMMING
STRUCTURES IN C PROGRAMMING
Gurwinderkaur45
 
C structure and union
C structure and unionC structure and union
C structure and union
Thesis Scientist Private Limited
 
structure.ppt
structure.pptstructure.ppt
structure.ppt
Sheik Mohideen
 
C structures
C structuresC structures
C structures
Md. Shafiuzzaman Hira
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
Krishna Nanda
 
C Language Unit-4
C Language Unit-4C Language Unit-4
C Language Unit-4
kasaragadda srinivasrao
 
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
 
Module 5-Structure and Union
Module 5-Structure and UnionModule 5-Structure and Union
Module 5-Structure and Union
nikshaikh786
 
03 structures
03 structures03 structures
03 structures
Rajan Gautam
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
Mehul Desai
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C Programming
Chandrakant Divate
 
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
 
1. structure
1. structure1. structure
1. structure
hasan Mohammad
 
CP Handout#10
CP Handout#10CP Handout#10
CP Handout#10
trupti1976
 
CA2_CYS101_31184422012_Arvind-Shukla.pptx
CA2_CYS101_31184422012_Arvind-Shukla.pptxCA2_CYS101_31184422012_Arvind-Shukla.pptx
CA2_CYS101_31184422012_Arvind-Shukla.pptx
ArvindShukla81
 

Similar to Basic of Structure,Structure members,Accessing Structure member,Nested Structure…. (20)

Structures
StructuresStructures
Structures
 
STRUCTURES IN C PROGRAMMING
STRUCTURES IN C PROGRAMMING STRUCTURES IN C PROGRAMMING
STRUCTURES IN C PROGRAMMING
 
C structure and union
C structure and unionC structure and union
C structure and union
 
structure.ppt
structure.pptstructure.ppt
structure.ppt
 
C structures
C structuresC structures
C structures
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
 
C Language Unit-4
C Language Unit-4C Language Unit-4
C Language Unit-4
 
Unit4
Unit4Unit4
Unit4
 
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
 
Module 5-Structure and Union
Module 5-Structure and UnionModule 5-Structure and Union
Module 5-Structure and Union
 
03 structures
03 structures03 structures
03 structures
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C Programming
 
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
 
1. structure
1. structure1. structure
1. structure
 
Chap 10(structure and unions)
Chap 10(structure and unions)Chap 10(structure and unions)
Chap 10(structure and unions)
 
CP Handout#10
CP Handout#10CP Handout#10
CP Handout#10
 
CA2_CYS101_31184422012_Arvind-Shukla.pptx
CA2_CYS101_31184422012_Arvind-Shukla.pptxCA2_CYS101_31184422012_Arvind-Shukla.pptx
CA2_CYS101_31184422012_Arvind-Shukla.pptx
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
 

More from Smit Shah

Flow chart & Program for CAAD of choke coil
Flow chart & Program for CAAD of choke coilFlow chart & Program for CAAD of choke coil
Flow chart & Program for CAAD of choke coil
Smit Shah
 
Line to Line & Double Line to Ground Fault On Power System
Line to Line & Double Line to Ground Fault On Power SystemLine to Line & Double Line to Ground Fault On Power System
Line to Line & Double Line to Ground Fault On Power System
Smit Shah
 
Finite difference method for charge calculation
Finite difference method for charge calculationFinite difference method for charge calculation
Finite difference method for charge calculation
Smit Shah
 
Parallel Inverter
Parallel InverterParallel Inverter
Parallel Inverter
Smit Shah
 
Dry Type Transformer
Dry  Type TransformerDry  Type Transformer
Dry Type Transformer
Smit Shah
 
Half wave control rectifier with RL load
Half wave control rectifier with RL loadHalf wave control rectifier with RL load
Half wave control rectifier with RL load
Smit Shah
 
Pipeline & Nonpipeline Processor
Pipeline & Nonpipeline ProcessorPipeline & Nonpipeline Processor
Pipeline & Nonpipeline Processor
Smit Shah
 
AC Supply system, Comparison Between AC-DC System, Advantage HV transmission
AC Supply system, Comparison Between AC-DC System, Advantage HV transmissionAC Supply system, Comparison Between AC-DC System, Advantage HV transmission
AC Supply system, Comparison Between AC-DC System, Advantage HV transmission
Smit Shah
 
Lap winding for AC machine
Lap winding for AC machineLap winding for AC machine
Lap winding for AC machine
Smit Shah
 
Hacking & Attack vector
Hacking & Attack vectorHacking & Attack vector
Hacking & Attack vector
Smit Shah
 
Block Reduction Method
Block Reduction MethodBlock Reduction Method
Block Reduction Method
Smit Shah
 
Frequency spectrum of periodic signal..
Frequency spectrum of periodic signal..    Frequency spectrum of periodic signal..
Frequency spectrum of periodic signal..
Smit Shah
 
Divergence Theorem & Maxwell’s First Equation
Divergence  Theorem & Maxwell’s  First EquationDivergence  Theorem & Maxwell’s  First Equation
Divergence Theorem & Maxwell’s First Equation
Smit Shah
 
Solar Dryer & Solar Distillation
Solar Dryer & Solar DistillationSolar Dryer & Solar Distillation
Solar Dryer & Solar Distillation
Smit Shah
 
Parallel Adder and Subtractor
Parallel Adder and SubtractorParallel Adder and Subtractor
Parallel Adder and Subtractor
Smit Shah
 
Type of Single phase induction Motor
Type of Single phase induction MotorType of Single phase induction Motor
Type of Single phase induction Motor
Smit Shah
 
Fluid Properties Density , Viscosity , Surface tension & Capillarity
Fluid Properties Density , Viscosity , Surface tension & Capillarity Fluid Properties Density , Viscosity , Surface tension & Capillarity
Fluid Properties Density , Viscosity , Surface tension & Capillarity
Smit Shah
 
Application of different types of dc generator and dc motor
Application of different types of dc generator and dc motorApplication of different types of dc generator and dc motor
Application of different types of dc generator and dc motor
Smit Shah
 
Initial Conditions
Initial ConditionsInitial Conditions
Initial Conditions
Smit Shah
 
Laplace Transform And Its Applications
Laplace Transform And Its ApplicationsLaplace Transform And Its Applications
Laplace Transform And Its Applications
Smit Shah
 

More from Smit Shah (20)

Flow chart & Program for CAAD of choke coil
Flow chart & Program for CAAD of choke coilFlow chart & Program for CAAD of choke coil
Flow chart & Program for CAAD of choke coil
 
Line to Line & Double Line to Ground Fault On Power System
Line to Line & Double Line to Ground Fault On Power SystemLine to Line & Double Line to Ground Fault On Power System
Line to Line & Double Line to Ground Fault On Power System
 
Finite difference method for charge calculation
Finite difference method for charge calculationFinite difference method for charge calculation
Finite difference method for charge calculation
 
Parallel Inverter
Parallel InverterParallel Inverter
Parallel Inverter
 
Dry Type Transformer
Dry  Type TransformerDry  Type Transformer
Dry Type Transformer
 
Half wave control rectifier with RL load
Half wave control rectifier with RL loadHalf wave control rectifier with RL load
Half wave control rectifier with RL load
 
Pipeline & Nonpipeline Processor
Pipeline & Nonpipeline ProcessorPipeline & Nonpipeline Processor
Pipeline & Nonpipeline Processor
 
AC Supply system, Comparison Between AC-DC System, Advantage HV transmission
AC Supply system, Comparison Between AC-DC System, Advantage HV transmissionAC Supply system, Comparison Between AC-DC System, Advantage HV transmission
AC Supply system, Comparison Between AC-DC System, Advantage HV transmission
 
Lap winding for AC machine
Lap winding for AC machineLap winding for AC machine
Lap winding for AC machine
 
Hacking & Attack vector
Hacking & Attack vectorHacking & Attack vector
Hacking & Attack vector
 
Block Reduction Method
Block Reduction MethodBlock Reduction Method
Block Reduction Method
 
Frequency spectrum of periodic signal..
Frequency spectrum of periodic signal..    Frequency spectrum of periodic signal..
Frequency spectrum of periodic signal..
 
Divergence Theorem & Maxwell’s First Equation
Divergence  Theorem & Maxwell’s  First EquationDivergence  Theorem & Maxwell’s  First Equation
Divergence Theorem & Maxwell’s First Equation
 
Solar Dryer & Solar Distillation
Solar Dryer & Solar DistillationSolar Dryer & Solar Distillation
Solar Dryer & Solar Distillation
 
Parallel Adder and Subtractor
Parallel Adder and SubtractorParallel Adder and Subtractor
Parallel Adder and Subtractor
 
Type of Single phase induction Motor
Type of Single phase induction MotorType of Single phase induction Motor
Type of Single phase induction Motor
 
Fluid Properties Density , Viscosity , Surface tension & Capillarity
Fluid Properties Density , Viscosity , Surface tension & Capillarity Fluid Properties Density , Viscosity , Surface tension & Capillarity
Fluid Properties Density , Viscosity , Surface tension & Capillarity
 
Application of different types of dc generator and dc motor
Application of different types of dc generator and dc motorApplication of different types of dc generator and dc motor
Application of different types of dc generator and dc motor
 
Initial Conditions
Initial ConditionsInitial Conditions
Initial Conditions
 
Laplace Transform And Its Applications
Laplace Transform And Its ApplicationsLaplace Transform And Its Applications
Laplace Transform And Its Applications
 

Recently uploaded

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 

Recently uploaded (20)

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 

Basic of Structure,Structure members,Accessing Structure member,Nested Structure….

  • 1.
  • 2.
  • 3. Structure is a group of variables of different types known by a single name
  • 4. Syntax for defining the structure struct struct_name { data type var1; data type var2; . . };
  • 5. Struct_name provides a name of structure. It is a user defined name. Members of structure are written in curly {} braces. The structure definition is terminated by semicolon (;) symbol.
  • 6. Above definition declares a structure named as student, having 6 member variables. Rollno and Age are integers, while name, city, address and sex is a character type variable.
  • 7. EXAMPLE : For the student, we can write the structure as shown below struct student { int rollno; char name[25]; char address[30]; char city[15]; char sex; int age; };
  • 8. ACCESSING STRUCTURE MEMBERS We can access the individual members of a structure using the dot(.) operator.The dot(.) operator is called as structure member operator because it connects the structure variable and its member variable. The syntax is: struct_var.struct_member; Where,struct_var is a variable of structure type,while struct_member is a name of a member variable of structure……
  • 9. For example,for the struct student with s1 and s2 as variables, S1.rollno=5; S1.age=20; S2.rollno=7; S2.age=21; S1.sex=‘m’; S2.sex=‘f’; Above code assigns student s1 rollno=5,age=20 and sex=‘m’ while for student s2 rollno=7,age=21 and sex=‘f’.
  • 10. >> Write a program to input and print following details of student using structure-roll number,name,address,city,sex and age…… #include<stdio.h> #include<conio.h> Void main() { struct student { Int rollno; Char name[20]; Char address[30]; Char city[20]; Char sex; Int age; };
  • 11. Struct student s1; Clrscr(); Printf(“Give roll numbern”); Scanf(“%d”,&s1.rollno); fflush(stdin); Printf(“Give namen”); Gets(s1.name); Printf(“give addressn”); Gets(s1.address); Printf(“Give cityn”); Gets(s1.city); Printf(“give sex n”) Scanf(“%c”,&s1.sex); Printf(“give agen”); Scanf(“%d”,&s1.age); Printf(“roll number=%d, name=%s, Address=%sn”,s1.rollno, S1.name,s1.address);
  • 12. Printf(“city=%s, sex=%c, age=%dn”,s1.city,s1.sex,s1.age); } OUTPUT:- Give roll number 1 Give name Vansh Give address University road Give city Patan Give sex m Give age 3 Roll number=1,Name=vansh,Address=University road,City=patan,sex=m,age=3
  • 13. ARRAY OF STRUCTURES suppose we want to store details of 10 students do instead if declaring 50 new variables to store details of 10 students we can declare an array of size 10 to store the details. For example, Struct student { int rollno; char name[25]; char adress[30]; char city[15]; } Struct students s[10];
  • 14. A program to calculate average marks of N for three different subjects #include<stdio.h> #include<conio.h> struct stud_exam { char name[20]; int m1; int m2;
  • 15. int m3; float avg; } Void main( ) { struct stud_exam st[10]; int I,n; clrscr(); printf(“hoe many students?n’); Scanf(“%d”,&n”); for (i=0;i<n;i++) printf(“give name :”); scanf(“%s”,st[i],name); printf(“n give marks of sub 1,2 and 3 ;”0; scanf(“%d%d%d”,&st[i].m1,&st[i].m2,&st[i].m3); st[i].avg={st[i].m1+st[i].m2+st[i].m3}/3;
  • 16. } printf(“name subject1 subject2 subject3 averagen”); for(i=0;i<n;i++) printf(“%-10s %7d %7d %7d %7.2fn ”,st[i].name,st[i].m1,st[i].m2,st[i].m3,st[i].avg); getch( ); }
  • 17. STRUCTURE INTTIALIZATION As applicabale to basic data types, we can also initialize the structure variable at the time of creation of variables.for our student structure example,it can written as: Struct student: { Int rollno; Char name[25]; Char address[30]; Char city[15]; Char sex; Int age;
  • 18. char age; ); . . Struct student s1 = { 1, “vansh” “universityroad” , “patan”, “m”, 3}; Struct student s2 = { 2, “saniya”, “krishna nagar”, “ahemdabad”, 4); In above codes, the two lines Struct student s1 = { 1, “vansh”, “universityroad”, “patan”, ‘m’,3}; Struct student s2 = { 2, “saniya”, “krishna nagar”, “ahemdabad”,4); Initializes the structure variables s1 and s2 with the values written in {} brackets
  • 19. • If all the values in initialization are not supplied,then rest of the member variables will be initialized to zero fornumbers and null to strings. for examole, Student s1 = { 1, “vansh”}; Will initialize only the rollno and name,while other variables are initialized to zero or null whichever is applicable.
  • 20. Program about domanstarte initialization of structure members….. # include <stdio.h> # include <conio.h> Struct book { Char title[25]; Char author[20]; Char publisher[20]; Int page; Float price; }; Void main() { Struct book bk = { “c pograming”, “xyz”, “abc”,441,275}; Clrscr (); Getch(); }
  • 21. • Output title = c pograming, author name =xyz Publisher = abc ltd Pages =441, price = 275.0
  • 22. Nestead structures: When the member variable of a structure itself is a structure, it is called as nesting of structure. The structure which is nested inside other structure must be declared as a structure before the structure in which it is nested.
  • 23. Suppose we want to include the birth date in stead of age in student structure, we can first define a structure for date as shown. struct date { int day; int month; int year; }; struct student { int rollno; char name[25]; char address[30]; char city[15]; char sex; struct date bdate; } ;
  • 24. here, in the definition of student structure, last member bdate itself is a structure of type data. The data structure is declared as having three parts namely: day, month and year. struct student s1; s1.bdate.year = 1995; s1.bdate.month=1; s1.bdate.day =1; In above declaration of date and student, we can declare variables of date as well as student type.
  • 25. But if the above definition is written as: stuct student { int rollno; char name[25]; char address[30]; char city[15]; char sex; struct date { int day; int month; int year; } bdate; } ;
  • 26. continued…. Then we can create variables of student type only. We can not create variables of data type. so, effectively date structure is not global data type, but it becomes local to student data type. if we have declared the variable s1 as Struct student s1; Then we can access day by statement: s1.bdate.day;