SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
Pointer to Array and
Structure
Prepared By: Mr. S. A. Patil
Assistant Professor,PVPIT Budhgaon
Pointers to Array
 Array is collection elements with same datatype.
 When we create an array some memory space is allocated to that array.
 So we can create pointer of array also.
 By using pointer to array we can access elements of array
Example
int numbers[5]={10,20,30,40,50};
int *p;
p=&numbers; // p=numbers;
this store address of first element of the array. And once we store address of first
element of array we can access by using *(p+1),*(p+2) and so on.
Access array using pointer
int numbers[5]={10,20,30,40,50};
int *p,i;
p=&numbers; // p=numbers;
for( i=0; i<5 ; i++)
{
printf(“n%d”,*(p+i));
}
Pointer to structure
 Structure is collection of elements with different datatypes.
 When we define any structure we create a user defined datatype of structure type.
 Memory is allocated to each structure variable.
 We can also create pointer to structure variable.
 And access structure by using pointer
Example
struct student
{
int roll;
float marks;
};
struct student s1;
struct student *ptr;
ptr=&s1;
Access structure elements using pointer
 We can access structure elements by using -> operator
 Write data into structure variable
printf(“nEnter Roll No:”);
scanf(“%d”,&ptr->roll);
printf(“nEnter Marks:”);
scanf(“%f”,&ptr->marks);
 Read structure variable
printf(“nRoll number: %d”,ptr->roll);
printf(“nMarks: %f”,ptr->marks);
Pointer to array of structure
 It is possible to create pointer to array of structure as regular array.
struct student
{
int roll;
float marks;
};
struct student s[5];
struct student *ptr;
ptr=&s;
Access array of structure using pointer
 We can access structure elements by using -> operator
 Write data into structure variable
for(i=0;i<5;i++)
{
printf(“nEnter Roll No:”);
scanf(“%d”,&ptr->roll);
printf(“nEnter Marks:”);
scanf(“%f”,&ptr->marks);
ptr++;
}
Access array of structure using pointer
 Read structure variable
for(i=0;i<5;i++)
{
printf(“nRoll number: %d”,ptr->roll);
printf(“nMarks: %f”,ptr->marks);
ptr++;
}

More Related Content

What's hot (20)

PPTX
Pointer in c
Imamul Kadir
 
PPTX
Presentation on pointer.
Md. Afif Al Mamun
 
PPTX
arrays and pointers
Samiksha Pun
 
PPTX
Arrays in Data Structure and Algorithm
KristinaBorooah
 
PPTX
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR
 
PPTX
Decision making and branching in c programming
Priyansh Thakar
 
PPTX
Pointers in C Language
madan reddy
 
PPTX
Data types
Zahid Hussain
 
PPTX
Union in C programming
Kamal Acharya
 
PPT
Constants in C Programming
programming9
 
PPTX
Pointers in c - Mohammad Salman
MohammadSalman129
 
PPT
358 33 powerpoint-slides_5-arrays_chapter-5
sumitbardhan
 
PPTX
Pre processor directives in c
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
File handling in c
aakanksha s
 
PPTX
Data types
Nokesh Prabhakar
 
PPTX
Operators and expressions in c language
tanmaymodi4
 
PPTX
Data types in c++
Venkata.Manish Reddy
 
PPTX
Data Types - Premetive and Non Premetive
Raj Naik
 
PPT
File in c
Prabhu Govind
 
PPTX
Pointer in C++
Mauryasuraj98
 
Pointer in c
Imamul Kadir
 
Presentation on pointer.
Md. Afif Al Mamun
 
arrays and pointers
Samiksha Pun
 
Arrays in Data Structure and Algorithm
KristinaBorooah
 
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR
 
Decision making and branching in c programming
Priyansh Thakar
 
Pointers in C Language
madan reddy
 
Data types
Zahid Hussain
 
Union in C programming
Kamal Acharya
 
Constants in C Programming
programming9
 
Pointers in c - Mohammad Salman
MohammadSalman129
 
