SlideShare a Scribd company logo
1 of 13
POINTER
in C language
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 67 67 68 69
70 71 72 73 74 75 76 77 78 79
RAM
Single unit of memory
a byte
Sample of a 79 byte memory
Address of any
particular byte
int a=3;
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 67 67 68 69
70 71 72 73 74 75 76 77 78 79
34 35
3
a
34 35
3
a
Base address or
address of
memory block
Name of memory
block or variable
name
Content on
memory block
34 35
3
a
Base address or
address of
memory block
In pointers we
shall deal with
address of the
memory block
Definition of Pointer
• Pointer is a special kind of variable which can contain address of
another variable of same data type.
Declaration of Pointer
int *x;
Initialization of Pointer
x=&a;
54 55
34
xa
34 35
3
void main()
{printf(“ %d n ”, &a);
printf(“ %d n ”, x);
printf(“ %d n ”, &x);
printf(“ %d n ”, *x);
printf(“ %d n ”, *&a);
printf(“ %d n ”, *&x);
}
34
34
54
3
3
34
To store the address of any longer variable we
have to declare a double pointer.
int **y;
which can store the address of pointer variable x;
y=&x;
int ***z;
z=&y;
z is for store the address of y and so on.
Pointer always consumes 2 bytes memory
• According to Dos Based architecture a C program consumes 16 kb or
65536 bytes of memory means in unsigned binary it is
1111111111111111 (16 times 1) and so the maximum address may be
65535 and 2 bytes are sufficient to store it.
Arithmetic operations for pointers
• We can’t add, divide or multiply two address.
• We can subtract two address of same data type.
int a,b;
//&a-&b= (&a-&b)/sizeof(a)
• We can’t divide or multiply an integer to a pointer.
• We can add and subtract an integer to a pointer.
Arithmetic operations for pointers
int *y , a = 3;
y = &a;
y = y + n;
y = y - n;
/*
: y = y + n;
: y = y + sizeof(datatype of y)*n;
: y = y - n;
: y = y - sizeof(datatype of y)*n;
*/
Key facts about Pointers
• For printing any address we should use %u instead of %d in printf()
function.
Because Range of %d is -32768 to 32767 and %u is 0 to 65535
• & is Known as address of or referencing operator. It takes variable and
return its address. It is unary operator. &a is used to represent the
address of block x.
• * is Indirection or dereferencing operator. It takes address and gives
value on that address. It is also unary operator.
• Pointer When incremented, always point to immediately next block of
its own type.

More Related Content

What's hot

Ellipse T
Ellipse TEllipse T
Ellipse Tbwlomas
 
Maths exercises
Maths exercisesMaths exercises
Maths exercisesvaniceyew
 
add and subtract decimals
add and subtract decimals add and subtract decimals
add and subtract decimals nglaze10
 
Algebra 1 unit 1.1
Algebra 1 unit 1.1Algebra 1 unit 1.1
Algebra 1 unit 1.1Mark Ryder
 
SMU BCA SPRING 2014 SOLVED ASSIGNMENTS SEM-3
SMU BCA SPRING 2014  SOLVED ASSIGNMENTS SEM-3SMU BCA SPRING 2014  SOLVED ASSIGNMENTS SEM-3
SMU BCA SPRING 2014 SOLVED ASSIGNMENTS SEM-3smumbahelp
 

What's hot (10)

Ellipse T
Ellipse TEllipse T
Ellipse T
 
Stdform
StdformStdform
Stdform
 
Maths exercises
Maths exercisesMaths exercises
Maths exercises
 
3XRC4
3XRC43XRC4
3XRC4
 
add and subtract decimals
add and subtract decimals add and subtract decimals
add and subtract decimals
 
Pc 8.5 notes_appsof_det
Pc 8.5 notes_appsof_detPc 8.5 notes_appsof_det
Pc 8.5 notes_appsof_det
 
Pc 8.5 notes_appsof_det
Pc 8.5 notes_appsof_detPc 8.5 notes_appsof_det
Pc 8.5 notes_appsof_det
 
Algebra 1 unit 1.1
Algebra 1 unit 1.1Algebra 1 unit 1.1
Algebra 1 unit 1.1
 
Cube Roots from CCSS
Cube Roots from CCSSCube Roots from CCSS
Cube Roots from CCSS
 
SMU BCA SPRING 2014 SOLVED ASSIGNMENTS SEM-3
SMU BCA SPRING 2014  SOLVED ASSIGNMENTS SEM-3SMU BCA SPRING 2014  SOLVED ASSIGNMENTS SEM-3
SMU BCA SPRING 2014 SOLVED ASSIGNMENTS SEM-3
 

Similar to Pointer in c

Similar to Pointer in c (20)

POINTERS IN C++ CBSE +2 COMPUTER SCIENCE
POINTERS IN C++ CBSE +2 COMPUTER SCIENCEPOINTERS IN C++ CBSE +2 COMPUTER SCIENCE
POINTERS IN C++ CBSE +2 COMPUTER SCIENCE
 
