SlideShare a Scribd company logo
1 of 16
Pointer
• Pointer is a variable, that stores the address of another
variable.
• Syntax:
data_type *pointer_name;
• Here, the data type specifies the type of data to which the
pointer points.
• The pointer name specifies the name of the pointer. It must
preceded with an * (Asterisk).
Examples:
• int *iptr; // iptr is pointer to an integer variable
• float *fptr; // fptr is pointer to an float variable
• char *cptr; // cptr is a pointer to a character variable
Initialization of a pointer variable
• The process of assigning the address of another variable to a
pointer variable is known as initialization.
• A pointer can be assigned or initialized with the address of an
variable.
• A pointer variable cannot hold a non-address value.
• A pointer can be assigned or initialized with another pointer
of the same type.
• A pointer can be assigned or initialized with another pointer
of the same type. However, it is not possible to assign a
pointer of one type to a pointer of another type without
explicit type casting.
Example:
P=&n;
Initialization of a pointer variable
Example:
• P=&n;
• Where, ‘p’ contains the address of variable ‘n’. The data item
represented by ‘n’ can be accessed by ‘*p’.
• Where * is called the indirection operator.
• We can initialize a pointer variable while declaring it, as
given below.
int num=15;
int *iptr=# // Initialization while declaration
• In the above example, variable num is first declared and then
its address is stored in pointer variable iptr.
Pointer Operators
*  Represents the value
 Also called Indirection operator / Dereferencing
operator / Value of operator.
&  It represents the address.
 Also called as, direction operator / referencing