358 33 powerpoint-slides_5-arrays_chapter-5
sumitbardhan
 
File handling in c
aakanksha s
 
Data types
Nokesh Prabhakar
 
Operators and expressions in c language
tanmaymodi4
 
Data types in c++
Venkata.Manish Reddy
 
Data Types - Premetive and Non Premetive
Raj Naik
 
File in c
Prabhu Govind
 
Pointer in C++
Mauryasuraj98
 

Similar to Pointer to array and structure (20)

PPTX
Welcome to our_presentation in c
imran hasan
 
PPTX
Address, Pointers, Arrays, and Structures2.pptx
Dr. Amna Mohamed
 
PPTX
pointers_final.pptxxxxxxxxxxxxxxxxxxxxxx
assignmenthet
 
PDF
java.pdf
RAJCHATTERJEE24
 
PPTX
Programming for problem solving-II(UNIT-2).pptx
prathima304
 
PPT
C Language_PPS_3110003_unit 8ClassPPT.ppt
NikeshaPatel1
 
PPTX
Structure&amp;union
PralhadKhanal1
 
PDF
unit 5.pdf structure pdf is here you can do this
sofiyakhan0280
 
PPTX
User defined data types.pptx
Ananthi Palanisamy
 
PPT
Introduction to structures in c lang.ppt
shivani366010
 
PPT
structures.ppt
RamyaR163211
 
PPT
DS_PPT.ppt
MeghaKulkarni27
 
PPTX
795834179-DS-module-1.pptx for dta sffssystrseeg
ssuser951fc8
 
DOCX
PPS 9.9.POINTERS IDEA OF POINTERS, DEFINING POINTERS, USE OF POINTERS IN SEL...
Sitamarhi Institute of Technology
 
PPTX
detail structure presentation of problem solving
talencorconsultancy
 
PPTX
Fundamentals of Structure in C Programming
Dr. Chandrakant Divate
 
PPTX
Structures
DrJasmineBeulahG
 
PPT
Unit4 C
arnold 7490
 
PPT
SPC Unit 3
SIMONTHOMAS S
 
Welcome to our_presentation in c
imran hasan
 
Address, Pointers, Arrays, and Structures2.pptx
Dr. Amna Mohamed
 
pointers_final.pptxxxxxxxxxxxxxxxxxxxxxx
assignmenthet
 
java.pdf
RAJCHATTERJEE24
 
Programming for problem solving-II(UNIT-2).pptx
prathima304
 
C Language_PPS_3110003_unit 8ClassPPT.ppt
NikeshaPatel1
 
Structure&amp;union
PralhadKhanal1
 
unit 5.pdf structure pdf is here you can do this
sofiyakhan0280
 
User defined data types.pptx
Ananthi Palanisamy
 
Introduction to structures in c lang.ppt
shivani366010
 
structures.ppt
RamyaR163211
 
DS_PPT.ppt
MeghaKulkarni27
 
795834179-DS-module-1.pptx for dta sffssystrseeg
ssuser951fc8
 
PPS 9.9.POINTERS IDEA OF POINTERS, DEFINING POINTERS, USE OF POINTERS IN SEL...
Sitamarhi Institute of Technology
 
detail structure presentation of problem solving
talencorconsultancy
 
Fundamentals of Structure in C Programming
Dr. Chandrakant Divate
 
Structures
DrJasmineBeulahG
 
Unit4 C
arnold 7490
 
SPC Unit 3
SIMONTHOMAS S
 
Ad

More from sangrampatil81 (20)

PPTX
Deadlock
sangrampatil81
 
PPTX
Memory Management
sangrampatil81
 
PPTX
virtual memory
sangrampatil81
 
PPTX
IO hardware
sangrampatil81
 
PPTX
File system structure
sangrampatil81
 
PPTX
File management
sangrampatil81
 
PPTX
Disk structure
sangrampatil81
 
PPTX
Directory structure
sangrampatil81
 
PPTX
Directory implementation and allocation methods
sangrampatil81
 
