SlideShare a Scribd company logo
1 of 4
Types of Pointers

TYPES OF POINTERS
Void Pointer:
It is a special type of pointer that can be pointed at objectsof any data type.A void pointer is
declared like a normal pointer,using the void keyword as the pointer’s type.
Example :
float *f;
int i;
f = &i;

//pointer of type float
//integer variable
//compilation error

The above problem can be solved by general purpose pointer called void pointer.
Void pointer can be declared as follows:
void *v // defines a pointer of type void
Wild Pointer:
A pointer in c which has not been initialized is known as wild pointer.
Example :
What will be output of following c program?
#include<stdio.h>
int main(){
int *ptr;
printf("%un",ptr);
printf("%d",*ptr);
return 0;
}
Output: Any address
Garbage value
Here ptr is wild pointer because it has not been initialized.
There is difference between the NULL pointer and wild pointer.
Null pointer points the base address of segment
wild pointer doesn’t point any specific memory location.

Created By: Ravindra

Page 1
Types of Pointers

Different types of pointers:
1] Dangling Pointer:
If any pointer is pointing the memory address of any variable but after some variable has
deleted from that memory location while pointer is still pointing such memory location. Such
pointer is known as dangling pointer and this problem is known as dangling pointer problem.
Example :
#include<stdio.h>
#include<stdlib.h>
main()
{
int *p,n,i;
p=(int *)malloc(n*sizeof(int));
printf("Before FREE = %d",p);
free(p);
p=NULL;
printf("After FREE = %d",p);
return 0;
}
It will remove the problem of Dangling Pointers, but if you tries to access the *ptr it goes to
general protection, leading to arise the dangling pointers problem.
In TURBO C there are three types of pointers. TURBO C works under DOS operating system
which is based on 8085 microprocessor.
1. Near pointer
2.Far pointer
3.Huge pointer
1. Near pointer:
The pointer which can points only 64KB data segment or segment number 8 is known as near
pointer.
That is near pointer cannot access beyond the data segment like graphics video memory, text
video memory etc. Size of near pointer is two byte. With help keyword near, we can make any
pointer as near pointer.
Example :
(1)
#include<stdio.h>
int main(){
int x=25;
Created By: Ravindra

Page 2
Types of Pointers

int near* ptr;
ptr=&x;
printf(“%d”,sizeof ptr);
return 0;
}
Output: 2
Explanation: Size of any type of near pointer is two byte.
2. Far pointer:
The pointer which can point or access whole the residence memory of RAM i.e. which can
access all 16 segments is known as far pointer.
Size of far pointer is 4 byte or 32 bit.
Example :
#include<stdio.h>
int main(){
int far *near*ptr;
printf("%d %d",sizeof(ptr) ,sizeof(*ptr));
return 0;
}
Output: 4 2
Explanation: ptr is far pointer while *ptr is near pointer.
Example :
#include<stdio.h>
int main(){
int far *p,far *q;
printf("%d %d",sizeof(p) ,sizeof(q));
return 0;
}
Output: 4 4
First 16 bit stores: Segment number
Next 16 bit stores: Offset address
Now here question arises what is segment number & Offset address, Let’s check it…
Example :
#include<stdio.h>
int main(){
int x=100;
int far *ptr;
Created By: Ravindra

Page 3
Types of Pointers

ptr=&x;
printf("%Fp",ptr);
return 0;
}
Output: 8FD8:FFF4.
Here 8FD8 is segment address and FFF4 is offset address in hexadecimal number format.
Note: %Fp is used for print offset and segment address of pointer in printf function in
hexadecimal number format.
# Limitation of far pointer:
We cannot change or modify the segment address of given far address by applying any
arithmetic operation on it. That is by using arithmetic operator we cannot jump from one
segment to other segment. If you will increment the far address beyond the maximum value of its
offset address instead of incrementing segment address it will repeat its offset address in cyclic
order.

3. Huge Pointer:
The pointer which can point or access whole the residence memory of RAM i.e. which can
access all the 16 segments is known as huge pointer.
Size of huge pointer is 4 byte or 32 bit.
Example :
#include<stdio.h>
int main(){
char huge * far *p;
printf("%d %d %d",sizeof(p),sizeof(*p),sizeof(**p));
return 0;
}
Output: 4 4 1
Explanation: p is huge pointer, *p is far pointer and **p is char type data variable.

Created By: Ravindra

Page 4

More Related Content

What's hot (20)

C –FAQ:
C –FAQ:C –FAQ:
C –FAQ:
 
Advanced pointers
Advanced pointersAdvanced pointers
Advanced pointers
 
C Programming Assignment
C Programming AssignmentC Programming Assignment
C Programming Assignment
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
Pointers_c
Pointers_cPointers_c
Pointers_c
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in C
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
Lecture 17 - Strings
Lecture 17 - StringsLecture 17 - Strings
Lecture 17 - Strings
 
Pointers
PointersPointers
Pointers
 
