SlideShare a Scribd company logo
1 of 13
DISCOVER . LEARN . EMPOWER
Structure: Structure and functions, Structures
and pointers
INSTITUTE - UIE
DEPARTMENT- ACADEMIC UNIT-2
Bachelor of Engineering (Computer Science & Engineering)
Subject Name: Introduction to Problem Solving
Code:23CSH-101
Introduction to
Problem Solving
Course Objectives
2
The course aims to provide exposure to problem-
solving through programming.
The course aims to raise the programming skills
of students via logic building capability.
With knowledge of C programming language,
students would be able to model real world
problems.
3
CO
Number
Course Outcome
CO1 Remember the concepts related to fundamentals of C language,
draw flowcharts and write algorithm/pseudocode.
CO2 Understand the way of execution and debug programs in C
language.
CO3 Apply various constructs, loops, functions to solve mathematical
and scientific problem.
CO4 Analyze the dynamic behavior of memory by the use of pointers.
CO5 Design and develop modular programs for real world problems
using control structure and selection structure.
Course Outcomes
Scheme of Evaluation
4
Structure and Pointers
• Pointer to structure: Pointer which stores address of structure is called as “Pointer to
Structure “.
• Explanation :
1. sptr is pointer to structure address.
2. -> and (*). both represents the same.
3. These operators are used to access data member of structure by using structure’s
pointer.
5
• Example: Program to create a structure and display the content using
pointer.
#include<stdio.h>
struct team {
char *name;
int members;
char captain[20];
}
t1 = {"India",11,"Dhoni"} , *sptr = &t1;
int main()
{
printf("nTeam : %s",(*sptr).name);
printf("nMemebers : %d",sptr->members);
printf("nCaptain : %s",(*sptr).captain);
return 0;
}
6
Output:
7
Summary
A structure can be passed to
any function from main
function or from any sub
function.
Structure definition will be
available within the function
only.
It won’t be available to other
functions unless it is passed to
those functions by value or by
address
Else, we have to declare
structure variable as global
variable. That means, structure
variable should be declared
outside the main function. So,
this structure will be visible to
all the functions in a C program.
To access members of a
structure using pointers, we use
the -> operator.
We can also initialize the array
of structures using the same
syntax as that for initializing
arrays.
Frequently Asked Questions
Q1 Write a Program to enter the employee Information & display the data passing Structures By Using
Pointers
Expected Output:
Enter the name of the Employee : John
Enter the Employee Id : 16
Enter Experience of the Employee : 3
---------Details List---------
Employee Name : ram
Employee Id : 16
Employee Experience : 3
Solution:
8
9
Assessment Questions:
10
1. Write a Program to demonstrate How to return multiple values from a function in C?
2. Program to add two distances in inch-feet system(Passing structure).
Discussion forum
PROBLEM:
Write a Program to add two complex numbers
Using (Passing struct by reference).
11
REFERENCES
Reference Books
1. Programming in C by Reema Thareja.
2. Programming in ANSI C by E. Balaguruswamy, Tata McGraw Hill.
3. Programming with C (Schaum's Outline Series) by Byron Gottfried Jitender
Chhabra, Tata McGraw Hill.
4. The C Programming Language by Brian W. Kernighan, Dennis Ritchie, Pearson
education.
Websites:
1. https://fresh2refresh.com/c-programming/c-passing-struct-to-function/
2. https://www.geeksforgeeks.org/how-to-pass-or-return-a-structure-to-from-a-
function-in-c-c/
3. https://www.studytonight.com/c/pointers-to-structure-in-c.php
4. https://dev.to/mikkel250/structures-and-pointers-in-c-n6i
5. https://www.programiz.com/c-programming/c-structures-pointers
YouTube Links:
1. https://www.youtube.com/watch?v=4HC8X966Q5M
2. https://www.youtube.com/watch?v=VF40lxbXR_0
12
THANK YOU

More Related Content

Similar to Lecture 3.2.4 C pointer to Structure.pptx

Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEMMansi Tyagi
 
IP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG ProgrammeIP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG ProgrammeSAFAD ISMAIL
 
Mit4021–%20 c# and .net
Mit4021–%20 c# and .netMit4021–%20 c# and .net
Mit4021–%20 c# and .netsmumbahelp
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptManivannan837728
 
Principles of object oriented programing
Principles of object oriented programingPrinciples of object oriented programing
Principles of object oriented programingAhammed Alamin
 
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...NicheTech Com. Solutions Pvt. Ltd.
 
object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxurvashipundir04
 
Bca1020 programming in c
Bca1020  programming in cBca1020  programming in c
Bca1020 programming in csmumbahelp
 
Fy secondsemester2016
Fy secondsemester2016Fy secondsemester2016
Fy secondsemester2016Ankit Dubey
 
Fy secondsemester2016
Fy secondsemester2016Fy secondsemester2016
Fy secondsemester2016Ankit Dubey
 
Fy secondsemester2016
Fy secondsemester2016Fy secondsemester2016
Fy secondsemester2016Ankit Dubey
 
Learn C# programming - Program Structure & Basic Syntax
Learn C# programming - Program Structure & Basic SyntaxLearn C# programming - Program Structure & Basic Syntax
Learn C# programming - Program Structure & Basic SyntaxEng Teong Cheah
 

Similar to Lecture 3.2.4 C pointer to Structure.pptx (20)

Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEM
 
IP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG ProgrammeIP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG Programme
 
Mit4021–%20 c# and .net
Mit4021–%20 c# and .netMit4021–%20 c# and .net
Mit4021–%20 c# and .net
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
 
Principles of object oriented programing
Principles of object oriented programingPrinciples of object oriented programing
Principles of object oriented programing
 
C programming
C programmingC programming
C programming
 
Cd lab manual
Cd lab manualCd lab manual
Cd lab manual
 
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
 
trial
trialtrial
trial
 
object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptx
 
DS functions-1.pptx
DS functions-1.pptxDS functions-1.pptx
DS functions-1.pptx
 
T2
T2T2
T2
 
Bca1020 programming in c
Bca1020  programming in cBca1020  programming in c
Bca1020 programming in c
 
Fy secondsemester2016
Fy secondsemester2016Fy secondsemester2016
Fy secondsemester2016
 
Fy secondsemester2016
Fy secondsemester2016Fy secondsemester2016
Fy secondsemester2016
 
Fy secondsemester2016
Fy secondsemester2016Fy secondsemester2016
Fy secondsemester2016
 
C# p3
C# p3C# p3
C# p3
 
c++ referesher 1.pdf
c++ referesher 1.pdfc++ referesher 1.pdf
c++ referesher 1.pdf
 
Learn C# programming - Program Structure & Basic Syntax
Learn C# programming - Program Structure & Basic SyntaxLearn C# programming - Program Structure & Basic Syntax
Learn C# programming - Program Structure & Basic Syntax
 
c#.pptx
c#.pptxc#.pptx
c#.pptx
 

Recently uploaded

Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 

Recently uploaded (20)

Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 

Lecture 3.2.4 C pointer to Structure.pptx

  • 1. DISCOVER . LEARN . EMPOWER Structure: Structure and functions, Structures and pointers INSTITUTE - UIE DEPARTMENT- ACADEMIC UNIT-2 Bachelor of Engineering (Computer Science & Engineering) Subject Name: Introduction to Problem Solving Code:23CSH-101
  • 2. Introduction to Problem Solving Course Objectives 2 The course aims to provide exposure to problem- solving through programming. The course aims to raise the programming skills of students via logic building capability. With knowledge of C programming language, students would be able to model real world problems.
  • 3. 3 CO Number Course Outcome CO1 Remember the concepts related to fundamentals of C language, draw flowcharts and write algorithm/pseudocode. CO2 Understand the way of execution and debug programs in C language. CO3 Apply various constructs, loops, functions to solve mathematical and scientific problem. CO4 Analyze the dynamic behavior of memory by the use of pointers. CO5 Design and develop modular programs for real world problems using control structure and selection structure. Course Outcomes
  • 5. Structure and Pointers • Pointer to structure: Pointer which stores address of structure is called as “Pointer to Structure “. • Explanation : 1. sptr is pointer to structure address. 2. -> and (*). both represents the same. 3. These operators are used to access data member of structure by using structure’s pointer. 5
  • 6. • Example: Program to create a structure and display the content using pointer. #include<stdio.h> struct team { char *name; int members; char captain[20]; } t1 = {"India",11,"Dhoni"} , *sptr = &t1; int main() { printf("nTeam : %s",(*sptr).name); printf("nMemebers : %d",sptr->members); printf("nCaptain : %s",(*sptr).captain); return 0; } 6 Output:
  • 7. 7 Summary A structure can be passed to any function from main function or from any sub function. Structure definition will be available within the function only. It won’t be available to other functions unless it is passed to those functions by value or by address Else, we have to declare structure variable as global variable. That means, structure variable should be declared outside the main function. So, this structure will be visible to all the functions in a C program. To access members of a structure using pointers, we use the -> operator. We can also initialize the array of structures using the same syntax as that for initializing arrays.
  • 8. Frequently Asked Questions Q1 Write a Program to enter the employee Information & display the data passing Structures By Using Pointers Expected Output: Enter the name of the Employee : John Enter the Employee Id : 16 Enter Experience of the Employee : 3 ---------Details List--------- Employee Name : ram Employee Id : 16 Employee Experience : 3 Solution: 8
  • 9. 9
  • 10. Assessment Questions: 10 1. Write a Program to demonstrate How to return multiple values from a function in C? 2. Program to add two distances in inch-feet system(Passing structure).
  • 11. Discussion forum PROBLEM: Write a Program to add two complex numbers Using (Passing struct by reference). 11
  • 12. REFERENCES Reference Books 1. Programming in C by Reema Thareja. 2. Programming in ANSI C by E. Balaguruswamy, Tata McGraw Hill. 3. Programming with C (Schaum's Outline Series) by Byron Gottfried Jitender Chhabra, Tata McGraw Hill. 4. The C Programming Language by Brian W. Kernighan, Dennis Ritchie, Pearson education. Websites: 1. https://fresh2refresh.com/c-programming/c-passing-struct-to-function/ 2. https://www.geeksforgeeks.org/how-to-pass-or-return-a-structure-to-from-a- function-in-c-c/ 3. https://www.studytonight.com/c/pointers-to-structure-in-c.php 4. https://dev.to/mikkel250/structures-and-pointers-in-c-n6i 5. https://www.programiz.com/c-programming/c-structures-pointers YouTube Links: 1. https://www.youtube.com/watch?v=4HC8X966Q5M 2. https://www.youtube.com/watch?v=VF40lxbXR_0 12