Pointer
PointerPointer
Pointer
 
Kaizen cso002 l1
Kaizen cso002 l1Kaizen cso002 l1
Kaizen cso002 l1
 
Bits and the organization of memory
Bits and the organization of memoryBits and the organization of memory
Bits and the organization of memory
 
Happy To Use SIMD
Happy To Use SIMDHappy To Use SIMD
Happy To Use SIMD
 
SPL_PS2 (1).ppt
SPL_PS2 (1).pptSPL_PS2 (1).ppt
SPL_PS2 (1).ppt
 
Basic arithmetic, instruction execution and program
Basic arithmetic, instruction execution and programBasic arithmetic, instruction execution and program
Basic arithmetic, instruction execution and program
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
Ieee+floating
Ieee+floatingIeee+floating
Ieee+floating
 
primitive data types
 primitive data types primitive data types
primitive data types
 
C Sharp Nagina (1)
C Sharp Nagina (1)C Sharp Nagina (1)
C Sharp Nagina (1)
 
C Sharp Jn (1)
C Sharp Jn (1)C Sharp Jn (1)
C Sharp Jn (1)
 
Base64 Encoding
Base64 EncodingBase64 Encoding
Base64 Encoding
 
Cpa lecture (theory) 02_
Cpa lecture (theory) 02_Cpa lecture (theory) 02_
Cpa lecture (theory) 02_
 
Basics of Python
Basics of PythonBasics of Python
Basics of Python
 
#GDC15 Code Clinic
#GDC15 Code Clinic#GDC15 Code Clinic
#GDC15 Code Clinic
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
Cache mapping
Cache mappingCache mapping
Cache mapping
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
Int 2 data representation 2010
Int 2 data representation 2010Int 2 data representation 2010
Int 2 data representation 2010
 

More from AvichalVishnoi

More from AvichalVishnoi (6)

Grpahs in Data Structure
Grpahs in Data StructureGrpahs in Data Structure
Grpahs in Data Structure
 
Tower of hanoi
Tower of hanoiTower of hanoi
Tower of hanoi
 
B trees
B treesB trees
B trees
 
Bfs dfs mst
Bfs dfs mstBfs dfs mst
Bfs dfs mst
 
Dsa sorting
Dsa sortingDsa sorting
Dsa sorting
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 

Recently uploaded

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...soginsider
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf203318pmpc
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 

Recently uploaded (20)

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 

Pointer in c

  • 2. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 67 67 68 69 70 71 72 73 74 75 76 77 78 79 RAM Single unit of memory a byte Sample of a 79 byte memory Address of any particular byte
  • 3. int a=3; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 67 67 68 69 70 71 72 73 74 75 76 77 78 79 34 35 3 a
  • 4. 34 35 3 a Base address or address of memory block Name of memory block or variable name Content on memory block
  • 5. 34 35 3 a Base address or address of memory block In pointers we shall deal with address of the memory block
  • 6. Definition of Pointer • Pointer is a special kind of variable which can contain address of another variable of same data type. Declaration of Pointer int *x; Initialization of Pointer x=&a;
  • 7. 54 55 34 xa 34 35 3 void main() {printf(“ %d n ”, &a); printf(“ %d n ”, x); printf(“ %d n ”, &x); printf(“ %d n ”, *x); printf(“ %d n ”, *&a); printf(“ %d n ”, *&x); } 34 34 54 3 3 34
  • 8.
  • 9. To store the address of any longer variable we have to declare a double pointer. int **y; which can store the address of pointer variable x; y=&x; int ***z; z=&y; z is for store the address of y and so on.
  • 10. Pointer always consumes 2 bytes memory • According to Dos Based architecture a C program consumes 16 kb or 65536 bytes of memory means in unsigned binary it is 1111111111111111 (16 times 1) and so the maximum address may be 65535 and 2 bytes are sufficient to store it.
  • 11. Arithmetic operations for pointers • We can’t add, divide or multiply two address. • We can subtract two address of same data type. int a,b; //&a-&b= (&a-&b)/sizeof(a) • We can’t divide or multiply an integer to a pointer. • We can add and subtract an integer to a pointer.
  • 12. Arithmetic operations for pointers int *y , a = 3; y = &a; y = y + n; y = y - n; /* : y = y + n; : y = y + sizeof(datatype of y)*n; : y = y - n; : y = y - sizeof(datatype of y)*n; */
  • 13. Key facts about Pointers • For printing any address we should use %u instead of %d in printf() function. Because Range of %d is -32768 to 32767 and %u is 0 to 65535 • & is Known as address of or referencing operator. It takes variable and return its address. It is unary operator. &a is used to represent the address of block x. • * is Indirection or dereferencing operator. It takes address and gives value on that address. It is also unary operator. • Pointer When incremented, always point to immediately next block of its own type.