3. Introduction
1. A pointer is a variable whose value is the
address of another variable, i.e., direct address
of the memory location. Like any variable or
constant, you must declare a pointer before
using it to store any variable address.
2. The actual data type of the value of all pointers,
whether integer, float, character, or otherwise,
is the same, a long hexadecimal number that
represents a memory address. The only
difference between pointers of different data
types is the data type of the variable or
constant that the pointer points to.
5. Concept of Pointer & Pointer to Pointer
1. If user want to store address of “a” which is of integer datatype to the pointer
variable then the pointer should be of same data type, i.e. integer.
2. Pointer variable stores address of another variable of similar data type
3. Pointer to pointer variable stores address of another pointer of similar data type
6. Concept of Pointer & Pointer to Pointer
1. // C program to demonstrate pointer and pointer to pointer
2. #include <stdio.h>
3. #include <conio.h>
4. #include <math.h>
5. #include <string.h>
6. void main()
7. {
8.
9. int a = 145;
10.
11. // pointer for a
12. int *ptr2;
13.
14. // double pointer for ptr2
15. int **ptr1;
16.
17. // storing address of a in ptr2
18. ptr2 = &a;
19.
20. // Storing address of ptr2 in ptr1
21. ptr1 = &ptr2;
22.
23. // Displaying value of a using
24. // both single and double pointers
25. printf("Value of a = %dn", a );
26. printf("Value of a using single pointer = %dn", *ptr2 );
27. printf("Value of a using double pointer = %dn", **ptr1);
28.
29. printf("Address of a = %un", &a );
30. printf("Address of a using single pointer = %un", ptr2 );
31. printf("Address of a using single pointer = %un", *ptr1);
32.
33. printf("Address of ptr2 using ptr2 = %un", &ptr2 );
34. printf("Address of ptr2 using ptr1 pointer to pointer = %un", ptr1 );
35.
36. }