SlideShare a Scribd company logo
Pointer
A pointer is a variable that stores memory address. Like all
other variables ,it also has a name, has to be declared and
occupies some space in memory. It is called pointer
because it points to a particular location in memory (by
storing the address of that location).
The expression having (*) operator is known as pointer
expression. Pointer is the variable that points to the
memory location of the next variable. So, we have to assign
address of a variable to the pointer variable.
Int a=5;
Int *p1=&a;
If we put *before p1, then, we can access the variable whose
address is stored in p1. since p1 contains the address of
variable a, we can access the variable a by writing *p1.
What are Pointers?
Pointers are different from other normal
variables. While other normal variables
store values, pointers are special variables
that can hold the address of a variable.
Since they store memory address of a
variable, the pointers are very commonly
said to “point to variables”.
Pointer
• A pointer is a variable which holds the address
of the storage location value for another given
variable.
• C provides two operators & and * which allow
pointers to be used in many versatile ways.
*:- is the value of address eg.*a
&:- is the address of variable eg. &a
*(&a):- we are using the value which is inside of
the address
pointer arithmetic operations are
allowed?
• A pointer can be incremented (++) or decremented (--)
• An integer may be added to a pointer (+ or +=)
• An integer may be subtracted from a pointer (- or -=)
• One pointer may be subtracted from another
In c programming every variable keeps two type of value.
1. Contain of variable or value of variable.
2. Address of variable where it has stored in the memory.
(1) Meaning of following simple pointer declaration and definition:
int a=5;
int * ptr;
ptr=&a;
Explanation:
About variable a:
1. Name of variable : a
2. Value of variable which it keeps: 5
3. Address where it has stored in memory : 1025 (assume)
About variable ptr:
4. Name of variable : ptr
5. Value of variable which it keeps: 1025
6. Address where it has stored in memory : 5000 (assume)
A normal variable ‘var’ has a memory address of 1001 and holds a
value 50.
A pointer variable has its own address 2047 but stores 1001,
which is the address of the variable ‘var’
Another example:
Int I, *j, **K;
Here I is dinary int ,J is a pointer to an int , whereas K is a pointer
to an integer pointer
3 65524 65522
i
65524
j
65522
65520
k
For example
a ) valid example
Int *p;
Int num;
P=#
b) Invalid example
Int *p;
Float num;
P=# /*as pointer variable p can not store address of float variable*/
Data type
Integer
Unsigned integer
Octal
Hexadecimal
Float simple
Float exponential
Character
string
Conversion Charater
D
U
O
X
F
E
C
S
#include <stdio.h>
#include <conio.h>
void main( )
{
int u = 36;
int *pu; /*pionter to an integer*/
clrscr();
pu=&u; /*assign address of u to pu*/
printf("nu=%d &u=%x *pu=%d",u,&u,*pu);
getch();
}
/* Illustration of pointer data type */
#include <stdio.h>
#include <conio.h>
void main( )
{
int u = 36;
int v;
int *pu; /* pointer to an integer*/
int *pv; /* pointer to an integer*/
clrscr();
pu = &u; /* assign address of u to pu */
v = *pu; /* assign address of u to v */
pv = &v; /* assign address of v to pv */
printf("nu = %d n&u = %x npu = %x n*pu = %d", u,&u, pu, *pu);
printf("nnv = %d n&v = %xn pv = %x n*pv = %d", v, &v, pv, *pv);
getch();
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,sum, *ptra,*ptrb;
a=20;
b=10;
ptra =&a;
ptrb=&b;
sum=*ptra+*ptrb;
printf("sum=%d",sum);
getch();
}
1. WAP to add value stored in two variable using pointer

More Related Content

What's hot

Data structure week 2
Data structure week 2Data structure week 2
Data structure week 2
karmuhtam
 
Pointer in C
Pointer in CPointer in C
Pointer in C
bipchulabmki
 
Pointers_c
Pointers_cPointers_c
Pointers_c
ahmed safwat
 
Pointers in C
Pointers in CPointers in C
Pointers in C
Kamal Acharya
 
Pointers in C
Pointers in CPointers in C
Pointers in C
Monishkanungo
 
Ponters
PontersPonters
Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in C
rgnikate
 
Used of Pointer in C++ Programming
Used of Pointer in C++ ProgrammingUsed of Pointer in C++ Programming
Used of Pointer in C++ Programming
Abdullah Jan
 
C++ Pointers And References
C++ Pointers And ReferencesC++ Pointers And References
C++ Pointers And References
verisan
 
Fundamentals of Pointers in C
Fundamentals of Pointers in CFundamentals of Pointers in C
Fundamentals of Pointers in C
ShivanshuVerma11
 
