SlideShare a Scribd company logo
NAME:- DARJI MIT BIPINBHAI
TOPICK : - POINTER TO POINTER
POINTER TO ARRAY
ARRAY TO POINTER
POINTER TO POINTER
 A pointer to a pointer is a form of multiple
indirection, or a chain of pointers. Normally, a pointer
contains the address of a variable.
 When we define a pointer to a pointer, the first pointer
contains the address of the second pointer, which
points to the location that contains the actual value as
shown below.
 A pointer to a pointer is a form of multiple indirection,
or a chain of pointers. Normally, a pointer contains the
address of a variable. When we define a pointer to a
pointer, the first pointer contains the address of the
second pointer, which points to the location that
contains the actual value as shown below.
.
−
I ptr1
ptr2
 A variable that is a pointer to a pointer must be
declared as such. This is done by placing an additional
asterisk in front of its name. For example, the following
declaration declares a pointer to a pointer of type int −
int **var
When a target value is indirectly pointed to by a pointer to a
pointer, accessing that value requires that the asterisk
operator be applied twice, as is show below in the example-;
#include <stdio.h>
Int main (){
int var ;
int*ptr;
int**pptr;
var=3003
/*take the address of var */
ptr = &var;
/*take the address of ptr using address of operator&*/
pptr =&ptr;
/*take the value using pptr*/
printf(“value of var %dn”,var);
print f (“value available at *ptr =%dn,*ptr);
print f(“value available at **pptr =%dn”,**pptr);
return 𝜃;
}
When the above code is compiled and executes , it produces the
following result
 When an array is declared, the compiler allocates a base
address and sufficient amount of storage is the location
of the first element(index 0) of the array. The compiler also
defines the array name as a constant pointer to the first
element. Suppose we declare an array x as follows:
int X[5]={1,2,3,4,5};
 Suppose the base address of x is 1000 and assuming
that each integer requires two bytes, the five elements
will be stored as follows:
Elements X[0] X[1] X[2] X[3]
X[4]
value
Address
Base address
the name X is defined as a constant pointer pointing to the first element,
X[0] and therefore the value of X is 1000, the location where X[0] is stored. This
is,
X= &x [0] =1000
1 1000 2 1002 3 1004 4 1008
 if we declare p as an integer pointer, then we can
make the pointer p to point to the array x by the
following assignment:
p=x;
This is equivalent to
p=&x[0];
 Now, we can access every value of X using p++ to
move from one element to another. The relationship
between p and X is shown as :
p=&x[0](=1000)
p+1=&x[1](=1002)
p+2=&x[2](=1004)
p+3=&x[3](=1006)
p+4=&x[4](=1008)
 You may notice that the address of an
element is calculated using its index and the
scale factor of the data type. For instance,
address of x[3] = base address+(3x scale factor of int)
=1000+(3×2) 1006
 When handing array, instead of using array
indexing, we can pointers to access array elements.
Note that *(p+3) gives the value of x[3]. The pointer
accessing method is much faster than array indexing.
 One important use of pointer is in handling of a
table of strings. Consider the following array of
strings:
char name [3] [25];
 This says that the name is a table containing three
names, each with a maximum length of 25
characters (including null character). The total
storage requirements for the name table are 75
bytes.
 We know that rarely the individual strings will be of
equal lengths. Therefore, instead of making each row
a fixed number of characters, we can make it a
pointer to a string of varying length.
For example,
char *name[3] = {
“New Zeland”,
Australia”,
“India”
};
declares name to be an array of three pointers to
characters, each pointer pointing to a particular name as:
name[0] New zeland
name[1] Australia
name[2] India
This declaration allocates only 28 bytes, sufficient to hold
all the characters as shown
The following statement would print out all the three
names;
for(i=0; i<=2; i++)
printf(“%sn “, name[i]);
 To access the jth character in the ith name, we may
write as
*(name[i]+j)
 The character array with the rows of varying length
are called ragged array’ and are better handled by
pointers.
 Remember the difference between the notations *p[3]