operator / Address of operator.
Pointer Example
#include<stdio.h>
void main()
{
int a=10,v;
int *p;
p=&a;
v=*p;
printf("Address of a is % un", p);
printf("Value is %d", v);
}
Void Pointer or Generic Pointer
• A void pointer is a generic pointer. (i.e) Means it has no
associated data type.
• A void pointer that can point to any data type and is known as
void pointer.
• A void pointer can hold address of any type and can be
“typecasted” to access the values.
• Syntax:
void *pointer_name; /* pointer to void*/
Example:
int i=5;
void *vptr;
vptr=&i;
printf(“Value of vptr =%d”, *(int*)vptr);
NULL Pointer
• A Null pointer is a special pointer that does not point to any
memory location.
• It represents an invalid memory location.
• It does not hold the address of any variable.
• It has numeric value 0.
• When a NULL value is assigned to a pointer the pointer is
considered as NULL pointer.
Declaration:
int *nptr=NULL;
or
int *nptr=0;
Pointers to Pointers
• In C, a pointer stores the address of another variable which in
turn can store address of another variable and so on.
• Therefore we can have a pointer that stores another pointer’s
address.
• Example:
int val=500, *ptr, **ptr_to_ptr;
ptr=&val;
ptr_to_ptr=&ptr;
Here, *ptr denotes an integer pointer.
**ptr_to_ptr denotes a pointer to an integer pointer.
This is known as multiplication indirections.
Pointers to Pointers (An Example)
#include<stdio.h>
#include<conio.h>
void main()
{
int a=50;
int *b;
int **c;
clrscr();
b=&a;
c=&b;
printf("n Value of a is %d ", a);
printf("n Value of a is %d", *(&a));
printf("n Value of a is %d", *b);
printf("n Value of a is %d", **c);
printf("n Value of b and
address of a= %u", b);
printf("n Address of a is %u", &a);
printf("n Address of b is %u", &b);
printf("n Address of a is %u", *c);
printf("n Address of b is %u", &b);
printf("n Address of b is %u", c);
printf("n Address of c is %u", &c);
getch();
}
Output:
Value of a is 50
Value of a is 50
Value of a is 50
Value of a is 50
Value of b and address of a= 65524
Address of a is 65524
Address of b is 65522
Address of a is 65524
Address of b is 65522
Address of b is 65522
Address of c is 65520
Relationship between Arrays and
Pointers
• The following relationships exist between arrays and pointers:
1. The name of an array refers to the address of the first element of the
array, i.e. an expression of array type decomposes to pointer type.
A program to depict the relationship between arrays and pointers
#include<stdio.h>
main()
{
int arr[3]={40,15,20};
printf("First element of array is at %p
n",arr);
printf("Second element of array is at %p
n",arr+1);
printf("Third element of array is at %p
n",arr+2);
}
OUTPUT:
First element of array is at 24D7;2242
Second element of array is at 24D7:2244
Third element of array is at 241J7:2248
Relationship between Arrays and
Pointers
• The name of an array refers to the address of the first element
of the array but there are two exceptions to this rule:
• a. When an array name is operand of sized operator it does
not decompose to the address of its first element.
Relationship between Arrays and Pointers
• In C language, any operation that involves array subscripting is done
by using pointers. The expression of form E1[E2] is automatically
converted into an equivalent expression of form *(E1+E2).
Array of Pointers
• Array of pointers is a collection of addresses.
• The addresses in an array of pointers could be the addresses
of isolated variables or the addresses of array elements or any
other addresses.
• Example:
int *p[3];
Pointers to an Array
• It is possible to create a pointer that points to a complete array
instead of pointing to the individual elements of an array.
Such a pointer is known as pointer to an array
• Example:
int (*p1)[3];
int (*p2)[2][2];

More Related Content

What's hot

What's hot (19)

Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Ponters
PontersPonters
Ponters
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
 
Lect 8(pointers) Zaheer Abbas
Lect 8(pointers) Zaheer AbbasLect 8(pointers) Zaheer Abbas
Lect 8(pointers) Zaheer Abbas
 
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
 
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...
 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
 
C pointers
C pointersC pointers
C pointers
 
C programming - Pointer and DMA
C programming - Pointer and DMAC programming - Pointer and DMA
C programming - Pointer and DMA
 
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
 
Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in C
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
 
Computer Science:Pointers in C
Computer Science:Pointers in CComputer Science:Pointers in C
Computer Science:Pointers in C
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1
 

Similar to Guide to C Pointers in 40 Characters

Similar to Guide to C Pointers in 40 Characters (20)

PPS-POINTERS.pptx
PPS-POINTERS.pptxPPS-POINTERS.pptx
PPS-POINTERS.pptx
 
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.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
4 Pointers.pptx
4 Pointers.pptx4 Pointers.pptx
4 Pointers.pptx
 
Pointer
PointerPointer
Pointer
 
Pointer introduction day1
Pointer introduction day1Pointer introduction day1
Pointer introduction day1
 
Pointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptxPointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptx
 
Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptx
 
pointers of the programming in c most efficient.pptx
pointers of the programming in c most efficient.pptxpointers of the programming in c most efficient.pptx
pointers of the programming in c most efficient.pptx
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
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
 
Pointers
PointersPointers
Pointers
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programming
 
pointers (1).ppt
pointers (1).pptpointers (1).ppt
pointers (1).ppt
 
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
 
Pointers
PointersPointers
Pointers
 
Pointers
PointersPointers
Pointers
 
NRG 106_Session 6_String&Pointer.pptx
NRG 106_Session 6_String&Pointer.pptxNRG 106_Session 6_String&Pointer.pptx
NRG 106_Session 6_String&Pointer.pptx
 
Pointers Notes.pptx
Pointers Notes.pptxPointers Notes.pptx
Pointers Notes.pptx
 

More from SIMONTHOMAS S

Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1SIMONTHOMAS S
 
IT6701-Information Management Unit 5
IT6701-Information Management Unit 5IT6701-Information Management Unit 5
IT6701-Information Management Unit 5SIMONTHOMAS S
 
IT6701-Information Management Unit 4
IT6701-Information Management Unit 4IT6701-Information Management Unit 4
IT6701-Information Management Unit 4SIMONTHOMAS S
 
IT6701-Information Management Unit 3
IT6701-Information Management Unit 3IT6701-Information Management Unit 3
IT6701-Information Management Unit 3SIMONTHOMAS S
 
IT6701-Information Management Unit 2
IT6701-Information Management Unit 2IT6701-Information Management Unit 2
IT6701-Information Management Unit 2SIMONTHOMAS S
 
IT6701-Information Management Unit 1
IT6701-Information Management Unit 1IT6701-Information Management Unit 1
IT6701-Information Management Unit 1SIMONTHOMAS S
 
CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5SIMONTHOMAS S
 
CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4SIMONTHOMAS S
 
CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3SIMONTHOMAS S
 
CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2SIMONTHOMAS S
 
CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1SIMONTHOMAS S
 

More from SIMONTHOMAS S (20)

Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5
 
Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2
 
Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1
 
Mg6088 spm unit-5
Mg6088 spm unit-5Mg6088 spm unit-5
Mg6088 spm unit-5
 
Mg6088 spm unit-4
Mg6088 spm unit-4Mg6088 spm unit-4
Mg6088 spm unit-4
 
Mg6088 spm unit-3
Mg6088 spm unit-3Mg6088 spm unit-3
Mg6088 spm unit-3
 
Mg6088 spm unit-2
Mg6088 spm unit-2Mg6088 spm unit-2
Mg6088 spm unit-2
 
Mg6088 spm unit-1
Mg6088 spm unit-1Mg6088 spm unit-1
Mg6088 spm unit-1
 
IT6701-Information Management Unit 5
IT6701-Information Management Unit 5IT6701-Information Management Unit 5
IT6701-Information Management Unit 5
 
IT6701-Information Management Unit 4
IT6701-Information Management Unit 4IT6701-Information Management Unit 4
IT6701-Information Management Unit 4
 
IT6701-Information Management Unit 3
IT6701-Information Management Unit 3IT6701-Information Management Unit 3
IT6701-Information Management Unit 3
 
IT6701-Information Management Unit 2
IT6701-Information Management Unit 2IT6701-Information Management Unit 2
IT6701-Information Management Unit 2
 
IT6701-Information Management Unit 1
IT6701-Information Management Unit 1IT6701-Information Management Unit 1
IT6701-Information Management Unit 1
 
CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5
 
CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4
 
CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3
 
CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2
 
CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1
 

Recently uploaded

Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
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
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
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
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
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
 

Recently uploaded (20)

Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
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...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
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
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
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
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 

Guide to C Pointers in 40 Characters

  • 1. Pointer • Pointer is a variable, that stores the address of another variable. • Syntax: data_type *pointer_name; • Here, the data type specifies the type of data to which the pointer points. • The pointer name specifies the name of the pointer. It must preceded with an * (Asterisk). Examples: • int *iptr; // iptr is pointer to an integer variable • float *fptr; // fptr is pointer to an float variable • char *cptr; // cptr is a pointer to a character variable
  • 2. Initialization of a pointer variable • The process of assigning the address of another variable to a pointer variable is known as initialization. • A pointer can be assigned or initialized with the address of an variable. • A pointer variable cannot hold a non-address value. • A pointer can be assigned or initialized with another pointer of the same type. • A pointer can be assigned or initialized with another pointer of the same type. However, it is not possible to assign a pointer of one type to a pointer of another type without explicit type casting. Example: P=&n;
  • 3. Initialization of a pointer variable Example: • P=&n; • Where, ‘p’ contains the address of variable ‘n’. The data item represented by ‘n’ can be accessed by ‘*p’. • Where * is called the indirection operator. • We can initialize a pointer variable while declaring it, as given below. int num=15; int *iptr=&num; // Initialization while declaration • In the above example, variable num is first declared and then its address is stored in pointer variable iptr.
  • 4. Pointer Operators *  Represents the value  Also called Indirection operator / Dereferencing operator / Value of operator. &  It represents the address.  Also called as, direction operator / referencing operator / Address of operator.
  • 5.
  • 6.
  • 7. Pointer Example #include<stdio.h> void main() { int a=10,v; int *p; p=&a; v=*p; printf("Address of a is % un", p); printf("Value is %d", v); }
  • 8. Void Pointer or Generic Pointer • A void pointer is a generic pointer. (i.e) Means it has no associated data type. • A void pointer that can point to any data type and is known as void pointer. • A void pointer can hold address of any type and can be “typecasted” to access the values. • Syntax: void *pointer_name; /* pointer to void*/ Example: int i=5; void *vptr; vptr=&i; printf(“Value of vptr =%d”, *(int*)vptr);
  • 9. NULL Pointer • A Null pointer is a special pointer that does not point to any memory location. • It represents an invalid memory location. • It does not hold the address of any variable. • It has numeric value 0. • When a NULL value is assigned to a pointer the pointer is considered as NULL pointer. Declaration: int *nptr=NULL; or int *nptr=0;
  • 10. Pointers to Pointers • In C, a pointer stores the address of another variable which in turn can store address of another variable and so on. • Therefore we can have a pointer that stores another pointer’s address. • Example: int val=500, *ptr, **ptr_to_ptr; ptr=&val; ptr_to_ptr=&ptr; Here, *ptr denotes an integer pointer. **ptr_to_ptr denotes a pointer to an integer pointer. This is known as multiplication indirections.
  • 11. Pointers to Pointers (An Example) #include<stdio.h> #include<conio.h> void main() { int a=50; int *b; int **c; clrscr(); b=&a; c=&b; printf("n Value of a is %d ", a); printf("n Value of a is %d", *(&a)); printf("n Value of a is %d", *b); printf("n Value of a is %d", **c); printf("n Value of b and address of a= %u", b); printf("n Address of a is %u", &a); printf("n Address of b is %u", &b); printf("n Address of a is %u", *c); printf("n Address of b is %u", &b); printf("n Address of b is %u", c); printf("n Address of c is %u", &c); getch(); } Output: Value of a is 50 Value of a is 50 Value of a is 50 Value of a is 50 Value of b and address of a= 65524 Address of a is 65524 Address of b is 65522 Address of a is 65524 Address of b is 65522 Address of b is 65522 Address of c is 65520
  • 12. Relationship between Arrays and Pointers • The following relationships exist between arrays and pointers: 1. The name of an array refers to the address of the first element of the array, i.e. an expression of array type decomposes to pointer type. A program to depict the relationship between arrays and pointers #include<stdio.h> main() { int arr[3]={40,15,20}; printf("First element of array is at %p n",arr); printf("Second element of array is at %p n",arr+1); printf("Third element of array is at %p n",arr+2); } OUTPUT: First element of array is at 24D7;2242 Second element of array is at 24D7:2244 Third element of array is at 241J7:2248
  • 13. Relationship between Arrays and Pointers • The name of an array refers to the address of the first element of the array but there are two exceptions to this rule: • a. When an array name is operand of sized operator it does not decompose to the address of its first element.
  • 14. Relationship between Arrays and Pointers • In C language, any operation that involves array subscripting is done by using pointers. The expression of form E1[E2] is automatically converted into an equivalent expression of form *(E1+E2).
  • 15. Array of Pointers • Array of pointers is a collection of addresses. • The addresses in an array of pointers could be the addresses of isolated variables or the addresses of array elements or any other addresses. • Example: int *p[3];
  • 16. Pointers to an Array • It is possible to create a pointer that points to a complete array instead of pointing to the individual elements of an array. Such a pointer is known as pointer to an array • Example: int (*p1)[3]; int (*p2)[2][2];