SlideShare a Scribd company logo
1 of 24
ā€˜*ā€™ , ā€˜&ā€™ ļƒ  Pointers In C
What is a Pointer ?
POINTERS
Point to here, point to there, point to that, point
to this, and point to nothing!
well, they are just memory addresses!!??
ā€¢In a generic sense, a ā€œpointerā€ is anything that tells
us where something can be found.
ā€“Addresses in the phone book
ā€“URLs for webpages
ā€“Road signs
C Pointer Variables
To declare a pointer variable, we must do
two things
ā€“ Use the ā€œ*ā€ (star) character to indicate
that the variable being defined is a
pointer type.
ā€“ Indicate the type of variable to which
the pointer will point (the pointee).
This is necessary because C provides
operations on pointers (e.g., *, ++,
etc) whose meaning depends on the
type of the pointee.
ā€¢General declaration of a pointer
type *nameOfPointer;
Operators used in Pointers
* &
AddressDereferencing
(Address of)(Value of)
Int i=3;
Address of ā€˜iā€™ Value of ā€˜iā€™
X1000 x1004 x1008 x100c x1010 x1014
variable
i
3
(Value of i)
Address of i
ā€˜&iā€™ ā€˜*iā€™
The value ā€˜3ā€™ is saved in the memory location ā€˜x100cā€™
Syntax for pointers
(pointer type declaration)
type *identifier ;
Example
Char *cp ;
Int *ip ;
Double *dp ;
Pointer Assignment
Int i = 1 , *ip ; //pointer declaration
ip = &i ; //pointer assignment
*ip = 3 ; //pointer assignment
49/51
ļ‚§ Other pointer declarations that you may find and can make
you confused are listed below.
Ā Pointer declaration Description
intĀ Ā Ā *x x is a pointer to int data type.
intĀ Ā Ā *x[10] x is an array[10] of pointer to int data type.
intĀ Ā Ā *(x[10]) x is an array[10] of pointer to int data type.
intĀ Ā Ā **x
x is a pointer to a pointer to an int data type ā€“ double
pointers.
intĀ Ā Ā (*x)[10] x is a pointer to an array[10] of int data type.
intĀ Ā Ā *funct() funct() is a function returning an integer pointer.
intĀ Ā Ā (*funct)()
funct() is a pointer to a function returning int data type ā€“
quite familiar constructs.
intĀ Ā Ā (*(*funct())
[10])()
funct() is a function returning pointer to an array[10]
of pointers to functions returning int.
intĀ Ā Ā (*(*x[4])())
[5]
x is an array[4] of pointers to functions returning pointers
to array[5] of int.
www.tenouk.com, Ā©
Pointer Arithmetic
Lets take this example program
#include<stdio.h>
Void main()
{
Int a [5]={1,2,3,4,5} , b , *pt ;
pt = &a[0];
pt = pt + 4 ;
b=a[0] ;
b+=4 ;
}
a[0]
X1000 x1004 x1008 x100c x1010
X1000 x1004 x1008 x100c x1010
pt
a[2]a[1] a[4]a[3]
a[0] a[2]a[1] a[4]a[3]
b
b = 1
b=1+4
b= 5
Lets Take an Example and See how pointers work
#include<stdio.h>
Void main()
{
Int i=3;
Int *j;
j=&i;
Printf(ā€œi=%dā€i);
Printf(ā€œ*j=%dā€*j);
}
X1000 x1004 x1008 x100c x1010 x1014
3
M
e
m
o
r
y
variabl
es Int iInt *j
Int i=3;
Int *j;
j = &i;
x100c
Create an integer variable ā€˜iā€™ and initialize it to 3
Create a pointer variable ā€˜jā€™- create value of ā€˜jā€™
Initialize the pointer value of ā€˜jā€™ to the address of ā€˜iā€™
X1000 x1004 x1008 x100c x1010 x1014
M
e
m
o
r
y
variables Int iInt *j
Output screen
Printf(ā€œi=%dā€ i);
We know j=&i
So ļƒ  *j=*(&i) value of (address of
i)
(i.e.) value in address (x100c)
Printf(ā€œi=%dā€ i);
i=3
*j=3
Printf(ā€œ*j=%dā€ *j);Printf(ā€œ*j=%dā€ *j);
x100c
33
Void main()
{
int num=10;
int* pnum=NULL;
pnum = &num;
*pnum += 20;
printf("nNumber = %d", num);
printf("nPointer Number = %d", *pnum);
}
Predict the output of this code
Number = 10
Pointer Number = 30
int a[10] = {1,2,3,4,5,6,7,8,9,12} ,*p, *q , i;
p = &a[2];
q = &a[5];
i = *q - *p;
Printf(ā€œThe value of i is %dā€ i );
i = *p - *q;
Printf(ā€œThe value of i is %dā€ i );
a[2] = a[5] = 0;
Printf(ā€œThe value of i is %dā€ i );
Work to your Brain
The value of i is 3
The value of i is -3
The value of i is 0
int a[10] = { 2,3,4,5,6,7,8,9,1,0 }, *p, *q;
p = &a[2];
q = p + 3;
p = q ā€“ 1;
p+ + ;
Printf(ā€œThe value of p and q are : %d , %dā€ *p,*q);
Work to your Brain
The value of p and q are : 7 , 7
int main()
{
int x[2]={1,2},y[2]={3,4};
int small,big;
small=&x[0];
big=&y[0];
min_max(&small,&big);
printf(ā€œsmall%d big%d",*small,*big);
return 0;
}
min_max(int *a,int *b)
{
a++;
b++;
return (*a,*b);
}
Work to your Brain
Small 2 big 4
Pointer in C

More Related Content

What's hot

Pointers in c
Pointers in cPointers in c
Pointers in cMohd Arif
Ā 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language Mohamed Loey
Ā 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareGagan Deep
Ā 
Pointers in c language
Pointers in c languagePointers in c language
Pointers in c languageTanmay Modi
Ā 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C ProgrammingDevoAjit Gupta
Ā 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Languagemadan reddy
Ā 
Strings in c++
Strings in c++Strings in c++
Strings in c++Neeru Mittal
Ā 
Structure in c language
Structure in c languageStructure in c language
Structure in c languagesangrampatil81
Ā 
Need of OOPs and Programming,pop vs oop
Need of OOPs and Programming,pop vs oopNeed of OOPs and Programming,pop vs oop
Need of OOPs and Programming,pop vs oopJanani Selvaraj
Ā 
POINTERS IN C
POINTERS IN CPOINTERS IN C
POINTERS IN CNeel Mungra
Ā 
358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6sumitbardhan
Ā 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
Ā 
detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c languagegourav kottawar
Ā 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)Ritika Sharma
Ā 