Pointer in c
Pointer in cPointer in c
Pointer in c
lavanya marichamy
 
Pointers in c
Pointers in cPointers in c
Pointers in c
Mohd Arif
 
C++ functions
C++ functionsC++ functions
C++ functions
Ganesh Hogade
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
Ashim Lamichhane
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
Wingston
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
tech4us
 
Pointer in c
Pointer in cPointer in c
Pointer in c
Imamul Kadir
 
Pointers in C
Pointers in CPointers in C
Pointers in C
Prabhu Govind
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3
karmuhtam
 
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
Uri Dekel
 

What's hot (20)

Data structure week 2
Data structure week 2Data structure week 2
Data structure week 2
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Pointers_c
Pointers_cPointers_c
Pointers_c
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Ponters
PontersPonters
Ponters
 
Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in C
 
Used of Pointer in C++ Programming
Used of Pointer in C++ ProgrammingUsed of Pointer in C++ Programming
Used of Pointer in C++ Programming
 
C++ Pointers And References
C++ Pointers And ReferencesC++ Pointers And References
C++ Pointers And References
 
Fundamentals of Pointers in C
Fundamentals of Pointers in CFundamentals of Pointers in C
Fundamentals of Pointers in C
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
C++ functions
C++ functionsC++ functions
C++ functions
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3
 
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
 

Similar to Pointer

PPS-POINTERS.pptx
PPS-POINTERS.pptxPPS-POINTERS.pptx
PPS-POINTERS.pptx
sajinis3
 
SPC Unit 3
SPC Unit 3SPC Unit 3
SPC Unit 3
SIMONTHOMAS S
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfEASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
sudhakargeruganti
 
Pointers in C
Pointers in CPointers in C
Pointers in C
Vijayananda Ratnam Ch
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
ArshiniGubbala3
 
Lect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer AbbasLect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer Abbas
Information Technology Center
 
Lect 8(pointers) Zaheer Abbas
Lect 8(pointers) Zaheer AbbasLect 8(pointers) Zaheer Abbas
Lect 8(pointers) Zaheer Abbas
Information Technology Center
 
pointers (1).ppt
pointers (1).pptpointers (1).ppt
pointers (1).ppt
Osmania University
 
Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptx
ajajkhan16
 
COM1407: Working with Pointers
COM1407: Working with PointersCOM1407: Working with Pointers
COM1407: Working with Pointers
Hemantha Kulathilake
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
janithlakshan1
 
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...
Jayanshu Gundaniya
 
20.C++Pointer.pptx
20.C++Pointer.pptx20.C++Pointer.pptx
20.C++Pointer.pptx
AtharvPotdar2
 
POINTERS IN C
POINTERS IN CPOINTERS IN C
POINTERS IN C
Neel Mungra
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
s170883BesiVyshnavi
 
Pointers
PointersPointers
Pointers
Vardhil Patel
 
Chapter 13.1.8
Chapter 13.1.8Chapter 13.1.8
Chapter 13.1.8
patcha535
 
Pointer in c
Pointer in cPointer in c
Pointer in c
sangrampatil81
 
Pointer in c
Pointer in c Pointer in c
Pointer in c
sangrampatil81
 

Similar to Pointer (20)

PPS-POINTERS.pptx
PPS-POINTERS.pptxPPS-POINTERS.pptx
PPS-POINTERS.pptx
 
SPC Unit 3
SPC Unit 3SPC Unit 3
SPC Unit 3
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
 
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfEASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
Lect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer AbbasLect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer Abbas
 
Lect 8(pointers) Zaheer Abbas
Lect 8(pointers) Zaheer AbbasLect 8(pointers) Zaheer Abbas
Lect 8(pointers) Zaheer Abbas
 
pointers (1).ppt
pointers (1).pptpointers (1).ppt
pointers (1).ppt
 
Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptx
 
COM1407: Working with Pointers
COM1407: Working with PointersCOM1407: Working with Pointers
COM1407: Working with Pointers
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
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...
 
20.C++Pointer.pptx
20.C++Pointer.pptx20.C++Pointer.pptx
20.C++Pointer.pptx
 
POINTERS IN C
POINTERS IN CPOINTERS IN C
POINTERS IN C
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
Pointers
PointersPointers
Pointers
 
Chapter 13.1.8
Chapter 13.1.8Chapter 13.1.8
Chapter 13.1.8
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Pointer in c
Pointer in c Pointer in c
Pointer in c
 

More from DharmaKumariBhandari

K map
K map K map
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,  De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
DharmaKumariBhandari
 
