SlideShare ist ein Scribd-Unternehmen logo
1 von 10
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++;
}

Weitere ähnliche Inhalte

Was ist angesagt?

Array in c language
Array in c languageArray in c language
Array in c language
home
 

Was ist angesagt? (20)

Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variables
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
Linked List
Linked ListLinked List
Linked List
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Files in c++
Files in c++Files in c++
Files in c++
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Arrays
ArraysArrays
Arrays
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Arrays
ArraysArrays
Arrays
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 

Ähnlich wie Pointer to array and structure

9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
Terry Yoast
 

Ähnlich wie 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
 
Chap 2 Arrays and Structures.pptx
Chap 2  Arrays and Structures.pptxChap 2  Arrays and Structures.pptx
Chap 2 Arrays and Structures.pptx
 
C Language Lecture 20
C Language Lecture 20C Language Lecture 20
C Language Lecture 20
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
Pointers and arrays
Pointers and arraysPointers and arrays
Pointers and arrays
 
Array notes
Array notesArray notes
Array notes
 
Numpy in Python.docx
Numpy in Python.docxNumpy in Python.docx
Numpy in Python.docx
 
Arrays
ArraysArrays
Arrays
 
Array
ArrayArray
Array
 
Array
ArrayArray
Array
 
Chap 11(pointers)
Chap 11(pointers)Chap 11(pointers)
Chap 11(pointers)
 
Notes-10-Array.pdf
Notes-10-Array.pdfNotes-10-Array.pdf
Notes-10-Array.pdf
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
1st lecture.ppt
1st lecture.ppt1st lecture.ppt
1st lecture.ppt
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
 
7.basic array
7.basic array7.basic array
7.basic array
 
Data structure week 2
Data structure week 2Data structure week 2
Data structure week 2
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 

Mehr von sangrampatil81

Mehr von sangrampatil81 (20)

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

Kürzlich hochgeladen

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Kürzlich hochgeladen (20)

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 

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