and (*p)[3].Since *has a lower precedence than [],*p[3]
declares p as an array of 3 pointers while (*p)[3]
declares p as a pointer to an array of three elements.
N e w Z e a l a n d 0
A u s t r a l i a 0
I n d i a 0
Pointer in c

More Related Content

PPTX
PPTX
C programming - Pointer and DMA
PPT
Introduction to pointers and memory management in C
PPTX
Fundamentals of Pointers in C
PDF
Pointers In C
PPTX
Computer Science:Pointers in C
PPTX
Presentation on pointer.
PPTX
ppt on pointers
C programming - Pointer and DMA
Introduction to pointers and memory management in C
Fundamentals of Pointers in C
Pointers In C
Computer Science:Pointers in C
Presentation on pointer.
ppt on pointers

What's hot (18)

PPTX
Pointer in c
PPTX
Pointers in c v5 12102017 1
PPTX
Pointers in c - Mohammad Salman
PDF
Pointers in C
PPT
Pointers in c
PPT
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
PPTX
Pointer in c program
PPTX
Pointers in C Programming
PPTX
Pointers in C Language
PPTX
Unit 8. Pointers
PPT
C pointers
PPT
PDF
C Pointers
PDF
Pointers
PPT
pointers
PPTX
C programming - Pointers
PPTX
Pointer in c
PPT
Pointers (Pp Tminimizer)
Pointer in c
Pointers in c v5 12102017 1
Pointers in c - Mohammad Salman
Pointers in C
Pointers in c
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Pointer in c program
Pointers in C Programming
Pointers in C Language
Unit 8. Pointers
C pointers
C Pointers
Pointers
pointers
C programming - Pointers
Pointer in c
Pointers (Pp Tminimizer)
Ad

Similar to Pointer in c (20)

PPTX
Lecture 9
PDF
Homework Assignment – Array Technical DocumentWrite a technical .pdf
PDF
C pointers and references
PPTX
3.ArraysandPointers.pptx
PPT
13092119343434343432232323121211213435554
PPTX
C++ - UNIT_-_IV.pptx which contains details about Pointers
PDF
Unit ii data structure-converted
DOCX
Array assignment
PPS
C programming session 05
PPTX
Lecture 7
PPT
Lect 9(pointers) Zaheer Abbas
PPTX
Array, string and pointer
PPTX
arraytypes of array and pointer string in c++.pptx
PDF
Module7
PPT
Lect 8(pointers) Zaheer Abbas
PPTX
Pointers
PPTX
Pointers in c++
PPTX
M-1-Pointers-2.pptx by tamil nadu institutions
Lecture 9
Homework Assignment – Array Technical DocumentWrite a technical .pdf
C pointers and references
3.ArraysandPointers.pptx
13092119343434343432232323121211213435554
C++ - UNIT_-_IV.pptx which contains details about Pointers
Unit ii data structure-converted
Array assignment
C programming session 05
Lecture 7
Lect 9(pointers) Zaheer Abbas
Array, string and pointer
arraytypes of array and pointer string in c++.pptx
Module7
Lect 8(pointers) Zaheer Abbas
Pointers
Pointers in c++
M-1-Pointers-2.pptx by tamil nadu institutions
Ad

Recently uploaded (20)

PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
master seminar digital applications in india
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Updated Idioms and Phrasal Verbs in English subject
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Classroom Observation Tools for Teachers
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Cell Types and Its function , kingdom of life
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
UNIT III MENTAL HEALTH NURSING ASSESSMENT
2.FourierTransform-ShortQuestionswithAnswers.pdf
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Weekly quiz Compilation Jan -July 25.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
master seminar digital applications in india
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Updated Idioms and Phrasal Verbs in English subject
Orientation - ARALprogram of Deped to the Parents.pptx
01-Introduction-to-Information-Management.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Microbial diseases, their pathogenesis and prophylaxis
Classroom Observation Tools for Teachers
A systematic review of self-coping strategies used by university students to ...
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Supply Chain Operations Speaking Notes -ICLT Program
Cell Types and Its function , kingdom of life
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE

Pointer in c

  • 1. NAME:- DARJI MIT BIPINBHAI TOPICK : - POINTER TO POINTER POINTER TO ARRAY ARRAY TO POINTER
  • 2. POINTER TO POINTER  A pointer to a pointer is a form of multiple indirection, or a chain of pointers. Normally, a pointer contains the address of a variable.  When we define a pointer to a pointer, the first pointer contains the address of the second pointer, which points to the location that contains the actual value as shown below.  A pointer to a pointer is a form of multiple indirection, or a chain of pointers. Normally, a pointer contains the address of a variable. When we define a pointer to a pointer, the first pointer contains the address of the second pointer, which points to the location that contains the actual value as shown below.
  • 4.  A variable that is a pointer to a pointer must be declared as such. This is done by placing an additional asterisk in front of its name. For example, the following declaration declares a pointer to a pointer of type int − int **var When a target value is indirectly pointed to by a pointer to a pointer, accessing that value requires that the asterisk operator be applied twice, as is show below in the example-;
  • 5. #include <stdio.h> Int main (){ int var ; int*ptr; int**pptr; var=3003 /*take the address of var */ ptr = &var; /*take the address of ptr using address of operator&*/ pptr =&ptr; /*take the value using pptr*/ printf(“value of var %dn”,var); print f (“value available at *ptr =%dn,*ptr); print f(“value available at **pptr =%dn”,**pptr); return 𝜃; } When the above code is compiled and executes , it produces the following result
  • 6.  When an array is declared, the compiler allocates a base address and sufficient amount of storage is the location of the first element(index 0) of the array. The compiler also defines the array name as a constant pointer to the first element. Suppose we declare an array x as follows: int X[5]={1,2,3,4,5};  Suppose the base address of x is 1000 and assuming that each integer requires two bytes, the five elements will be stored as follows: Elements X[0] X[1] X[2] X[3] X[4] value Address Base address the name X is defined as a constant pointer pointing to the first element, X[0] and therefore the value of X is 1000, the location where X[0] is stored. This is, X= &x [0] =1000 1 1000 2 1002 3 1004 4 1008
  • 7.  if we declare p as an integer pointer, then we can make the pointer p to point to the array x by the following assignment: p=x; This is equivalent to p=&x[0];  Now, we can access every value of X using p++ to move from one element to another. The relationship between p and X is shown as : p=&x[0](=1000) p+1=&x[1](=1002) p+2=&x[2](=1004) p+3=&x[3](=1006) p+4=&x[4](=1008)
  • 8.  You may notice that the address of an element is calculated using its index and the scale factor of the data type. For instance, address of x[3] = base address+(3x scale factor of int) =1000+(3×2) 1006  When handing array, instead of using array indexing, we can pointers to access array elements. Note that *(p+3) gives the value of x[3]. The pointer accessing method is much faster than array indexing.
  • 9.  One important use of pointer is in handling of a table of strings. Consider the following array of strings: char name [3] [25];  This says that the name is a table containing three names, each with a maximum length of 25 characters (including null character). The total storage requirements for the name table are 75 bytes.  We know that rarely the individual strings will be of equal lengths. Therefore, instead of making each row a fixed number of characters, we can make it a pointer to a string of varying length.
  • 10. For example, char *name[3] = { “New Zeland”, Australia”, “India” }; declares name to be an array of three pointers to characters, each pointer pointing to a particular name as: name[0] New zeland name[1] Australia name[2] India This declaration allocates only 28 bytes, sufficient to hold all the characters as shown
  • 11. The following statement would print out all the three names; for(i=0; i<=2; i++) printf(“%sn “, name[i]);  To access the jth character in the ith name, we may write as *(name[i]+j)  The character array with the rows of varying length are called ragged array’ and are better handled by pointers.  Remember the difference between the notations *p[3] and (*p)[3].Since *has a lower precedence than [],*p[3] declares p as an array of 3 pointers while (*p)[3] declares p as a pointer to an array of three elements. N e w Z e a l a n d 0 A u s t r a l i a 0 I n d i a 0