Loop's definition and practical code in C programming
Loop's definition and  practical code in C programming Loop's definition and  practical code in C programming
Loop's definition and practical code in C programming
DharmaKumariBhandari
 
About Array
About ArrayAbout Array
C programme presentation
C programme presentationC programme presentation
C programme presentation
DharmaKumariBhandari
 
social prospective in Education
social prospective in Educationsocial prospective in Education
social prospective in Education
DharmaKumariBhandari
 
Array
ArrayArray

More from DharmaKumariBhandari (7)

K map
K map K map
K map
 
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,  De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
 
Loop's definition and practical code in C programming
Loop's definition and  practical code in C programming Loop's definition and  practical code in C programming
Loop's definition and practical code in C programming
 
About Array
About ArrayAbout Array
About Array
 
C programme presentation
C programme presentationC programme presentation
C programme presentation
 
social prospective in Education
social prospective in Educationsocial prospective in Education
social prospective in Education
 
Array
ArrayArray
Array
 

Pointer

  • 1. Pointer A pointer is a variable that stores memory address. Like all other variables ,it also has a name, has to be declared and occupies some space in memory. It is called pointer because it points to a particular location in memory (by storing the address of that location). The expression having (*) operator is known as pointer expression. Pointer is the variable that points to the memory location of the next variable. So, we have to assign address of a variable to the pointer variable. Int a=5; Int *p1=&a; If we put *before p1, then, we can access the variable whose address is stored in p1. since p1 contains the address of variable a, we can access the variable a by writing *p1.
  • 2. What are Pointers? Pointers are different from other normal variables. While other normal variables store values, pointers are special variables that can hold the address of a variable. Since they store memory address of a variable, the pointers are very commonly said to “point to variables”.
  • 3. Pointer • A pointer is a variable which holds the address of the storage location value for another given variable. • C provides two operators & and * which allow pointers to be used in many versatile ways. *:- is the value of address eg.*a &:- is the address of variable eg. &a *(&a):- we are using the value which is inside of the address
  • 4. pointer arithmetic operations are allowed? • A pointer can be incremented (++) or decremented (--) • An integer may be added to a pointer (+ or +=) • An integer may be subtracted from a pointer (- or -=) • One pointer may be subtracted from another
  • 5. In c programming every variable keeps two type of value. 1. Contain of variable or value of variable. 2. Address of variable where it has stored in the memory. (1) Meaning of following simple pointer declaration and definition: int a=5; int * ptr; ptr=&a; Explanation: About variable a: 1. Name of variable : a 2. Value of variable which it keeps: 5 3. Address where it has stored in memory : 1025 (assume) About variable ptr: 4. Name of variable : ptr 5. Value of variable which it keeps: 1025 6. Address where it has stored in memory : 5000 (assume)
  • 6. A normal variable ‘var’ has a memory address of 1001 and holds a value 50. A pointer variable has its own address 2047 but stores 1001, which is the address of the variable ‘var’
  • 7. Another example: Int I, *j, **K; Here I is dinary int ,J is a pointer to an int , whereas K is a pointer to an integer pointer 3 65524 65522 i 65524 j 65522 65520 k
  • 8. For example a ) valid example Int *p; Int num; P=&num; b) Invalid example Int *p; Float num; P=&num; /*as pointer variable p can not store address of float variable*/
  • 9. Data type Integer Unsigned integer Octal Hexadecimal Float simple Float exponential Character string Conversion Charater D U O X F E C S
  • 10. #include <stdio.h> #include <conio.h> void main( ) { int u = 36; int *pu; /*pionter to an integer*/ clrscr(); pu=&u; /*assign address of u to pu*/ printf("nu=%d &u=%x *pu=%d",u,&u,*pu); getch(); }
  • 11. /* Illustration of pointer data type */ #include <stdio.h> #include <conio.h> void main( ) { int u = 36; int v; int *pu; /* pointer to an integer*/ int *pv; /* pointer to an integer*/ clrscr(); pu = &u; /* assign address of u to pu */ v = *pu; /* assign address of u to v */ pv = &v; /* assign address of v to pv */ printf("nu = %d n&u = %x npu = %x n*pu = %d", u,&u, pu, *pu); printf("nnv = %d n&v = %xn pv = %x n*pv = %d", v, &v, pv, *pv); getch();
  • 12. #include <stdio.h> #include <conio.h> void main() { int a,b,sum, *ptra,*ptrb; a=20; b=10; ptra =&a; ptrb=&b; sum=*ptra+*ptrb; printf("sum=%d",sum); getch(); } 1. WAP to add value stored in two variable using pointer