declare

C POGRAMMING - POINTERS TO STRUCTURES



Sharing buttons:

[Music]

hello friends welcome to our channel so

in this session let us have a look one

structures two pointers so in the

previous sessions we have seen the

definition of a structure so how to

define a structure in the program and

how could declare a structure variable

and how initialize the structure

variables and important thing is how to

access the members of a structure using

the structure variable so in this

session let us have a look on how to

access the members using the pointers so

first of all we have to create a

structure that means we have two

different structure and then we have to

declare a structure variable as well as

a pointer available and then we have to

initialize the pointer available with

the structure and by using these

pointers we have to access the members

of this structure so as we know the

point is concept here we will use two

operators that is Star and Amazon star

is a value operator and ampersand is

their error somewhere so here we have to

declare a pointer and initialize the

pointer with some variable so that means

here a pointer variable is a variable

which holds the address of another

variable that means first we are

creating what we are declaring a

variable and then we are declaring the

pointer variable and we are initializing

this pointer variable with another with

another video the same procedure will be

followed in the structures also so first

we have to define a structure then

declare a structure variable and then

declare a pointer variable and then

assign the address of a structure

variable with a pointer and now we have

to access the members

factor using this pointers see let us

see that so if we define the structure

start student let us take a tag and

student so in whole number character

name and then float a sandwich close and

create one structure movable here so we

can create a structure variable and the

definition itself or inside the main

function so we can create the structure

now this is the first part define a

structure second declare structure

variable dicker pointer variable so

pointer variable should be declared so

how do you declare a pointer variable so

in the marvel pointer it is a pointer so

every pointer should have a datatype

right so whatever the address we are

storing into the pointer variable that

data path should be used as user for the

declaration of this pointer so if in a

that means is a pointer is used to hold

the address of integer variable we have

to declare that pointer with a integer

determined so if a pointer is used to

hold the floating-point the address of

floating point variable we have to

declare the file

that floating-point data similarly here

we are supposed to store the address

office structure variable so the pointer

should be declared using this section I

suppose so

in order to let's let us equation is

linear so in order to declare the

structure available what is the syntax

we have seen the striped tag name

variable name so in order to declare

this pointer which stores the address of

the structure same but student star PDR

so here's PDL is a pointer variable

which is declared using the structure

and it stores the address of a structure

variable which is which follows the

student structure so after the

declaration we have to ensure eyes so

here after declaration so what is the

initialization we have to assign the

enters of a to the pointer will

similarly here also we have to assign

the structure of the letters of

structure variable to the point the same

seed X nothing is yet so this is the

definition

declaration of a structure variable

declaration of a point available and

then initialization nice first one is

the most important so now how to access

the members of the structure how to

access the members of the structure to

the point so a normal accessing is so

how they access the members using the

we will use the structure variable dot

the company remember similarly this one

dot name yes 1.4 sandwich this is the

normal way how we access the structure

may be members of a structure using the

structure middle now the question is we

have to access the members of the

structure using the pointer available so

here we will use an another operator

called arrow operator arrow operator so

in order to access the members of the

structure producing the structure

available we will use the dot operator

so in order to access the members of the

structure using the pointer available

with use an operator so how to get this

arrow operator in our keyboard just

press the minus and a greater than

symbol minus n greater than symbol so

that we can get this out so by using

this arrow operator will access the

members of a structure using this

pointer so in order to access the role

member of a student 1 we can write it as

s on the whole number this is a normal

axis where our 70 this pointer PTR arrow

bar full number Sigma V name PTR and

Mark name similarly pretty our arrow

mark parsonage so what will result the

same so this is a dot operator a normal

axis and this is a my operator poi

Francis so let us see the program so let

us initialize the only one variable and

then let us initialize a pointer

variable and access the members of the

structure using these pointers

so first I define a structure SPECT

student each roll number

character name of twenty next float

percentage close the structure open the

main function so now we have to declare

a structure variable the end of one

variable so struct student yes one so in

the same single statement we can declare

the point available also star media so

will be respond is another variable

structure variable and PTR is a pointer

variable which is declared using this

start there now initialization period is

equal to ampersand yes 1 so X 1 then F

of s 1 is initialized to the point

printf

and then roll number scanf percentage D

ampersand yes one God or we can

precipitate I am present PT R of s let

me pull them freedom enter name scanner

percentage yes s1 dot and then as it is

system we need not read this a more

sensible then again printer enter

percentage scanf percentage here

amber said less one dot PDRC

now if you want to print this we can

simply write as well dot name as well

Oliver or a smaller percentage or we can

simply write printf volt-ampere is equal

to percentage D so instead of writing X

1 or whole number we can access the

value using this pointer so PTR of whole

number so it will also give the same

result next printf name is equal to

percentage yes save PDF of name printf

percentage

percentage is equal to percentage f PT

our arrow operator P R see this so here

also we can write am % PT F alpha arrow

operator

rule number prettier arrow operator name

and ampersand PTR arrow operator

percentage so anything is same because

we are initializing the address to the

pointer variable so the important thing

we have to remember is in order to

access the numbers using the structure

variable we have to use the dot operator

and in order to access the members of a

structure using the pointers we have to

use the arrow operator an operator dot

operator using special variable this is

pointer way so hope you understood this

is a simple concept so the structures

two pointers so if you like my videos

shape my videos with your friends and if

you are having any doubts regarding our

regarding the C language feel free to

post your thoughts in the comment

section so that I will definitely try to

clarify all your notes and do subscribe

to my channel for more technical videos

thank you for watching

thank you very much