0% found this document useful (0 votes)
3 views13 pages

Lecture 3.2.4 C Pointer To Structure

Pointer to Structure

Uploaded by

deepakshiraj299
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views13 pages

Lecture 3.2.4 C Pointer To Structure

Pointer to Structure

Uploaded by

deepakshiraj299
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

UNIVERSITY INSTITUTE OF ENGINEERING

DEPARTMENT- ACADEMIC UNITS


FIRST YEAR ENGINEERING PROGRAMMES
Subject Name : Introduction to Problem Solving
Subject Code: 24CSH-101

Structure: Structure and functions, Structures DISCOVER . LEARN . EMPOWER


and pointers
Introduction to
Problem Solving

Course Objectives

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. 2
Course
Outcomes
CO Course Outcome
Number

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 lan-


guage.
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 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

A structure can be passed to It won’t be available to other


Structure definition will be
any function from main functions unless it is passed to
available within the function
function or from any sub those functions by value or by
only.
function. address

Else, we have to declare


structure variable as global
We can also initialize the array
variable. That means, structure To access members of a
of structures using the same
variable should be declared structure using pointers, we use
syntax as that for initializing
outside the main function. So, the -> operator.
arrays.
this structure will be visible to
all the functions in a C program.

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?

2. Program to add two distances in inch-feet system(Passing structure).

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

You might also like