Lecture 3.2.4 C Pointer To Structure
Lecture 3.2.4 C Pointer To Structure
Course Objectives
CO5 Design and develop modular programs for real world problems us-
ing control structure and selection structure.
3
ASSESSMENT PATTERN
The performance of students is evaluated as follows:
Theory Practical
Continuous Internal As- Semester End Examina- Continuous Internal Semester End Exam-
Components sessment (CAE) tion (SEE) Assessment (CAE) ination (SEE)
Marks 40 60 60 40
Total Marks 100 100
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 { Output:
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
Summary
7
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:
1. Write a Program to demonstrate How to return multiple values from a function in C?
10
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:
5. https://fresh2refresh.com/c-programming/c-passing-struct-to-function/
6. https://www.geeksforgeeks.org/how-to-pass-or-return-a-structure-to-from-a-func
tion-in-c-c/
7. https://www.studytonight.com/c/pointers-to-structure-in-c.php
8. https://dev.to/mikkel250/structures-and-pointers-in-c-n6i
9. https://www.programiz.com/c-programming/c-structures-pointers
YouTube Links:
10. https://www.youtube.com/watch?v=4HC8X966Q5M 12
THANK YOU