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

Recommended

PPT
Structure in c
Prabhu Govind
 
PPT
detailed information about Pointers in c language
gourav kottawar
 
PPTX
Structure & union
lalithambiga kamaraj
 
PPT
Structure and union
Samsil Arefin
 
PPTX
Union in C programming
Kamal Acharya
 
PDF
Pointers
sarith divakar
 
PDF
C Pointers
omukhtar
 
PPT
Structure c
thirumalaikumar3
 
PPT
Strings
Nilesh Dalvi
 
PDF
Pointers in C
Monishkanungo
 
PPTX
Structure in C language
CGC Technical campus,Mohali
 
PPTX
C string
University of Potsdam
 
PPTX
Pointer in c program
Rumman Ansari
 
PPT
Data type in c
thirumalaikumar3
 
PPTX
Passing an Array to a Function (ICT Programming)
Fatima Kate Tanay
 
PPTX
Pointers in c - Mohammad Salman
MohammadSalman129
 
PDF
Learn C# Programming - Data Types & Type Conversion
Eng Teong Cheah
 
PPTX
Typedef
vaseemkhn
 
PPT
Pointer in C
Sonya Akter Rupa
 
PPT
358 33 powerpoint-slides_3-pointers_chapter-3
sumitbardhan
 
PPTX
File Handling and Command Line Arguments in C
Mahendra Yadav
 
PPTX
C Programming: Structure and Union
Selvaraj Seerangan
 
PDF
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
PPTX
Arrays in c
CHANDAN KUMAR
 
PDF
Unit 1-Introduction to Data Structures-BCA.pdf
MaryJacob24
 
PPT
Preprocessor in C
Prabhu Govind
 
PPT
C++ oop
Sunil OS
 
PPTX
Welcome to our_presentation in c
imran hasan
 
PPTX
Address, Pointers, Arrays, and Structures2.pptx
Dr. Amna Mohamed
 

More Related Content

What's hot (20)

PPT
Structure c
thirumalaikumar3
 
PPT
Strings
Nilesh Dalvi
 
PDF
Pointers in C
Monishkanungo
 
PPTX
Structure in C language
CGC Technical campus,Mohali
 
PPTX
C string
University of Potsdam
 
PPTX
Pointer in c program
Rumman Ansari
 
PPT
Data type in c
thirumalaikumar3
 
PPTX
Passing an Array to a Function (ICT Programming)
Fatima Kate Tanay
 
PPTX
Pointers in c - Mohammad Salman
MohammadSalman129
 
PDF
Learn C# Programming - Data Types & Type Conversion
Eng Teong Cheah
 
PPTX
Typedef
vaseemkhn
 
PPT
Pointer in C
Sonya Akter Rupa
 
PPT
358 33 powerpoint-slides_3-pointers_chapter-3
sumitbardhan
 
PPTX
File Handling and Command Line Arguments in C
Mahendra Yadav
 
PPTX
C Programming: Structure and Union
Selvaraj Seerangan
 
PDF
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
PPTX
Arrays in c
CHANDAN KUMAR
 
PDF
Unit 1-Introduction to Data Structures-BCA.pdf
MaryJacob24
 
PPT
Preprocessor in C
Prabhu Govind
 
PPT
C++ oop
Sunil OS
 
Structure c
thirumalaikumar3
 
Strings
Nilesh Dalvi
 
Pointers in C
Monishkanungo
 
Structure in C language
CGC Technical campus,Mohali
 
Pointer in c program
Rumman Ansari
 
Data type in c
thirumalaikumar3
 
Passing an Array to a Function (ICT Programming)
Fatima Kate Tanay
 
Pointers in c - Mohammad Salman
MohammadSalman129
 
Learn C# Programming - Data Types & Type Conversion
Eng Teong Cheah
 
Typedef
vaseemkhn
 
Pointer in C
Sonya Akter Rupa
 
358 33 powerpoint-slides_3-pointers_chapter-3
sumitbardhan
 
File Handling and Command Line Arguments in C
Mahendra Yadav
 
C Programming: Structure and Union
Selvaraj Seerangan
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
Arrays in c
CHANDAN KUMAR
 
Unit 1-Introduction to Data Structures-BCA.pdf
MaryJacob24
 
Preprocessor in C
Prabhu Govind
 
C++ oop
Sunil OS
 

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
 
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
 
PPTX
Unit-4-1.pptxjtjrjfjfjfjfjfjfjfjrjrjrjrjejejeje
KathanPatel49
 
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
 
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
 
Unit-4-1.pptxjtjrjfjfjfjfjfjfjfjrjrjrjrjejejeje
KathanPatel49
 
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)

PDF
University Campus Navigation for All - Peak of Data & AI
Safe Software
 
DOCX
Zoho Creator Solution for EI by Elsner Technologies.docx
Elsner Technologies Pvt. Ltd.
 
PPTX
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
PPTX
Top Time Tracking Solutions for Accountants
oliviareed320
 
PDF
Heat Treatment Process Automation in India
Reckers Mechatronics
 
PPTX
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
 
PDF
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
PPTX
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
Jamie Coleman
 
PDF
Complete WordPress Programming Guidance Book
Shabista Imam
 
PDF
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
PPT
Complete Guideliness to Build an Effective Maintenance Plan.ppt
QualityzeInc1
 
PDF
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
 
PPTX
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
 
PDF
Decipher SEO Solutions for your startup needs.
mathai2
 
DOCX
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
PPTX
declaration of Variables and constants.pptx
meemee7378
 
PDF
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
PDF
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 
PDF
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 
PDF
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
WSO2
 
University Campus Navigation for All - Peak of Data & AI
Safe Software
 
Zoho Creator Solution for EI by Elsner Technologies.docx
Elsner Technologies Pvt. Ltd.
 
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
Top Time Tracking Solutions for Accountants
oliviareed320
 
Heat Treatment Process Automation in India
Reckers Mechatronics
 
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
 
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
Jamie Coleman
 
Complete WordPress Programming Guidance Book
Shabista Imam
 
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
Complete Guideliness to Build an Effective Maintenance Plan.ppt
QualityzeInc1
 
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
 
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
 
Decipher SEO Solutions for your startup needs.
mathai2
 
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
declaration of Variables and constants.pptx
meemee7378
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
WSO2
 

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