What's hot (20)

Pointers in c
Pointers in cPointers in c
Pointers in c
Ā 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
Ā 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
Ā 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
Ā 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
Ā 
Function in C program
Function in C programFunction in C program
Function in C program
Ā 
Pointers in c language
Pointers in c languagePointers in c language
Pointers in c language
Ā 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
Ā 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
Ā 
Strings in c++
Strings in c++Strings in c++
Strings in c++
Ā 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
Ā 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
Ā 
Function C++
Function C++ Function C++
Function C++
Ā 
C keywords and identifiers
C keywords and identifiersC keywords and identifiers
C keywords and identifiers
Ā 
Need of OOPs and Programming,pop vs oop
Need of OOPs and Programming,pop vs oopNeed of OOPs and Programming,pop vs oop
Need of OOPs and Programming,pop vs oop
Ā 
POINTERS IN C
POINTERS IN CPOINTERS IN C
POINTERS IN C
Ā 
358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6
Ā 
Functions in c language
Functions in c language Functions in c language
Functions in c language
Ā 
detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
Ā 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
Ā 

Viewers also liked

C programming - Pointer and DMA
C programming - Pointer and DMAC programming - Pointer and DMA
C programming - Pointer and DMAAchyut Devkota
Ā 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in cPrabhu Govind
Ā 
Dynamic memory allocation(memory,allocation,memory allocatin,calloc,malloc,re...
Dynamic memory allocation(memory,allocation,memory allocatin,calloc,malloc,re...Dynamic memory allocation(memory,allocation,memory allocatin,calloc,malloc,re...
Dynamic memory allocation(memory,allocation,memory allocatin,calloc,malloc,re...Mangalayatan university
Ā 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++Tech_MX
Ā 

Viewers also liked (8)

C programming - Pointer and DMA
C programming - Pointer and DMAC programming - Pointer and DMA
C programming - Pointer and DMA
Ā 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
Ā 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
Ā 
Ponters
PontersPonters
Ponters
Ā 
Dynamic memory allocation(memory,allocation,memory allocatin,calloc,malloc,re...
Dynamic memory allocation(memory,allocation,memory allocatin,calloc,malloc,re...Dynamic memory allocation(memory,allocation,memory allocatin,calloc,malloc,re...
Dynamic memory allocation(memory,allocation,memory allocatin,calloc,malloc,re...
Ā 
Pointers
PointersPointers
Pointers
Ā 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
Ā 
C++ Pointers
C++ PointersC++ Pointers
C++ Pointers
Ā 

Similar to Pointer in C

Pointers in C
Pointers in CPointers in C
Pointers in Cguestdc3f16
Ā 
Pointers in c
Pointers in cPointers in c
Pointers in cguestb811fb
Ā 
Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxajajkhan16
Ā 
Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minalminal kumar soni
Ā 
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.pdfsudhakargeruganti
Ā 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanMohammadSalman129
Ā 
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptchintuyadav19
Ā 
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingMca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
Ā 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingRai University
Ā 
Ch6 pointers (latest)
Ch6 pointers (latest)Ch6 pointers (latest)
Ch6 pointers (latest)Hattori Sidek
Ā 
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingBtech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
Ā 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingRai University
Ā 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programmingnmahi96
Ā 

Similar to Pointer in C (20)

Pointers in C
Pointers in CPointers in C
Pointers in C
Ā 
Pointers in c
Pointers in cPointers in c
Pointers in c
Ā 
Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptx
Ā 
Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minal
Ā 
Pointers
PointersPointers
Pointers
Ā 
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
Ā 
Lecture 18 - Pointers
Lecture 18 - PointersLecture 18 - Pointers
Lecture 18 - Pointers
Ā 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
Ā 
Advanced pointers
Advanced pointersAdvanced pointers
Advanced pointers
Ā 
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
Ā 
Pointers in C
Pointers in CPointers in C
Pointers in C
Ā 
Ch 7-pointers
Ch 7-pointersCh 7-pointers
Ch 7-pointers
Ā 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
Ā 
Pointers
PointersPointers
Pointers
Ā 
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingMca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
Ā 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
Ā 
Ch6 pointers (latest)
Ch6 pointers (latest)Ch6 pointers (latest)
Ch6 pointers (latest)
Ā 
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingBtech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
Ā 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
Ā 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programming
Ā 

More from Sonya Akter Rupa

Synchronous Counter in Digital Logic Device
Synchronous Counter in Digital Logic DeviceSynchronous Counter in Digital Logic Device
Synchronous Counter in Digital Logic DeviceSonya Akter Rupa
Ā 
Method Overloading in Java
Method Overloading in JavaMethod Overloading in Java
Method Overloading in JavaSonya Akter Rupa
Ā 
Enviremental Pollution
Enviremental PollutionEnviremental Pollution
Enviremental PollutionSonya Akter Rupa
Ā 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C ProgrammingSonya Akter Rupa
Ā 
File in C Programming
File in C ProgrammingFile in C Programming
File in C ProgrammingSonya Akter Rupa
Ā 
One Dimentional Array
One Dimentional ArrayOne Dimentional Array
One Dimentional ArraySonya Akter Rupa
Ā 
Two Dimentional Array
Two Dimentional ArrayTwo Dimentional Array
Two Dimentional ArraySonya Akter Rupa
Ā 
The population is resource or burden for Bangladesh
The population is resource or burden for BangladeshThe population is resource or burden for Bangladesh
The population is resource or burden for BangladeshSonya Akter Rupa
Ā 
Spherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics IISpherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics IISonya Akter Rupa
Ā 

More from Sonya Akter Rupa (9)

Synchronous Counter in Digital Logic Device
Synchronous Counter in Digital Logic DeviceSynchronous Counter in Digital Logic Device
Synchronous Counter in Digital Logic Device
Ā 
Method Overloading in Java
Method Overloading in JavaMethod Overloading in Java
Method Overloading in Java
Ā 
Enviremental Pollution
Enviremental PollutionEnviremental Pollution
Enviremental Pollution
Ā 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
Ā 
File in C Programming
File in C ProgrammingFile in C Programming
File in C Programming
Ā 
One Dimentional Array
One Dimentional ArrayOne Dimentional Array
One Dimentional Array
Ā 
Two Dimentional Array
Two Dimentional ArrayTwo Dimentional Array
Two Dimentional Array
Ā 
The population is resource or burden for Bangladesh
The population is resource or burden for BangladeshThe population is resource or burden for Bangladesh
The population is resource or burden for Bangladesh
Ā 
Spherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics IISpherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics II
Ā 

Recently uploaded

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
Ā 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
Ā 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
Ā 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
Ā 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
Ā 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
Ā 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
Ā 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
Ā 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
Ā 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
Ā 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
Ā 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
Ā 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
Ā 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
Ā 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniquesugginaramesh
Ā 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
Ā 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
Ā 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
Ā 

Recently uploaded (20)

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
Ā 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Ā 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
Ā 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Ā 
young call girls in Green ParkšŸ” 9953056974 šŸ” escort Service
young call girls in Green ParkšŸ” 9953056974 šŸ” escort Serviceyoung call girls in Green ParkšŸ” 9953056974 šŸ” escort Service
young call girls in Green ParkšŸ” 9953056974 šŸ” escort Service
Ā 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
Ā 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
Ā 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
Ā 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
Ā 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
Ā 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
Ā 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
Ā 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
Ā 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
Ā 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
Ā 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
Ā 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniques
Ā 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
Ā 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
Ā 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
Ā 

Pointer in C

  • 1. ā€˜*ā€™ , ā€˜&ā€™ ļƒ  Pointers In C
  • 2.
  • 3. What is a Pointer ?
  • 4. POINTERS Point to here, point to there, point to that, point to this, and point to nothing! well, they are just memory addresses!!?? ā€¢In a generic sense, a ā€œpointerā€ is anything that tells us where something can be found. ā€“Addresses in the phone book ā€“URLs for webpages ā€“Road signs
  • 5. C Pointer Variables To declare a pointer variable, we must do two things ā€“ Use the ā€œ*ā€ (star) character to indicate that the variable being defined is a pointer type. ā€“ Indicate the type of variable to which the pointer will point (the pointee). This is necessary because C provides operations on pointers (e.g., *, ++, etc) whose meaning depends on the type of the pointee. ā€¢General declaration of a pointer type *nameOfPointer;
  • 6. Operators used in Pointers * & AddressDereferencing (Address of)(Value of)
  • 7. Int i=3; Address of ā€˜iā€™ Value of ā€˜iā€™ X1000 x1004 x1008 x100c x1010 x1014 variable i 3 (Value of i) Address of i ā€˜&iā€™ ā€˜*iā€™ The value ā€˜3ā€™ is saved in the memory location ā€˜x100cā€™
  • 8. Syntax for pointers (pointer type declaration) type *identifier ; Example Char *cp ; Int *ip ; Double *dp ;
  • 9. Pointer Assignment Int i = 1 , *ip ; //pointer declaration ip = &i ; //pointer assignment *ip = 3 ; //pointer assignment
  • 10. 49/51 ļ‚§ Other pointer declarations that you may find and can make you confused are listed below. Ā Pointer declaration Description intĀ Ā Ā *x x is a pointer to int data type. intĀ Ā Ā *x[10] x is an array[10] of pointer to int data type. intĀ Ā Ā *(x[10]) x is an array[10] of pointer to int data type. intĀ Ā Ā **x x is a pointer to a pointer to an int data type ā€“ double pointers. intĀ Ā Ā (*x)[10] x is a pointer to an array[10] of int data type. intĀ Ā Ā *funct() funct() is a function returning an integer pointer. intĀ Ā Ā (*funct)() funct() is a pointer to a function returning int data type ā€“ quite familiar constructs. intĀ Ā Ā (*(*funct()) [10])() funct() is a function returning pointer to an array[10] of pointers to functions returning int. intĀ Ā Ā (*(*x[4])()) [5] x is an array[4] of pointers to functions returning pointers to array[5] of int. www.tenouk.com, Ā©
  • 11. Pointer Arithmetic Lets take this example program #include<stdio.h> Void main() { Int a [5]={1,2,3,4,5} , b , *pt ; pt = &a[0]; pt = pt + 4 ; b=a[0] ; b+=4 ; } a[0] X1000 x1004 x1008 x100c x1010 X1000 x1004 x1008 x100c x1010 pt a[2]a[1] a[4]a[3] a[0] a[2]a[1] a[4]a[3] b b = 1 b=1+4 b= 5
  • 12. Lets Take an Example and See how pointers work #include<stdio.h> Void main() { Int i=3; Int *j; j=&i; Printf(ā€œi=%dā€i); Printf(ā€œ*j=%dā€*j); }
  • 13. X1000 x1004 x1008 x100c x1010 x1014 3 M e m o r y variabl es Int iInt *j Int i=3; Int *j; j = &i; x100c Create an integer variable ā€˜iā€™ and initialize it to 3 Create a pointer variable ā€˜jā€™- create value of ā€˜jā€™ Initialize the pointer value of ā€˜jā€™ to the address of ā€˜iā€™
  • 14. X1000 x1004 x1008 x100c x1010 x1014 M e m o r y variables Int iInt *j Output screen Printf(ā€œi=%dā€ i); We know j=&i So ļƒ  *j=*(&i) value of (address of i) (i.e.) value in address (x100c) Printf(ā€œi=%dā€ i); i=3 *j=3 Printf(ā€œ*j=%dā€ *j);Printf(ā€œ*j=%dā€ *j); x100c 33
  • 15. Void main() { int num=10; int* pnum=NULL; pnum = &num; *pnum += 20; printf("nNumber = %d", num); printf("nPointer Number = %d", *pnum); } Predict the output of this code
  • 16. Number = 10 Pointer Number = 30
  • 17.
  • 18. int a[10] = {1,2,3,4,5,6,7,8,9,12} ,*p, *q , i; p = &a[2]; q = &a[5]; i = *q - *p; Printf(ā€œThe value of i is %dā€ i ); i = *p - *q; Printf(ā€œThe value of i is %dā€ i ); a[2] = a[5] = 0; Printf(ā€œThe value of i is %dā€ i ); Work to your Brain
  • 19. The value of i is 3 The value of i is -3 The value of i is 0
  • 20. int a[10] = { 2,3,4,5,6,7,8,9,1,0 }, *p, *q; p = &a[2]; q = p + 3; p = q ā€“ 1; p+ + ; Printf(ā€œThe value of p and q are : %d , %dā€ *p,*q); Work to your Brain
  • 21. The value of p and q are : 7 , 7
  • 22. int main() { int x[2]={1,2},y[2]={3,4}; int small,big; small=&x[0]; big=&y[0]; min_max(&small,&big); printf(ā€œsmall%d big%d",*small,*big); return 0; } min_max(int *a,int *b) { a++; b++; return (*a,*b); } Work to your Brain