SlideShare a Scribd company logo
Established as per the Section 2(f) of the UGC Act, 1956
Approved by AICTE, COA and BCI, New Delhi
Structures in C Programming
N i m r i t a K o u l
n i m r i t a k o u l @ r e v a . e d u . i n
OUTLINE
• Quick Recap
• Structure Type
• Definition & Declaration
• Member Initialization and Access
• Nested Structures
• Arrays of Structures
• Union
• typedef
• What Next?
RECAP - C ROCKS. EVEN TODAY!!
Image Source: https://www.edureka.co/blog/c-programming-tutorial/
PROGRAM
PROCEDURE DATA
ALGORITHM + DATA STRUCTURE = PROGRAM
TYPICAL CONSTITUENTS OF A C PROGRAM
THE PROCESS OF WRITING A C PROGRAM
Source: https://www3.ntu.edu.sg/home/ehchua/programming/cpp/c0_Introduction.html
CONSTRUCTS OF C LANGUAGE
C DATA TYPES
Image Source: https://www.edureka.co/blog/c-programming-tutorial/
C DATA
TYPES
C DATATYPES
Enumerated
types
void
Derived Types –
• Pointers
• Arrays
• Functions
• Structures
• Unions
• Basic Types – Integer types, floating
point types
• Integer - Char, unsigned char, int,
unsigned int, short, unsigned short, long,
unsigned long
• Floating types -Float, double, long
double
WHY DO WE NEED STRUCTURE DATA TYPE?
CARS IN MY GARAGE AND THEIR SPECIFICATIONS
Credits: https://www.youtube.com/watch?v=zmRxC7gYw-g
ALL DATA ABOUTCAR-1 I NEED TO STORE -
ANOTHER CAR
CREATING TOO MANY VARIABLES?
CONSIDERING ARRAY?
SO WHAT TO DO?
WHAT IF WE CAN DEFINE OUR OWN DATA
TYPE THAT CAN ACCOMMODATE INDIVIDUAL
PIECES OF INFORMATION OF DIFFERENT DATA
TYPES!!!
STRUCTURE IS THE WAY TO GO.
STRUCTURE IS ONE
STOP SOLUTION.
DEFINITION
1. A structure is a namedcollectionof dataitems of different datatypes.
2. Eachelement or member orfield withinthe struct are accessed by nameinstead of aninteger index.
3. Structs are very powerful for bundling together data items that collectively describe a thing, or are in some
other wayrelated to eachother.
STRUCTURES
Name of Structure
Member 1 Member 2
Member 3 Member 4
Member 5 Member 5 Member 5 Member 5
STRUCTURE
EXAMPLES
1. Studentrecord: student id, name, major, gender, start year, …
2. Bank account: account number, name, currency, balance, …
3. Address book: name, address, telephone number, …
C NOTATION
1. A structure inClanguageis defined withthekeyword‘struct’
2. Individualcomponents ofa struct type are called members(or fields).
3. Members canbe ofdifferent types (simple,array or struct).
4. A struct is namedas a wholewhileindividualmembers arenamedusing field identifiers.
5. Complexdata structures canbeformed bydefiningarrays of structs.
GENERAL SYNTAX FOR DECLARING A STRUCTURE
DEFINITION
1. Definition of a structure:
struct <struct-type>{
<type> <identifier_list>;
<type> <identifier_list>;
...
} ;
Example:
struct Date {
int day;
int month;
int year;
} ;
Each identifier
defines a member
of the structure.
The “Date” structure
has 3 members,
day, month & year.
struct examples
• Example:
struct StudentInfo{
int Id;
int age;
char Gender;
double CGA;
};
• Example:
struct StudentGrade{
char Name[15];
char Course[9];
int Lab[5];
int Homework[3];
int Exam[2];
};
The “StudentGrade”
structure has 5
members of
different array types.
The “StudentInfo”
structure has 4 members
of different types.
struct basics
• Declaration of a variable of struct type:
<struct-type> <identifier_list>;
StudentRecord Student1, Student2;
Student1 Student2
Name
Id Gender
Dept
Name
Id Gender
Dept
struct StudentRecord{
char Name[15];
int Id;
char Dept[5];
char Gender;
};
struct examples
• Example:
struct BankAccount{
char Name[15];
int AcountNo[10];
double balance;
Date Birthday;
};
The “BankAcount”
structure has simple,
array and structure
types as members.
27
Nimrita
12345 F
CSE
DOT OPERATOR FOR ACCESS
• The members of a struct type variable are accessed
with the dot (.) operator:
<struct-variable>.<member_name>;
• Example:
strcpy(Student1.Name, “Nimrita");
Student1.Id = 12345;
strcpy(Student1.Dept, “CSE");
Student1.gender = ‘F';
printf("The student is “);
switch (Student1.gender){
case 'F': printf("Ms. “); break;
case 'M': printf(“Mr. “); break;
}
printf(Student1.Name);
Student1
Name
Id Gender
Dept
OH YES!! LETS REVISIT MY GARAGE!
ACCESSING MEMBERS OF MY CARS
MEMORY ALLOCATED TO A STRUCTURE
STRUCUTRE PADDING
MEMORY REQUIRED BY A STRUCTURE
a b c c c c Memory Arrangement
2 bytes padding
CHANGE IN ORDER OF MEMBERS CHANGES THE MEMORY REQUIRED BY
STRUCTURE VARIABLE
a b b b b c
NESTED STRUCTURE IN C: STRUCT INSIDE ANOTHER STRUCT
You can use a structure inside another structure.
Inner structure is called a Nested Structure.
ANY LEVEL OF NESTING IS POSSIBLE
Nested structures
• We can nest structures inside structures.
• struct line{
point p1, p2;
};
line L;
(L.p1.x, L.p1.y)
(L.p2.x, L.p2.y)
line
p1 p2
x y x y
Nested structures
• Examples:
struct point{
double x, y;
};
point P;
struct line{
point p1, p2;
};
line L;
struct triangle{
point p1, p2, p3;
};
triangle T;
(P.x, P.y)
(L.p1.x, L.p1.y)
(L.p2.x, L.p2.y)
(T.p2.x, T.p2.y)
(T.p1.x, T.p1.y)
(T.p3.x, T.p3.y)
Nested structures
point P;
line L;
triangle T;
P.x = 4;
P.y = 11;
(4, 11)
(2, 7)
(10, 9)
(6, 5)
(2, 0)
(8, 3)
L.p1.x = 2;
L.p1.y = 7;
L.p2.x = 10;
L.p2.y = 9;
T.p1.x = 2;
T.p1.y = 0;
T.p2.x = 6;
T.p2.y = 5;
T.p3.x = 8;
T.p3.y = 3;
Nirmtia
12345 F
CSE
struct-to-struct assignment
• The values contained in one struct type variable can
be assigned to another variable of the same struct
type.
• Example:
strcpy(Student1.Name, Nimrita");
Student1.Id = 12345;
strcpy(Student1.Dept, "CSE");
Student1.gender = ‘F';
Student2 = Student1;
Student1
Nimrita
12345 F
CSEStudent2
PASSING STRUCTURES AS PARAMETERS TO FUNCTIONS
• Structs can be passed to and from
functions just like any basic data
types.
• Individual structs are always passed
by value, even if they contain arrays.
• The struct definition must be
known to both the calling and
called functions, which means it
is must be defined globally.
• However the actual
struct variables should still be
declared locally, just like any
other variables.• Arrays of structs are passed by
pointer / address.
Structure Definition
Main Function
Function Definition
ARRAY OF STRUCTURES
Array of structures is a collection of
structure variables of same type.
ARRAYS OF STRUCTURES
• An ordinary array: One type of data
• An array of structs: Multiple types of data in each array
element.
0 1 2 … 98 99
0 1 2 … 98 99
ARRAYS OF STRUCTURES
• Example:
StudentRecord Class[100];
strcpy(Class[98].Name, “Nimrita");
Class[98].Id = 12345;
strcpy(Class[98].Dept, "CSE");
Class[98].gender = ‘F';
Class[0] = Class[98];
. . .
0 1 2 … 98 99
Nimrita
12345 F
CSE
TWO WAYS TO DECLARE AN ARRAY OF STRUCTURES
EXAMPLE OF ARRAY OF STRUCTURES
ARRAYS INSIDE STRUCTURES
• We can use arrays inside structures.
• Example:
struct square{
point vertex[4];
};
square Sq;
(4, 3) (10, 3)
(4, 1) (10, 1)
x y x y x y x y
ARRAY VS STRUCTURE
UNION
• A union like a structure is a PROGRAMMER DEFINED
data type.
• It can hold heterogeneous data types in same memory
location.
• You can define a union with many members, but only
one member can contain a value at any given time.
STR VS UNION MEMORYREQUIREMENT
ACCESSING MEMBERS OF UNION
To access any member of a union,
weuse the memberaccessoperator (.).
TYPEDEF
1. Typedef is a keyword used to define your own identifiers that can be used in place of other type specifiers
such as int, float,anddouble.
2. Typedef creates synonyms for the datatypes or combinationsofdata types they represent.
USE OF TYPEDEF IN STRUCTURE
• A typedef cansimplify the declarationfor a structure.
• Itmakes the code short andimproves readability.
• Itis likeanaliasof struct.
TYPEDEF SYNTAX
TYPEDEF
LIMITATIONS OF STRUCTURES
•No Data Hiding
•No Functions inside Structure
•No Static Members
•No Access Modifiers
•No Constructors
What can you do with knowledge of
C programming?
APPLICATIONS OF C PROGRAMMING
Source: www.daataflair.com
WHAT CAN YOU EASILY BUILD WITH C?
1.OperatingSystems
2.LanguageCompilers
3.Assemblers
4.TextEditors
5.PrintSpoolers
6.NetworkDrivers
7.ModernPrograms
8.DataBases
9.LanguageInterpreters
10.Utilities
Interpreted languages
likePython,Ruby,and PHP have their
primary implementations written in
C.
OPPORTUNITIES AT SCHOOL OF CIT, REVA UNIVERSITY
• B.Tech(CSE)
• B.Tech(CS & IT)
• B.Tech(AI & ML)
• B.Tech(ISE)
• M.Tech( CSE)
• M.Tech (DECC)
• Hackathons
• WorkshopsandSkill
• Development Programs
• International Internships and
Project Expos
Latest Industry Oriented Curriculum -
• ProgrammingTechnologies -Cprogramming,Python
Programming,
Java Programming,R Programming etc.
• Web Technologies – PHP,Perl, Java Script, NodeJS,
Angular JSetc.
• Machine Learning, Deep Learning,
Blockchain,CloudComputing,Mobile
Application Development, DevOps,
Wireless and Sensor Networks
And manymore…
REFERENCES
• https://www.youtube.com/watch?v=zmRxC7gYw-g
• https://www.tutorialspoint.com/cprogramming/c_unions.htm#:~:text=A%20union%20is%20a%20special,memory%20location%20fo
r%20multiple%2Dpurpose.
• https://www.programiz.com/c-programming/examples/information-structure-array
• https://fresh2refresh.com/c-programming/c-structures/
• https://study.com/academy/lesson/practical-application-for-c-programming-structures-unions.html
• http://www.c4learn.com/c-programming/c-structure-applications/
PROGRAMS
THANK YOU

More Related Content

What's hot

Data types in c++
Data types in c++Data types in c++
Data types in c++
Venkata.Manish Reddy
 
البرمجة الهدفية بلغة جافا - مصفوفة الكائنات
البرمجة الهدفية  بلغة جافا - مصفوفة الكائناتالبرمجة الهدفية  بلغة جافا - مصفوفة الكائنات
البرمجة الهدفية بلغة جافا - مصفوفة الكائنات
Mahmoud Alfarra
 
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
Mahmoud Alfarra
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
Abou Bakr Ashraf
 
البرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكالالبرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكال
Mahmoud Alfarra
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
Mufaddal Nullwala
 
Visula C# Programming Lecture 8
Visula C# Programming Lecture 8Visula C# Programming Lecture 8
Visula C# Programming Lecture 8
Abou Bakr Ashraf
 
Basic c#
Basic c#Basic c#
Basic c#
kishore4268
 
(4) c sharp introduction_object_orientation_part_i
(4) c sharp introduction_object_orientation_part_i(4) c sharp introduction_object_orientation_part_i
(4) c sharp introduction_object_orientation_part_i
Nico Ludwig
 
14 Defining Classes
14 Defining Classes14 Defining Classes
14 Defining Classes
Intro C# Book
 
Chapter2 array of objects
Chapter2 array of objectsChapter2 array of objects
Chapter2 array of objects
Mahmoud Alfarra
 
Oop l3n
Oop l3nOop l3n
Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2
Mahmoud Alfarra
 
Pi j2.2 classes
Pi j2.2 classesPi j2.2 classes
Pi j2.2 classes
mcollison
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
Intro C# Book
 
Data oriented design
Data oriented designData oriented design
Data oriented design
Max Klyga
 
Java 2 chapter 10 - basic oop in java
Java 2   chapter 10 - basic oop in javaJava 2   chapter 10 - basic oop in java
Java 2 chapter 10 - basic oop in java
let's go to study
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend class
Abhishek Wadhwa
 
Csharp_mahesh
Csharp_maheshCsharp_mahesh
Csharp_mahesh
Ananthu Mahesh
 
What can scala puzzlers teach us
What can scala puzzlers teach usWhat can scala puzzlers teach us
What can scala puzzlers teach us
Daniel Sobral
 

What's hot (20)

Data types in c++
Data types in c++Data types in c++
Data types in c++
 
البرمجة الهدفية بلغة جافا - مصفوفة الكائنات
البرمجة الهدفية  بلغة جافا - مصفوفة الكائناتالبرمجة الهدفية  بلغة جافا - مصفوفة الكائنات
البرمجة الهدفية بلغة جافا - مصفوفة الكائنات
 
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
البرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكالالبرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكال
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Visula C# Programming Lecture 8
Visula C# Programming Lecture 8Visula C# Programming Lecture 8
Visula C# Programming Lecture 8
 
Basic c#
Basic c#Basic c#
Basic c#
 
(4) c sharp introduction_object_orientation_part_i
(4) c sharp introduction_object_orientation_part_i(4) c sharp introduction_object_orientation_part_i
(4) c sharp introduction_object_orientation_part_i
 
14 Defining Classes
14 Defining Classes14 Defining Classes
14 Defining Classes
 
Chapter2 array of objects
Chapter2 array of objectsChapter2 array of objects
Chapter2 array of objects
 
Oop l3n
Oop l3nOop l3n
Oop l3n
 
Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2
 
Pi j2.2 classes
Pi j2.2 classesPi j2.2 classes
Pi j2.2 classes
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
Data oriented design
Data oriented designData oriented design
Data oriented design
 
Java 2 chapter 10 - basic oop in java
Java 2   chapter 10 - basic oop in javaJava 2   chapter 10 - basic oop in java
Java 2 chapter 10 - basic oop in java
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend class
 
Csharp_mahesh
Csharp_maheshCsharp_mahesh
Csharp_mahesh
 
What can scala puzzlers teach us
What can scala puzzlers teach usWhat can scala puzzlers teach us
What can scala puzzlers teach us
 

Similar to Structures in C

Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
babuk110
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7
sumitbardhan
 
Chapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptxChapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptx
Abhishekkumarsingh630054
 
CP Handout#10
CP Handout#10CP Handout#10
CP Handout#10
trupti1976
 
User defined data types.pptx
User defined data types.pptxUser defined data types.pptx
User defined data types.pptx
Ananthi Palanisamy
 
Structure & union
Structure & unionStructure & union
Structure & union
lalithambiga kamaraj
 
structure1.pdf
structure1.pdfstructure1.pdf
structure1.pdf
AbhimanyuKumarYadav3
 
Structures and Pointers
Structures and PointersStructures and Pointers
Structures and Pointers
Prabu U
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
psaravanan1985
 
Structures
StructuresStructures
Structures
selvapon
 
Structure in C
Structure in CStructure in C
Structure in C
Kamal Acharya
 
1. structure
1. structure1. structure
1. structure
hasan Mohammad
 
Structures
StructuresStructures
Structures
arshpreetkaur07
 
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
 
Ocs752 unit 5
Ocs752   unit 5Ocs752   unit 5
Ocs752 unit 5
mgrameshmail
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptx
GebruGetachew2
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
kavitham66441
 
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
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
Tanmay Modi
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 

Similar to Structures in C (20)

Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7
 
Chapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptxChapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptx
 
CP Handout#10
CP Handout#10CP Handout#10
CP Handout#10
 
User defined data types.pptx
User defined data types.pptxUser defined data types.pptx
User defined data types.pptx
 
Structure & union
Structure & unionStructure & union
Structure & union
 
structure1.pdf
structure1.pdfstructure1.pdf
structure1.pdf
 
Structures and Pointers
Structures and PointersStructures and Pointers
Structures and Pointers
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
 
Structures
StructuresStructures
Structures
 
Structure in C
Structure in CStructure in C
Structure in C
 
1. structure
1. structure1. structure
1. structure
 
Structures
StructuresStructures
Structures
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C Programming
 
Ocs752 unit 5
Ocs752   unit 5Ocs752   unit 5
Ocs752 unit 5
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptx
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
 
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
 
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
 

More from Nimrita Koul

Tools for research plotting
Tools for research plottingTools for research plotting
Tools for research plotting
Nimrita Koul
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language Processing
Nimrita Koul
 
Deeplearning
Deeplearning Deeplearning
Deeplearning
Nimrita Koul
 
Templates and Exception Handling in C++
Templates and Exception Handling in C++Templates and Exception Handling in C++
Templates and Exception Handling in C++
Nimrita Koul
 
Shorter bioinformatics
Shorter bioinformaticsShorter bioinformatics
Shorter bioinformatics
Nimrita Koul
 
Linear regression analysis
Linear regression analysisLinear regression analysis
Linear regression analysis
Nimrita Koul
 
Nimrita deep learning
Nimrita deep learningNimrita deep learning
Nimrita deep learning
Nimrita Koul
 
Nimrita koul Machine Learning
Nimrita koul  Machine LearningNimrita koul  Machine Learning
Nimrita koul Machine Learning
Nimrita Koul
 
Hands on data science with r.pptx
Hands  on data science with r.pptxHands  on data science with r.pptx
Hands on data science with r.pptx
Nimrita Koul
 
Python Traning presentation
Python Traning presentationPython Traning presentation
Python Traning presentation
Nimrita Koul
 

More from Nimrita Koul (10)

Tools for research plotting
Tools for research plottingTools for research plotting
Tools for research plotting
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language Processing
 
Deeplearning
Deeplearning Deeplearning
Deeplearning
 
Templates and Exception Handling in C++
Templates and Exception Handling in C++Templates and Exception Handling in C++
Templates and Exception Handling in C++
 
Shorter bioinformatics
Shorter bioinformaticsShorter bioinformatics
Shorter bioinformatics
 
Linear regression analysis
Linear regression analysisLinear regression analysis
Linear regression analysis
 
Nimrita deep learning
Nimrita deep learningNimrita deep learning
Nimrita deep learning
 
Nimrita koul Machine Learning
Nimrita koul  Machine LearningNimrita koul  Machine Learning
Nimrita koul Machine Learning
 
Hands on data science with r.pptx
Hands  on data science with r.pptxHands  on data science with r.pptx
Hands on data science with r.pptx
 
Python Traning presentation
Python Traning presentationPython Traning presentation
Python Traning presentation
 

Recently uploaded

Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
Madan Karki
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
architagupta876
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 

Recently uploaded (20)

Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 

Structures in C

  • 1. Established as per the Section 2(f) of the UGC Act, 1956 Approved by AICTE, COA and BCI, New Delhi Structures in C Programming N i m r i t a K o u l n i m r i t a k o u l @ r e v a . e d u . i n
  • 2. OUTLINE • Quick Recap • Structure Type • Definition & Declaration • Member Initialization and Access • Nested Structures • Arrays of Structures • Union • typedef • What Next?
  • 3. RECAP - C ROCKS. EVEN TODAY!! Image Source: https://www.edureka.co/blog/c-programming-tutorial/
  • 4. PROGRAM PROCEDURE DATA ALGORITHM + DATA STRUCTURE = PROGRAM
  • 6. THE PROCESS OF WRITING A C PROGRAM Source: https://www3.ntu.edu.sg/home/ehchua/programming/cpp/c0_Introduction.html
  • 7. CONSTRUCTS OF C LANGUAGE
  • 8. C DATA TYPES Image Source: https://www.edureka.co/blog/c-programming-tutorial/ C DATA TYPES
  • 9. C DATATYPES Enumerated types void Derived Types – • Pointers • Arrays • Functions • Structures • Unions • Basic Types – Integer types, floating point types • Integer - Char, unsigned char, int, unsigned int, short, unsigned short, long, unsigned long • Floating types -Float, double, long double
  • 10. WHY DO WE NEED STRUCTURE DATA TYPE?
  • 11. CARS IN MY GARAGE AND THEIR SPECIFICATIONS Credits: https://www.youtube.com/watch?v=zmRxC7gYw-g
  • 12. ALL DATA ABOUTCAR-1 I NEED TO STORE -
  • 14. CREATING TOO MANY VARIABLES?
  • 16. SO WHAT TO DO? WHAT IF WE CAN DEFINE OUR OWN DATA TYPE THAT CAN ACCOMMODATE INDIVIDUAL PIECES OF INFORMATION OF DIFFERENT DATA TYPES!!!
  • 17. STRUCTURE IS THE WAY TO GO. STRUCTURE IS ONE STOP SOLUTION.
  • 18. DEFINITION 1. A structure is a namedcollectionof dataitems of different datatypes. 2. Eachelement or member orfield withinthe struct are accessed by nameinstead of aninteger index. 3. Structs are very powerful for bundling together data items that collectively describe a thing, or are in some other wayrelated to eachother.
  • 19. STRUCTURES Name of Structure Member 1 Member 2 Member 3 Member 4 Member 5 Member 5 Member 5 Member 5 STRUCTURE
  • 20. EXAMPLES 1. Studentrecord: student id, name, major, gender, start year, … 2. Bank account: account number, name, currency, balance, … 3. Address book: name, address, telephone number, …
  • 21. C NOTATION 1. A structure inClanguageis defined withthekeyword‘struct’ 2. Individualcomponents ofa struct type are called members(or fields). 3. Members canbe ofdifferent types (simple,array or struct). 4. A struct is namedas a wholewhileindividualmembers arenamedusing field identifiers. 5. Complexdata structures canbeformed bydefiningarrays of structs.
  • 22. GENERAL SYNTAX FOR DECLARING A STRUCTURE
  • 23. DEFINITION 1. Definition of a structure: struct <struct-type>{ <type> <identifier_list>; <type> <identifier_list>; ... } ; Example: struct Date { int day; int month; int year; } ; Each identifier defines a member of the structure. The “Date” structure has 3 members, day, month & year.
  • 24. struct examples • Example: struct StudentInfo{ int Id; int age; char Gender; double CGA; }; • Example: struct StudentGrade{ char Name[15]; char Course[9]; int Lab[5]; int Homework[3]; int Exam[2]; }; The “StudentGrade” structure has 5 members of different array types. The “StudentInfo” structure has 4 members of different types.
  • 25. struct basics • Declaration of a variable of struct type: <struct-type> <identifier_list>; StudentRecord Student1, Student2; Student1 Student2 Name Id Gender Dept Name Id Gender Dept struct StudentRecord{ char Name[15]; int Id; char Dept[5]; char Gender; };
  • 26. struct examples • Example: struct BankAccount{ char Name[15]; int AcountNo[10]; double balance; Date Birthday; }; The “BankAcount” structure has simple, array and structure types as members.
  • 27. 27 Nimrita 12345 F CSE DOT OPERATOR FOR ACCESS • The members of a struct type variable are accessed with the dot (.) operator: <struct-variable>.<member_name>; • Example: strcpy(Student1.Name, “Nimrita"); Student1.Id = 12345; strcpy(Student1.Dept, “CSE"); Student1.gender = ‘F'; printf("The student is “); switch (Student1.gender){ case 'F': printf("Ms. “); break; case 'M': printf(“Mr. “); break; } printf(Student1.Name); Student1 Name Id Gender Dept
  • 28. OH YES!! LETS REVISIT MY GARAGE!
  • 30. MEMORY ALLOCATED TO A STRUCTURE
  • 32. MEMORY REQUIRED BY A STRUCTURE a b c c c c Memory Arrangement 2 bytes padding
  • 33. CHANGE IN ORDER OF MEMBERS CHANGES THE MEMORY REQUIRED BY STRUCTURE VARIABLE a b b b b c
  • 34. NESTED STRUCTURE IN C: STRUCT INSIDE ANOTHER STRUCT You can use a structure inside another structure. Inner structure is called a Nested Structure.
  • 35. ANY LEVEL OF NESTING IS POSSIBLE
  • 36. Nested structures • We can nest structures inside structures. • struct line{ point p1, p2; }; line L; (L.p1.x, L.p1.y) (L.p2.x, L.p2.y) line p1 p2 x y x y
  • 37. Nested structures • Examples: struct point{ double x, y; }; point P; struct line{ point p1, p2; }; line L; struct triangle{ point p1, p2, p3; }; triangle T; (P.x, P.y) (L.p1.x, L.p1.y) (L.p2.x, L.p2.y) (T.p2.x, T.p2.y) (T.p1.x, T.p1.y) (T.p3.x, T.p3.y)
  • 38. Nested structures point P; line L; triangle T; P.x = 4; P.y = 11; (4, 11) (2, 7) (10, 9) (6, 5) (2, 0) (8, 3) L.p1.x = 2; L.p1.y = 7; L.p2.x = 10; L.p2.y = 9; T.p1.x = 2; T.p1.y = 0; T.p2.x = 6; T.p2.y = 5; T.p3.x = 8; T.p3.y = 3;
  • 39. Nirmtia 12345 F CSE struct-to-struct assignment • The values contained in one struct type variable can be assigned to another variable of the same struct type. • Example: strcpy(Student1.Name, Nimrita"); Student1.Id = 12345; strcpy(Student1.Dept, "CSE"); Student1.gender = ‘F'; Student2 = Student1; Student1 Nimrita 12345 F CSEStudent2
  • 40. PASSING STRUCTURES AS PARAMETERS TO FUNCTIONS • Structs can be passed to and from functions just like any basic data types. • Individual structs are always passed by value, even if they contain arrays. • The struct definition must be known to both the calling and called functions, which means it is must be defined globally. • However the actual struct variables should still be declared locally, just like any other variables.• Arrays of structs are passed by pointer / address.
  • 42. ARRAY OF STRUCTURES Array of structures is a collection of structure variables of same type.
  • 43. ARRAYS OF STRUCTURES • An ordinary array: One type of data • An array of structs: Multiple types of data in each array element. 0 1 2 … 98 99 0 1 2 … 98 99
  • 44.
  • 45. ARRAYS OF STRUCTURES • Example: StudentRecord Class[100]; strcpy(Class[98].Name, “Nimrita"); Class[98].Id = 12345; strcpy(Class[98].Dept, "CSE"); Class[98].gender = ‘F'; Class[0] = Class[98]; . . . 0 1 2 … 98 99 Nimrita 12345 F CSE
  • 46. TWO WAYS TO DECLARE AN ARRAY OF STRUCTURES
  • 47. EXAMPLE OF ARRAY OF STRUCTURES
  • 48. ARRAYS INSIDE STRUCTURES • We can use arrays inside structures. • Example: struct square{ point vertex[4]; }; square Sq; (4, 3) (10, 3) (4, 1) (10, 1) x y x y x y x y
  • 50. UNION • A union like a structure is a PROGRAMMER DEFINED data type. • It can hold heterogeneous data types in same memory location. • You can define a union with many members, but only one member can contain a value at any given time.
  • 51. STR VS UNION MEMORYREQUIREMENT
  • 52.
  • 53. ACCESSING MEMBERS OF UNION To access any member of a union, weuse the memberaccessoperator (.).
  • 54.
  • 55.
  • 56. TYPEDEF 1. Typedef is a keyword used to define your own identifiers that can be used in place of other type specifiers such as int, float,anddouble. 2. Typedef creates synonyms for the datatypes or combinationsofdata types they represent.
  • 57. USE OF TYPEDEF IN STRUCTURE • A typedef cansimplify the declarationfor a structure. • Itmakes the code short andimproves readability. • Itis likeanaliasof struct.
  • 60. LIMITATIONS OF STRUCTURES •No Data Hiding •No Functions inside Structure •No Static Members •No Access Modifiers •No Constructors
  • 61. What can you do with knowledge of C programming?
  • 62. APPLICATIONS OF C PROGRAMMING Source: www.daataflair.com
  • 63. WHAT CAN YOU EASILY BUILD WITH C? 1.OperatingSystems 2.LanguageCompilers 3.Assemblers 4.TextEditors 5.PrintSpoolers 6.NetworkDrivers 7.ModernPrograms 8.DataBases 9.LanguageInterpreters 10.Utilities Interpreted languages likePython,Ruby,and PHP have their primary implementations written in C.
  • 64. OPPORTUNITIES AT SCHOOL OF CIT, REVA UNIVERSITY • B.Tech(CSE) • B.Tech(CS & IT) • B.Tech(AI & ML) • B.Tech(ISE) • M.Tech( CSE) • M.Tech (DECC) • Hackathons • WorkshopsandSkill • Development Programs • International Internships and Project Expos Latest Industry Oriented Curriculum - • ProgrammingTechnologies -Cprogramming,Python Programming, Java Programming,R Programming etc. • Web Technologies – PHP,Perl, Java Script, NodeJS, Angular JSetc. • Machine Learning, Deep Learning, Blockchain,CloudComputing,Mobile Application Development, DevOps, Wireless and Sensor Networks And manymore…
  • 65.
  • 66. REFERENCES • https://www.youtube.com/watch?v=zmRxC7gYw-g • https://www.tutorialspoint.com/cprogramming/c_unions.htm#:~:text=A%20union%20is%20a%20special,memory%20location%20fo r%20multiple%2Dpurpose. • https://www.programiz.com/c-programming/examples/information-structure-array • https://fresh2refresh.com/c-programming/c-structures/ • https://study.com/academy/lesson/practical-application-for-c-programming-structures-unions.html • http://www.c4learn.com/c-programming/c-structure-applications/