Fundamentals of Pointers in C
Fundamentals of Pointers in CFundamentals of Pointers in C
Fundamentals of Pointers in C
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Ponters
PontersPonters
Ponters
 
C programming day#2.
C programming day#2.C programming day#2.
C programming day#2.
 

Viewers also liked

《岳美中醫話集》(增訂本)
《岳美中醫話集》(增訂本)《岳美中醫話集》(增訂本)
《岳美中醫話集》(增訂本)yct.Ken Chang
 
袁正瑤醫術驗案集錦
袁正瑤醫術驗案集錦袁正瑤醫術驗案集錦
袁正瑤醫術驗案集錦yct.Ken Chang
 
Genome Scineces Poster
Genome Scineces PosterGenome Scineces Poster
Genome Scineces PosterColton McDavid
 
GL's Tier Sheet 2014
GL's Tier Sheet 2014GL's Tier Sheet 2014
GL's Tier Sheet 2014George Li
 
Maintaining compliance while compensating physicians for quality and cost sav...
Maintaining compliance while compensating physicians for quality and cost sav...Maintaining compliance while compensating physicians for quality and cost sav...
Maintaining compliance while compensating physicians for quality and cost sav...Jessica Nickerson
 
Problema numero 4 de hidráulica
Problema numero 4 de hidráulica Problema numero 4 de hidráulica
Problema numero 4 de hidráulica Jonathan Rodriguez
 
《奇效驗案》P166
《奇效驗案》P166《奇效驗案》P166
《奇效驗案》P166yct.Ken Chang
 
Let's hear from the providers - 7th RISE Summit, Nashville, TN 11MAR13
Let's hear from the providers - 7th RISE Summit, Nashville, TN 11MAR13Let's hear from the providers - 7th RISE Summit, Nashville, TN 11MAR13
Let's hear from the providers - 7th RISE Summit, Nashville, TN 11MAR13Wayne Pan
 
Riesgos eléctricos y mecánicos
Riesgos eléctricos y mecánicosRiesgos eléctricos y mecánicos
Riesgos eléctricos y mecánicosKlaudya Bar
 
Ventajas y desventajas de los sistemas de informacion
Ventajas y desventajas de los sistemas de informacionVentajas y desventajas de los sistemas de informacion
Ventajas y desventajas de los sistemas de informacionmanuelrivasv95
 

Viewers also liked (15)

《岳美中醫話集》(增訂本)
《岳美中醫話集》(增訂本)《岳美中醫話集》(增訂本)
《岳美中醫話集》(增訂本)
 
袁正瑤醫術驗案集錦
袁正瑤醫術驗案集錦袁正瑤醫術驗案集錦
袁正瑤醫術驗案集錦
 
Genome Scineces Poster
Genome Scineces PosterGenome Scineces Poster
Genome Scineces Poster
 
GL's Tier Sheet 2014
GL's Tier Sheet 2014GL's Tier Sheet 2014
GL's Tier Sheet 2014
 
Maintaining compliance while compensating physicians for quality and cost sav...
Maintaining compliance while compensating physicians for quality and cost sav...Maintaining compliance while compensating physicians for quality and cost sav...
Maintaining compliance while compensating physicians for quality and cost sav...
 
Problema numero 4 de hidráulica
Problema numero 4 de hidráulica Problema numero 4 de hidráulica
Problema numero 4 de hidráulica
 
《奇效驗案》P166
《奇效驗案》P166《奇效驗案》P166
《奇效驗案》P166
 
Press digest
Press digestPress digest
Press digest
 
Swami vivekananda
Swami vivekanandaSwami vivekananda
Swami vivekananda
 
Jayne jordon gi
Jayne jordon giJayne jordon gi
Jayne jordon gi
 
Let's hear from the providers - 7th RISE Summit, Nashville, TN 11MAR13
Let's hear from the providers - 7th RISE Summit, Nashville, TN 11MAR13Let's hear from the providers - 7th RISE Summit, Nashville, TN 11MAR13
Let's hear from the providers - 7th RISE Summit, Nashville, TN 11MAR13
 
Ethan p
Ethan pEthan p
Ethan p
 
Mkt olfativo clase
Mkt olfativo claseMkt olfativo clase
Mkt olfativo clase
 
Riesgos eléctricos y mecánicos
Riesgos eléctricos y mecánicosRiesgos eléctricos y mecánicos
Riesgos eléctricos y mecánicos
 
Ventajas y desventajas de los sistemas de informacion
Ventajas y desventajas de los sistemas de informacionVentajas y desventajas de los sistemas de informacion
Ventajas y desventajas de los sistemas de informacion
 

Similar to Types of pointer

Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)tech4us
 
Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Gamindu Udayanga
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptxvijayapraba1
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanMohammadSalman129
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programmingnmahi96
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfKosmikTech1
 
Chapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdfChapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdfTamiratDejene1
 
Complicated declarations in c
Complicated declarations in cComplicated declarations in c
Complicated declarations in cRahul Budholiya
 
VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3YOGESH SINGH
 
python ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institutepython ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network InstituteScode Network Institute
 
Arrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptxArrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptxRamakrishna Reddy Bijjam
 
presentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxpresentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxKrishanPalSingh39
 

Similar to Types of pointer (20)

C programming session8
C programming  session8C programming  session8
C programming session8
 
C programming session8
C programming  session8C programming  session8
C programming session8
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
 
Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programming
 
Lecture 18 - Pointers
Lecture 18 - PointersLecture 18 - Pointers
Lecture 18 - Pointers
 
POINTERS.pptx
POINTERS.pptxPOINTERS.pptx
POINTERS.pptx
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
C Programming Unit-4
C Programming Unit-4C Programming Unit-4
C Programming Unit-4
 
Chapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdfChapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdf
 
Complicated declarations in c
Complicated declarations in cComplicated declarations in c
Complicated declarations in c
 
VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3
 
python ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institutepython ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institute
 
Arrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptxArrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptx
 
presentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxpresentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptx
 

Recently uploaded

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 

Types of pointer

  • 1. Types of Pointers TYPES OF POINTERS Void Pointer: It is a special type of pointer that can be pointed at objectsof any data type.A void pointer is declared like a normal pointer,using the void keyword as the pointer’s type. Example : float *f; int i; f = &i; //pointer of type float //integer variable //compilation error The above problem can be solved by general purpose pointer called void pointer. Void pointer can be declared as follows: void *v // defines a pointer of type void Wild Pointer: A pointer in c which has not been initialized is known as wild pointer. Example : What will be output of following c program? #include<stdio.h> int main(){ int *ptr; printf("%un",ptr); printf("%d",*ptr); return 0; } Output: Any address Garbage value Here ptr is wild pointer because it has not been initialized. There is difference between the NULL pointer and wild pointer. Null pointer points the base address of segment wild pointer doesn’t point any specific memory location. Created By: Ravindra Page 1
  • 2. Types of Pointers Different types of pointers: 1] Dangling Pointer: If any pointer is pointing the memory address of any variable but after some variable has deleted from that memory location while pointer is still pointing such memory location. Such pointer is known as dangling pointer and this problem is known as dangling pointer problem. Example : #include<stdio.h> #include<stdlib.h> main() { int *p,n,i; p=(int *)malloc(n*sizeof(int)); printf("Before FREE = %d",p); free(p); p=NULL; printf("After FREE = %d",p); return 0; } It will remove the problem of Dangling Pointers, but if you tries to access the *ptr it goes to general protection, leading to arise the dangling pointers problem. In TURBO C there are three types of pointers. TURBO C works under DOS operating system which is based on 8085 microprocessor. 1. Near pointer 2.Far pointer 3.Huge pointer 1. Near pointer: The pointer which can points only 64KB data segment or segment number 8 is known as near pointer. That is near pointer cannot access beyond the data segment like graphics video memory, text video memory etc. Size of near pointer is two byte. With help keyword near, we can make any pointer as near pointer. Example : (1) #include<stdio.h> int main(){ int x=25; Created By: Ravindra Page 2
  • 3. Types of Pointers int near* ptr; ptr=&x; printf(“%d”,sizeof ptr); return 0; } Output: 2 Explanation: Size of any type of near pointer is two byte. 2. Far pointer: The pointer which can point or access whole the residence memory of RAM i.e. which can access all 16 segments is known as far pointer. Size of far pointer is 4 byte or 32 bit. Example : #include<stdio.h> int main(){ int far *near*ptr; printf("%d %d",sizeof(ptr) ,sizeof(*ptr)); return 0; } Output: 4 2 Explanation: ptr is far pointer while *ptr is near pointer. Example : #include<stdio.h> int main(){ int far *p,far *q; printf("%d %d",sizeof(p) ,sizeof(q)); return 0; } Output: 4 4 First 16 bit stores: Segment number Next 16 bit stores: Offset address Now here question arises what is segment number & Offset address, Let’s check it… Example : #include<stdio.h> int main(){ int x=100; int far *ptr; Created By: Ravindra Page 3
  • 4. Types of Pointers ptr=&x; printf("%Fp",ptr); return 0; } Output: 8FD8:FFF4. Here 8FD8 is segment address and FFF4 is offset address in hexadecimal number format. Note: %Fp is used for print offset and segment address of pointer in printf function in hexadecimal number format. # Limitation of far pointer: We cannot change or modify the segment address of given far address by applying any arithmetic operation on it. That is by using arithmetic operator we cannot jump from one segment to other segment. If you will increment the far address beyond the maximum value of its offset address instead of incrementing segment address it will repeat its offset address in cyclic order. 3. Huge Pointer: The pointer which can point or access whole the residence memory of RAM i.e. which can access all the 16 segments is known as huge pointer. Size of huge pointer is 4 byte or 32 bit. Example : #include<stdio.h> int main(){ char huge * far *p; printf("%d %d %d",sizeof(p),sizeof(*p),sizeof(**p)); return 0; } Output: 4 4 1 Explanation: p is huge pointer, *p is far pointer and **p is char type data variable. Created By: Ravindra Page 4