SlideShare a Scribd company logo
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++;
}
Ad

More Related Content

What's hot (20)

arrays of structures
arrays of structuresarrays of structures
arrays of structures
arushi bhatnagar
 
Pointers in C
Pointers in CPointers in C
Pointers in C
Vijayananda Ratnam Ch
 
String
StringString
String
Kishan Gohel
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
 
One Dimensional Array
One Dimensional Array One Dimensional Array
One Dimensional Array
dincyjain
 
Structure in C
Structure in CStructure in C
Structure in C
Fazle Rabbi Ador
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
Mazharul Islam
 
Pointer to function 1
Pointer to function 1Pointer to function 1
Pointer to function 1
Abu Bakr Ramadan
 
Structure & union
Structure & unionStructure & union
Structure & union
Rupesh Mishra
 
pointers
pointerspointers
pointers
teach4uin
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 
Array in c language
Array in c languageArray in c language
Array in c language
home
 
Introduction to pandas
Introduction to pandasIntroduction to pandas
Introduction to pandas
Piyush rai
 
2D arrays
2D arrays2D arrays
2D arrays
Mehedi Hasan Raju
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
Md. Afif Al Mamun
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
Rumman Ansari
 
C pointer
C pointerC pointer
C pointer
University of Potsdam
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Array in C
Array in CArray in C
Array in C
Kamal Acharya
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
Shubham Sharma
 

Similar to Pointer to array and structure (20)

Chap 2 Arrays and Structures.ppt
Chap 2  Arrays and Structures.pptChap 2  Arrays and Structures.ppt
Chap 2 Arrays and Structures.ppt
shashankbhadouria4
 
Chap 2 Arrays and Structures.pptx
Chap 2  Arrays and Structures.pptxChap 2  Arrays and Structures.pptx
Chap 2 Arrays and Structures.pptx
shashankbhadouria4
 
C Language Lecture 20
C Language Lecture 20C Language Lecture 20
C Language Lecture 20
Shahzaib Ajmal
 
Module_3_Arrays - Updated.pptx............
Module_3_Arrays - Updated.pptx............Module_3_Arrays - Updated.pptx............
Module_3_Arrays - Updated.pptx............
ChiragKankani
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
shafat6712
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
moazamali28
 
object oriented programing in python and pip
object oriented programing in python and pipobject oriented programing in python and pip
object oriented programing in python and pip
LakshmiMarineni
 
Unit 3(Arrays).pptx arrays topics in the c lang
Unit 3(Arrays).pptx arrays topics in the c langUnit 3(Arrays).pptx arrays topics in the c lang
Unit 3(Arrays).pptx arrays topics in the c lang
meesalasrinuvasuraon
 
Pointers and arrays
Pointers and arraysPointers and arrays
Pointers and arrays
Bhuvana Gowtham
 
Array notes
Array notesArray notes
Array notes
Deepika,Assistant Professor,PES College of Engineering ,Mandya
 
Numpy in Python.docx
Numpy in Python.docxNumpy in Python.docx
Numpy in Python.docx
manohar25689
 
Arrays
ArraysArrays
Arrays
Neeru Mittal
 
Array
ArrayArray
Array
DharmaKumariBhandari
 
Array
ArrayArray
Array
Samsil Arefin
 
Chap 11(pointers)
Chap 11(pointers)Chap 11(pointers)
Chap 11(pointers)
Bangabandhu Sheikh Mujibur Rahman Science and Technology University
 
Notes-10-Array.pdf
Notes-10-Array.pdfNotes-10-Array.pdf
Notes-10-Array.pdf
umeshraoumesh40
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
Anurag University Hyderabad
 
1st lecture.ppt
1st lecture.ppt1st lecture.ppt
1st lecture.ppt
ShujatAli47
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
AnisZahirahAzman
 
7.basic array
7.basic array7.basic array
7.basic array
Mir Riyanul Islam
 
Ad

More from sangrampatil81 (20)

Deadlock
DeadlockDeadlock
Deadlock
sangrampatil81
 
Memory Management
Memory ManagementMemory Management
Memory Management
sangrampatil81
 
virtual memory
virtual memoryvirtual memory
virtual memory
sangrampatil81
 
IO hardware
IO hardwareIO hardware
IO hardware
sangrampatil81
 
File system structure
File system structureFile system structure
File system structure
sangrampatil81
 
File management
File managementFile management
File management
sangrampatil81
 
Disk structure
Disk structureDisk structure
Disk structure
sangrampatil81
 
Directory structure
Directory structureDirectory structure
Directory structure
sangrampatil81
 
Directory implementation and allocation methods
Directory implementation and allocation methodsDirectory implementation and allocation methods
Directory implementation and allocation methods
sangrampatil81
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
sangrampatil81
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
sangrampatil81
 
Semaphore
SemaphoreSemaphore
Semaphore
sangrampatil81
 
Monitors
MonitorsMonitors
Monitors
sangrampatil81
 
Classical problems of process synchronization
Classical problems of process synchronizationClassical problems of process synchronization
Classical problems of process synchronization
sangrampatil81
 
System programs
System programsSystem programs
System programs
sangrampatil81
 
System programs
System programsSystem programs
System programs
sangrampatil81
 
Services and system calls
Services and system callsServices and system calls
Services and system calls
sangrampatil81
 
Operating system structure
Operating system structureOperating system structure
Operating system structure
sangrampatil81
 
Operating system deign and implementation
Operating system deign and implementationOperating system deign and implementation
Operating system deign and implementation
sangrampatil81
 
Pointer arithmetic in c
Pointer arithmetic in c Pointer arithmetic in c
Pointer arithmetic in c
sangrampatil81
 
Ad

Recently uploaded (20)

Implementing promises with typescripts, step by step
Implementing promises with typescripts, step by stepImplementing promises with typescripts, step by step
Implementing promises with typescripts, step by step
Ran Wahle
 
Full Cracked Resolume Arena Latest Version
Full Cracked Resolume Arena Latest VersionFull Cracked Resolume Arena Latest Version
Full Cracked Resolume Arena Latest Version
jonesmichealj2
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
DVDFab Crack FREE Download Latest Version 2025
DVDFab Crack FREE Download Latest Version 2025DVDFab Crack FREE Download Latest Version 2025
DVDFab Crack FREE Download Latest Version 2025
younisnoman75
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Top 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdfTop 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdf
AffinityCore
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
Imma Valls Bernaus
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 
Implementing promises with typescripts, step by step
Implementing promises with typescripts, step by stepImplementing promises with typescripts, step by step
Implementing promises with typescripts, step by step
Ran Wahle
 
Full Cracked Resolume Arena Latest Version
Full Cracked Resolume Arena Latest VersionFull Cracked Resolume Arena Latest Version
Full Cracked Resolume Arena Latest Version
jonesmichealj2
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
DVDFab Crack FREE Download Latest Version 2025
DVDFab Crack FREE Download Latest Version 2025DVDFab Crack FREE Download Latest Version 2025
DVDFab Crack FREE Download Latest Version 2025
younisnoman75
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Top 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdfTop 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdf
AffinityCore
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
Imma Valls Bernaus
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 

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++; }