PPTX
Page replacement algorithms
sangrampatil81
 
PPTX
Methods for handling deadlock
sangrampatil81
 
PPTX
Semaphore
sangrampatil81
 
PPTX
Monitors
sangrampatil81
 
PPTX
Classical problems of process synchronization
sangrampatil81
 
PPTX
System programs
sangrampatil81
 
PPTX
System programs
sangrampatil81
 
PPTX
Services and system calls
sangrampatil81
 
PPTX
Operating system structure
sangrampatil81
 
PPTX
Operating system deign and implementation
sangrampatil81
 
PPTX
Pointer arithmetic in c
sangrampatil81
 
Deadlock
sangrampatil81
 
Memory Management
sangrampatil81
 
virtual memory
sangrampatil81
 
IO hardware
sangrampatil81
 
File system structure
sangrampatil81
 
File management
sangrampatil81
 
Disk structure
sangrampatil81
 
Directory structure
sangrampatil81
 
Directory implementation and allocation methods
sangrampatil81
 
Page replacement algorithms
sangrampatil81
 
Methods for handling deadlock
sangrampatil81
 
Semaphore
sangrampatil81
 
Monitors
sangrampatil81
 
Classical problems of process synchronization
sangrampatil81
 
System programs
sangrampatil81
 
System programs
sangrampatil81
 
Services and system calls
sangrampatil81
 
Operating system structure
sangrampatil81
 
Operating system deign and implementation
sangrampatil81
 
Pointer arithmetic in c
sangrampatil81
 
Ad

Recently uploaded (20)

PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
How Cloud Computing is Reinventing Financial Services
Isla Pandora
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
How Cloud Computing is Reinventing Financial Services
Isla Pandora
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Import Data Form Excel to Tally Services
Tally xperts
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 

Pointer to array and structure

  • 1. Pointer to Array and Structure Prepared By: Mr. S. A. Patil Assistant Professor,PVPIT Budhgaon
  • 2. Pointers to Array  Array is collection elements with same datatype.  When we create an array some memory space is allocated to that array.  So we can create pointer of array also.  By using pointer to array we can access elements of array
  • 3. Example int numbers[5]={10,20,30,40,50}; int *p; p=&numbers; // p=numbers; this store address of first element of the array. And once we store address of first element of array we can access by using *(p+1),*(p+2) and so on.
  • 4. Access array using pointer int numbers[5]={10,20,30,40,50}; int *p,i; p=&numbers; // p=numbers; for( i=0; i<5 ; i++) { printf(“n%d”,*(p+i)); }
  • 5. Pointer to structure  Structure is collection of elements with different datatypes.  When we define any structure we create a user defined datatype of structure type.  Memory is allocated to each structure variable.  We can also create pointer to structure variable.  And access structure by using pointer
  • 6. Example struct student { int roll; float marks; }; struct student s1; struct student *ptr; ptr=&s1;
  • 7. Access structure elements using pointer  We can access structure elements by using -> operator  Write data into structure variable printf(“nEnter Roll No:”); scanf(“%d”,&ptr->roll); printf(“nEnter Marks:”); scanf(“%f”,&ptr->marks);  Read structure variable printf(“nRoll number: %d”,ptr->roll); printf(“nMarks: %f”,ptr->marks);
  • 8. Pointer to array of structure  It is possible to create pointer to array of structure as regular array. struct student { int roll; float marks; }; struct student s[5]; struct student *ptr; ptr=&s;
  • 9. Access array of structure using pointer  We can access structure elements by using -> operator  Write data into structure variable for(i=0;i<5;i++) { printf(“nEnter Roll No:”); scanf(“%d”,&ptr->roll); printf(“nEnter Marks:”); scanf(“%f”,&ptr->marks); ptr++; }
  • 10. Access array of structure using pointer  Read structure variable for(i=0;i<5;i++) { printf(“nRoll number: %d”,ptr->roll); printf(“nMarks: %f”,ptr->marks); ptr++; }