Pointer to Pointer
- Before learning What is the Concept of Pointer to Pointer we suggest You please go through the concept of What are Pointers?
- "Pointer to an Pointer",This means an Pointer Pointing to an Pointer variable
- As an Pointer is an variable which stores the address of an variable
- So, Pointer to an Pointer means a variable which will store the address of an Pointer variable.
- For example:
void main()
{
int a = 10; //integer variable
int *p; //Pointer variable
p = &a; //storing address of variable a
void main() { int a = 10; //integer variable int *p; //Pointer variable p = &a; //storing address of variable a
int **p_to_p; //declaring the pointer variable
//which will store the address of pointer variable p
p_to_p = &p; //assigning the address of variable p
int **p_to_p; //declaring the pointer variable //which will store the address of pointer variable p p_to_p = &p; //assigning the address of variable p
Let's print the address and the value of variable a,p , and p_to_P
printf("\nValue of variable a is %d",a);
printf("\nAddress of variable a is %u",&a);
printf("\nValue in pointer variable p is %d",p);
printf("\nAddress of pointer variable p is %u",&p);
printf("\nValue in p_to_p variable is %d",p_to_p);
printf("\nAddress of p_to_p variable is %u",&p_to_p);
printf("\nValue of variable a is %d",a); printf("\nAddress of variable a is %u",&a); printf("\nValue in pointer variable p is %d",p); printf("\nAddress of pointer variable p is %u",&p); printf("\nValue in p_to_p variable is %d",p_to_p); printf("\nAddress of p_to_p variable is %u",&p_to_p);
Output
Value of variable a is 10
Address of variable a is 6356748
Value in pointer variable p is 6356748
Address of pointer variable p is 6356744
Value in p_to_p variable is 6356744
Address of p_to_p variable is 6356740
Address of variable a is 6356748
Value in pointer variable p is 6356748
Address of pointer variable p is 6356744
Value in p_to_p variable is 6356744
Address of p_to_p variable is 6356740
Let's see what has happen behind
Let's understand the concept of declaring and levels of pointer variable
But ,what meant by level of pointer
let's understand it .
Pointer of level one:
void main()
{
int a = 10; //integer variable
int *p; //Pointer of level one
p = &a; //assigning the address of variable a
//to a pointer p of level one.
void main() { int a = 10; //integer variable int *p; //Pointer of level one p = &a; //assigning the address of variable a //to a pointer p of level one.
Pointer of level two:
int **p2; //pointer of level two and
//can store address of pointer of level 1
p2 = &p;//assigning the address of pointer of level 1
int **p2; //pointer of level two and //can store address of pointer of level 1 p2 = &p;//assigning the address of pointer of level 1
Pointer of level three:
int ***p3; //pointer of level three and
//can store address of pointer of level 2
p3 = &p2;//assigning the address of pointer of level 2
int ***p3; //pointer of level three and //can store address of pointer of level 2 p3 = &p2;//assigning the address of pointer of level 2
Pointer of level Four:
int ****p3; //pointer of level four and
//can store address of pointer of level 3
p4 = &p3;//assigning the address of pointer of level 2
}
int ****p3; //pointer of level four and //can store address of pointer of level 3 p4 = &p3;//assigning the address of pointer of level 2 }
- This is what levels of pointer variable means.
- let's recap it : Pointer can point to a pointer variable only if , its level is less than One as Compare to the level of Pointing pointer.
Further Concept:
- Array and Pointer
- What is array of pointer?
- how to initialize an array of pointers?
- How to Access elements of an Array Of Pointers?
- Functions and Pointers
- How to pass a Pointer To a Function?
- Call By reference
- How to declare Structure Pointer?
- Working with structure Pointer
- How to Create Structure Variable Dynamically ?
- Creating structure variable through malloc() and calloc()
Further Topics:
- How to initialize an structure variable?
- How to Access Structure member?
- What are Nested Structure?
- How to built an Nested Structure?
- How to Access members of Nested Structure?
- How to initialize Nested structure?
- Functions and Structure
- How to pass a structure variable to function?
- How to make function which will take structure variable as arguments?
- How to make function which will return structure variable?
- Array and Structure
- How to make array of structure variable?
- How to initialize array structure variable?
- How to Access members of an array of structure?
- How to take members of array structure as input from the user?
- Pointer and Structure
- How to Point a structure variable?
- How to declare a pointer of structure variable?
- How to Initialize an pointer of structure variable?
- How to access member of structure variable which is point by an pointer?
- What is '->' Operator?
- How to allocate memory for structure variable Dynamically
- How to allocate memory of structure variable using malloc() and calloc() function
- Self Referential Block
- What is Referential Structure?
- How to Create self Referential Structure?
- Applications of Self Referential Structures
- Practice Programs
People Also Searched:
- Functions In C
- Why Functions?
- What are Functions?
- how to write our functions?
- What are programmer define functions?
- How to declare function?
- How to define a function?
- What is function Prototype?
- how to declare a function?
- what are Actual Parameters?
- What are Formal Parameters?
- Function Call?
- how to call a Function?
- What are different types of calling function?
- Call by value
- call by reference
- Recursion
- Array and Functions
- How to pass an array to a function?
- What is Character array
- Functions for Characters
- Functions from #include<ctype.h> Header File
- what are isdigit(), islower() , isupper(),etc
- what are various string handling functions
- Functions from #include<string.h> Header File
- what are strcpy(), strcmp(), strncmp(), strcmpi(),etc
- strcmp() VS strncmp() VS strcmpi()
- Input And Output Functions
- How to take strings As Input
- What is gets() functions
- What is puts() function
0 Comments
Post a Comment