989 views

2 Answers

Best answer
7 votes
7 votes
int a = 10;
int *b;          //Single Pointer
int **c;         // Double Pointer
int ***d;        //Triple Pointer

/* Single Pointer */

// Here b is a sigle pointer hence its capable of storing the address
// of a variable.

b = &a; //Valid operation

printf("%d\n",*b); //To acess the value at address which is stored in b

// & is called as "address of" operator
// * is called as "dereferencing operator" or "value at address" operator

/* Double Pointer */

// Here c is double pointer hence,

c = &b; //Valid operation

c = &a; // Not valid, Program may not generate compile time error but definitely
        // generate a warning "suspicious pointer conversion" and wil generate a
        // runtime eerror.
        
printf("%d\n",**c); // this is the way to access the data from double pointer

/* Triple Pointer */

// Here d is a triple pointer. 

d = &c; // Valid operation

d = &b; //Will generate the run time error as we have seen above
d = &a; // Runtime error

printf("%d",***d); // To access the value trough d.

After this, If you have any specific doubt then ask in comment I will answer all. Enjoy. 

selected by
4 votes
4 votes

Well, your question popped two questions in my mind. First, if you are asking how triple pointers can be implemented and used(the syntax) and second, if you are interested in knowing the practical utility of triple pointers. The former has been vividly answered by  @rude , for the latter version ( i suppose this can be a good question too :P ) here I go.

For example, let's take a char pointer so that char pointer can point to a string, better say a sentence. Now imagine many such pointers, each pointing to a sentence.
Next, think of a pointer that points to the collection(array) of all the above pointers. It will point to a collection of sentences and hence it is analogous to a page.

And here comes the third pointer which can point to the collection of all page pointers and represent a chapter.

Something like this :

Triple Pointer

Add another pointer (fourth pointer) and you will have a book !

edited by

Related questions

4 votes
4 votes
1 answer
1
ritwik_07 asked Jun 10, 2023
424 views
#include<stdio.h #include<string.h #define MAX(x, y) ((x) (y) ? (x) : (y)) int main() { int i = 10, j = 5, k = 0; k = MAX(i++, ++j); printf("%d %d %d", i, j, k); return ...
0 votes
0 votes
2 answers
3
Sk Jamil Ahemad asked Feb 1, 2022
326 views
Please explain with some example that How Right to Left associativity takes place in case of Ternary operators?
1 votes
1 votes
1 answer
4