Equations of Character Triple Pointer

In this section, you are going to learn

What are the different ways of declarations ?

How to dervie equations ?

What are the Properties of Variable ?

What are the Properties of Expression ?

1. Equations of Triple Pointer

In this section, you are going to learn

  • How to derive pointer equations for Triple pointer ?

  • How to apply these equations to understand C statements ?

You can derive equations looking at C declarations !

There are many methods in C, using which a Triple pointer can be declared. See below

 1#include <stdio.h>
 2
 3int main(void)
 4{
 5        char x = 10, *p = &x, **q = &p, ***r = &q;
 6
 7        *p = 20;
 8
 9        **q = 200;
10
11        ***r = 2000;
12
13        printf("x = %d, *p = %d, **q = %d ***r = %d\n", x, *p, **q, ***r);
14
15        return 0;
16}
In this example,
  • x is a character

  • p is an single character pointer

  • q is a double character pointer

  • r is a triple character pointer

  • x, p, q, r are declared in one Single Line

  • x, p, q, r are assigned in one Single Line

  • x is assigned with value 10

  • p is assigned with address of x

  • q is assigned with address of p

  • r is assigned with address of q

 1#include <stdio.h>
 2
 3int main(void)
 4{
 5        char x = 10;
 6
 7        char *p = &x;
 8
 9        char **q = &p;
10
11        char ***r = &q;
12
13        *p = 20;
14
15        **q = 200;
16
17        ***r = 2000;
18
19        printf("x = %d, *p = %d, **q = %d ***r = %d\n", x, *p, **q, ***r);
20
21        return 0;
22}
In this example,
  • x is a character

  • p is a single character pointer

  • q is a double character pointer

  • r is a triple character pointer

  • x is declared in a separate line

  • p is declared in a separate line

  • q is declared in a separate line

  • r is declared in a separate line

  • x is assigned in the same line of declaration

  • p is assigned in the same line of declaration

  • q is assigned in the same line of declaration

  • r is assigned in the same line of declaration

  • x is assigned with value 10

  • p is assigned with address of x

  • q is assigned with address of p

  • r is assigned with address of q

 1#include <stdio.h>
 2
 3int main(void)
 4{
 5        char x;
 6
 7        char *p;
 8
 9        char **q;
10
11        char ***r;
12
13        x = 10;
14
15        p = &x;
16
17        q = &p;
18
19        *p = 20;
20
21        **q = 200;
22
23        ***r = 2000;
24
25        printf("x = %d, *p = %d, **q = %d, ***r = %d\n", x, *p, **q, ***r);
26
27        return 0;
28}
In this example,
  • x is a character

  • p is a single character pointer

  • q is a double character pointer

  • r is a triple character pointer

  • x is declared in a separate line

  • p is declared in a separate line

  • q is declared in a separate line

  • r is declared in a separate line

  • x is assigned and is not part of declaration

  • p is assigned and is not part of declaration

  • q is assigned and is not part of declaration

  • r is assigned and is not part of declaration

  • x is assigned with value 10

  • p is assigned with address of x

  • q is assigned with address of p

  • r is assigned with address of q

Decl #

Declaration

Description

Decl 1

  • char x = 10, *p = &x, **q = &p, ***r = &q;

Character x, Single Pointer p, Double Pointer q, Triple Pointer r are declared and assigned in same line

Decl 2

  • char x = 10;

  • char *p = &x;

  • char **q = &p;

  • char ***r = &q;

Character x, Single Pointer p, Double Pointer q, Triple Pointer r are declared and assigned in separate lines

Decl 3

  • char x;

  • char *p;

  • char **q;

  • char ***r;

  • x = 10;

  • p = &x;

  • q = &p;

  • r = &q;

Character x, Single Pointer p, Double Pointer q, Triple Pointer r are declared in one line and assigned in another line

  • Whenever we see any of the above methods of declarations, we need to rewrite them such that, declarations and assignments are not in same line. Similar to Declaration 3

  • Equation 1 : Obtained from Step 2

p = &x;
  • Equation 2 : Move & to the left of First Equation. It turns in to *

*p = x;
  • Equation 3 : * and [0] can be used interchangeably. Hence *p and p[0] are one and the same !

p[0] = x;
  • Equation 4 : From Equation 2, Equation 3, we can derive that x, *p, p[0] all are same !

*p = p[0] = x;
  • Equation 5 : Obtained from Step 2

q = &p;
  • Equation 6 : Move & to the left of First Equation. It turns in to *

*q = p;
  • Equation 7 : * and [0] can be used interchangeably. Hence *q and q[0] are one and the same !

q[0] = p;
  • Equation 8 : From Equation 6, Equation 7, we can derive that p, *q, q[0] all are same !

*q = q[0] = p;
  • Equation 9 : From Equation 1, we know p = &x. Hence Replace p with &x in Equation 8

*q = q[0] = &x;
  • Equation 10 : Move & to the left of Equation 9. It turns in to *

**q = *q[0] = x;
  • Equation 11 : * and [0] can be used interchangeably

q[0][0] = x;
  • Equation 12 : Obtained from Step 2

r = &q;
  • Equation 13 : Move & to the left of First Equation. It turns in to *

*r = q;
  • Equation 14 : * and [0] can be used interchangeably. Hence *r and r[0] are one and the same !

r[0] = q;
  • Equation 15 : From Equation 13, Equation 14, we can derive that q, *r, r[0] all are same !

*r = r[0] = q;
  • Equation 16 : From Equation 5, we know q = &p. Hence Replace q with &p in Equation 15

*r = r[0] = &p;
  • Equation 17 : Move & to the left of Equation 16. It turns in to *

**r = *r[0] = p;
  • Equation 18 : * and [0] can be used interchangeably

r[0][0] = p;
  • Equation 19 : Comparing Equation 17, 18 we can conclude **r, *r[0], r[0][0] and p all are same !

**r = *r[0] = r[0][0] = p;
  • Equation 20 : From Equation 1, p = &x. Hence replace p with &x in Equation 19

**r = *r[0] = r[0][0] = &x;
  • Equation 21 : Move & to the left of Equation 16. It turns in to *

***r = **r[0] = *r[0][0] = x;
  • Equation 22 : * and [0] can be used interchangeably

***r = **r[0] = r[0][0][0] = x;

Equation #

Equation

Description

Equation 1

p = &x

Base condition

Equation 2

*p = x

From Equation 1, Move & from RHS to LHS to get * on LHS

Equation 3

p[0] = x

* and [0] can be used interchangeably. Hence *p and p[0] are synonyms

Equation 4

*p = p[0] = x

From Equation 2, 3 we can conclude *p, p[0], x are synonyms

Equation #

Equation

Description

Equation 5

q = &p

Base condition

Equation 6

*q = p

From Equation 5, Move & from RHS to LHS to get * on LHS

Equation 7

q[0] = p

* and [0] can be used interchangeably. Hence *q and q[0] are synonyms

Equation 8

*q = q[0] = p

From Equation 6, Equation 7, we can derive that p, *q, q[0] all are same !

Equation 9

*q = q[0] = &x

From Equation 1, we know p = &x. Hence Replace p with &x in Equation 8

Equation 10

**q = *q[0] = x

From Equation 9, Move & from RHS to LHS to get * on LHS

Equation 11

q[0][0] = x

* and [0] can be used interchangeably

Equation #

Equation

Description

Equation 12

r = &q

Base condition

Equation 13

*r = q

From Equation 12, Move & from RHS to LHS to get * on LHS

Equation 14

r[0] = q

* and [0] can be used interchangeably. Hence *r and r[0] are synonyms

Equation 15

*r = r[0] = q

From Equation 13, Equation 14, we can derive that q, *r, r[0] all are same !

Equation 16

*r = r[0] = &p

From Equation 5, we know q = &p. Hence Replace q with &p in Equation 15

Equation 17

**r = *r[0] = p

Move & to the left of Equation 16. It turns in to *

Equation 18

q[0][0] = p

* and [0] can be used interchangeably

Equation 19

**r = *r[0] = r[0][0] = p;

Comparing Equation 17, 18 we can conclude **r, *r[0], r[0][0] and p all are same !

Equation 20

**r = *r[0] = r[0][0] = &x;

From Equation 1, p = &x. Hence replace p with &x in Equation 19

Equation 21

***r = **r[0] = *r[0][0] = x;

Move & to the left of Equation 16. It turns in to *

Equation 22

***r = **r[0] = r[0][0][0] = x;

* and [0] can be used interchangeably

*p = 100;

printf("x = %d, *p = %d\n", x, *p);
Output :

x = 100, *p = 100

p[0] = 100;

printf("x = %d, p[0] = %d\n", x, p[0]);
Output :

x = 100, p[0] = 100

x = 100;

printf("*p = %d, p[0] = %d\n", *p, p[0]);
Output :

*p = 100, p[0] = 100

**q = 100;

printf("x = %d, **q = %d\n", x, **q);
Output :

x = 100, **q = 100

*q[0] = 100;

printf("x = %d, *q[0] = %d\n", x, *q[0]);
Output :

x = 100, *q[0] = 100

q[0][0] = 100;

printf("x = %d, q[0][0] = %d\n", x, q[0][0]);
Output :

x = 100, q[0][0] = 100

char x, y, *p, **q;

x = 100;
p = &x;
q = &p;

printf("*p = %d, p[0] = %d, **q = %d\n", *p, p[0], **q);

y = 200;

// *q, p are synonyms.
// Means *q = &y also means p = &y
*q = &y;

printf("*p = %d, p[0] = %d, **q = %d\n", *p, p[0], **q);
Output :

*p = 100, p[0] = 100, **q = 100

*p = 200,``p[0]`` = 200, **q = 200

char x, y, *p, **q;

x = 100;
p = &x;
q = &p;

printf("*p = %d, p[0] = %d, **q = %d\n", *p, p[0], **q);

y = 200;

// q[0], p are synonyms.
// Means q[0] = &y also means p = &y
q = &y;

printf("*p = %d, p[0] = %d, **q = %d\n", *p, p[0], **q);
Output :

*p = 100, p[0] = 100, **q = 100

*p = 200,``p[0]`` = 200, **q = 200

***r = 100;

printf("x = %d, ***r = %d\n", x, ***r);
Output :

x = 100, ***r = 100

**r[0] = 100;

printf("x = %d, **r[0] = %d\n", x, **r[0]);
Output :

x = 100, **r[0] = 100

r[0][0][0] = 100;

printf("x = %d, r[0][0][0] = %d\n", x, r[0][0][0]);
Output :

x = 100, r[0][0][0] = 100

char x, y, *p, **q, ***r;

x = 100;
p = &x;
q = &p;
r = &q;

printf("*p = %d, p[0] = %d, **q = %d, ***r = %d\n", *p, p[0], **q, ***r);

y = 200;

**r = &y;
//Step 1 : Apply Equation 19 : **r = &y also means  p = &y
//Step 2 : Now all equations having p like Equation 6, 7, 8 are affected  because *q = p
//         Now, *q = &y, q[0] = &y since p, *q, q[0] all are same
//         Now, **q = y, *q[0] = y, q[0][0] = y
//         Now, **q = 200, *q[0] = 200, q[0][0] = 200
//Step 3 : ***r, *r[0], r[0][0][0] = y also means  *p = y

printf("*p = %d, p[0] = %d, **q = %d, ***r = %d\n", *p, p[0], **q, ***r);
Output :

*p = 100, p[0] = 100, **q = 100, ***r = 100

*p = 200, p[0] = 200, **q = 200, ***r = 200

char x, y, *p, **q, ***r;

x = 100;
p = &x;
q = &p;
r = &q;

printf("*p = %d, p[0] = %d, **q = %d, ***r = %d\n", *p, p[0], **q, ***r);

y = 200;

*r[0] = &y;
//Step 1 : Apply Equation 19 : *r[0] = &y also means  p = &y
//Step 2 : Now all equations having p like Equation 6, 7, 8 are affected  because *q = p
//         Now, *q = &y, q[0] = &y since p, *q, q[0] all are same
//         Now, **q = y, *q[0] = y, q[0][0] = y
//         Now, **q = 200, *q[0] = 200, q[0][0] = 200
//Step 3 : ***r, *r[0], r[0][0][0] = y also means  *p = y

printf("*p = %d, p[0] = %d, **q = %d, ***r = %d\n", *p, p[0], **q, ***r);
Output :

*p = 100, p[0] = 100, **q = 100, ***r = 100

*p = 200, p[0] = 200, **q = 200, ***r = 200

char x, y, *p, **q, ***r;

x = 100;
p = &x;
q = &p;
r = &q;

printf("*p = %d, p[0] = %d, **q = %d, ***r = %d\n", *p, p[0], **q, ***r);

y = 200;

r[0][0] = &y;
//Step 1 : Apply Equation 19 : r[0][0] = &y also means  p = &y
//Step 2 : Now all equations having p like Equation 6, 7, 8 are affected because *q = p
//         Now, *q = &y, q[0] = &y since p, *q, q[0] all are same
//         Now, **q = y, *q[0] = y, q[0][0] = y
//         Now, **q = 200, *q[0] = 200, q[0][0] = 200
//Step 3 : ***r, *r[0], r[0][0][0] = y also means  *p = y

printf("*p = %d, p[0] = %d, **q = %d, ***r = %d\n", *p, p[0], **q, ***r);
Output :

*p = 100, p[0] = 100, **q = 100, ***r = 100

*p = 200, p[0] = 200, **q = 200, ***r = 200

char x, *p, **q, ***r;

char m, *p1;

x = 100;
p = &x;
q = &p;
r = &q;

printf("*p = %d, p[0] = %d, **q = %d, ***r = %d\n", *p, p[0], **q, ***r);

m = 200;
p1 = &m;

*r = &p1;
//Step 1 : Apply Equation 15 : *r = &p1 also means q = &p1
//Step 2 : **r = p1 and *q = p1
//Step 3 : **r = &m and *q = &m
//Step 4 : ***r = m and **q = m
//Step 5 : ***r = 200 and **q = 200

//Note p is no changed so far. Hence *p, p[0] is still 100

printf("*p = %d, p[0] = %d, **q = %d, ***r = %d\n", *p, p[0], **q, ***r);
Output :

*p = 100, p[0] = 100, **q = 100, ***r = 100

*p = 100, p[0] = 100, **q = 200, ***r = 200

 1#include <stdio.h>
 2
 3int main(void)
 4{
 5        char x;
 6
 7        char *p;
 8
 9        char **q;
10
11        char ***r;
12
13        x = 10;
14
15        p = &x;
16
17        q = &p;
18
19        r = &q;
20
21        printf("x = %d, *p = %d, p[0] = %d, **q = %d, ***r = %d\n", x, *p, p[0], **q, ***r);
22
23        x = 20;
24
25        printf("x = %d, *p = %d, p[0] = %d, **q = %d, ***r = %d\n", x, *p, p[0], **q, ***r);
26
27        *p = 30;
28
29        printf("x = %d, *p = %d, p[0] = %d, **q = %d, ***r = %d\n", x, *p, p[0], **q, ***r);
30
31        p[0] = 40;
32
33        printf("x = %d, *p = %d, p[0] = %d, **q = %d, ***r = %d\n", x, *p, p[0], **q, ***r);
34
35        **q = 50;
36
37        printf("x = %d, *p = %d, p[0] = %d, **q = %d, ***r = %d\n", x, *p, p[0], **q, ***r);
38
39        ***r = 60;
40
41        printf("x = %d, *p = %d, p[0] = %d, **q = %d, ***r = %d\n", x, *p, p[0], **q, ***r);
42
43        return 0;
44}
Output :

x = 10, *p = 10, p[0] = 10 **q = 10, ***r = 10

x = 20, *p = 20, p[0] = 20 **q = 20, ***r = 20

x = 30, *p = 30, p[0] = 30 **q = 30, ***r = 30

x = 40, *p = 40, p[0] = 40 **q = 40, ***r = 40

x = 50, *p = 50, p[0] = 50 **q = 50, ***r = 50

x = 50, *p = 50, p[0] = 50 **q = 50, ***r = 60

2. Properties of a variable

In this section, you are going to learn

  • Properties of a variable

    • Type of a variable ?

    • Size of a variable ?

    • Scope, Lifetime and Memory of a variable ?

 1char x;
 2
 3char *p;
 4
 5char **q;
 6
 7char ***r;
 8
 9p = &x;
10
11q = &p;
12
13r = &q;
  • In above code snippet, there are four variables x, p, q, r

Variable

Type

Description

type_of(x)

char

See Line 1

type_of(p)

char *

See Line 3

type_of(q)

char **

See Line 5

type_of(r)

char ***

See Line 7

Adress of variable must be stored in next level pointer type always

 1char x;
 2
 3char *p;
 4
 5char **q;
 6
 7char ***r;
 8
 9p = &x;
10
11q = &p;
12
13r = &q;
14
15*p = 10;
  • In above code snippet, there are four variables x, p, q, r

Variable

Type

Description

type_of(&x)

char *

  • type_of(x) is char

  • Hence, type_of(&x) is char *

type_of(&p)

char **

  • type_of(p) is char *

  • Hence, type_of(&p) is char **

type_of(&q)

char ***

  • type_of(q) is char **

  • Hence, type_of(&q) is char ***

type_of(&r)

char ****

  • type_of(r) is char ***

  • Hence, type_of(&r) is char ****

Sizeof(type)

Size

sizeof(char)

1 Bytes

sizeof(int)

4 Bytes

sizeof(float)

4 Bytes

sizeof(double)

8 Bytes

sizeof(pointer types) is always 8 Bytes, where pointer is single, double, triple etc.,:

Sizeof(type *)

Size

sizeof(char *)

8 Bytes

sizeof(int *)

8 Bytes

sizeof(float *)

8 Bytes

sizeof(double *)

8 Bytes

sizeof(struct xyz *)

8 Bytes

sizeof(union xyz *)

8 Bytes

Sizeof(type **)

Size

sizeof(char **)

8 Bytes

sizeof(int **)

8 Bytes

sizeof(float **)

8 Bytes

sizeof(double **)

8 Bytes

sizeof(struct xyz **)

8 Bytes

sizeof(union xyz **)

8 Bytes

etc.,

Sizeof(type ***)

Size

sizeof(char ***)

8 Bytes

sizeof(int ***)

8 Bytes

sizeof(float ***)

8 Bytes

sizeof(double ***)

8 Bytes

sizeof(struct xyz ***)

8 Bytes

sizeof(union xyz ***)

8 Bytes

etc.,

sizeof(&variable) is always 8 Bytes, where type_of(variable) can be anything

Sizeof(&variable)

Size

Declaration

sizeof(&x)

8 Bytes

char x;

sizeof(&x)

8 Bytes

char x;

sizeof(&x)

8 Bytes

float x;

sizeof(&x)

8 Bytes

double x;

sizeof(&x)

8 Bytes

struct xyz x;

sizeof(&x)

8 Bytes

union xyz x;

Sizeof(&variable)

Size

Declaration

sizeof(&x)

8 Bytes

char *x;

sizeof(&x)

8 Bytes

int *x;

sizeof(&x)

8 Bytes

float *x;

sizeof(&x)

8 Bytes

double *x;

sizeof(&x)

8 Bytes

struct xyz *x;

sizeof(&x)

8 Bytes

union xyz *x;

Sizeof(&variable)

Size

Declaration

sizeof(&x)

8 Bytes

char **x;

sizeof(&x)

8 Bytes

int **x;

sizeof(&x)

8 Bytes

float **x;

sizeof(&x)

8 Bytes

double **x;

sizeof(&x)

8 Bytes

struct xyz **x;

sizeof(&x)

8 Bytes

union xyz **x;

Sizeof(&variable)

Size

Declaration

sizeof(&x)

8 Bytes

char ***x;

sizeof(&x)

8 Bytes

int ***x;

sizeof(&x)

8 Bytes

float ***x;

sizeof(&x)

8 Bytes

double ***x;

sizeof(&x)

8 Bytes

struct xyz ***x;

sizeof(&x)

8 Bytes

union xyz ***x;

sizeof(variable) equals sizeof(typeof(variable))

 1char x;
 2
 3char *p;
 4
 5char **q;
 6
 7char ***r;
 8
 9p = &x;
10
11q = &p;
12
13*p = 10;
  • In above code snippet, there are four variables x, p, q, r

Sizeof(Variable)

Size

Description

sizeof(x)

1 Byte

  • How ?
    • Step 1 : sizeof(x) equals sizeof(typeof(x))

    • Step 2 : type_of(x) is char

    • Step 3 : sizeof(char) is 1 Byte

    • Hence, sizeof(x) is 1 Byte

sizeof(p)

8 Bytes

  • How ?
    • Step 1 : sizeof(p) equals sizeof(typeof(p))

    • Step 2 : type_of(p) is char *

    • Step 3 : sizeof(char *) is 8 Bytes

    • Hence, sizeof(p) is 8 Bytes

sizeof(q)

8 Bytes

  • How ?
    • Step 1 : sizeof(q) equals sizeof(typeof(q))

    • Step 2 : type_of(q) is char **

    • Step 3 : sizeof(char **) is 8 Bytes

    • Hence, sizeof(q) is 8 Bytes

sizeof(r)

8 Bytes

  • How ?
    • Step 1 : sizeof(r) equals sizeof(typeof(r))

    • Step 2 : type_of(r) is char ***

    • Step 3 : sizeof(char ***) is 8 Bytes

    • Hence, sizeof(r) is 8 Bytes

  • Global Scope and Lifetime.

  • Local Scope and Lifetime

3. Properties of Expressions

In this section, you are going to learn

  • Properties of Expressions

    • What is an Expression ?

    • Table of Expressions

    • Table of Size (for Expressions)

    • Table of Type (for Expressions)

    • Table of Address/Value (for Expression)

    • Table of Function Prototype (for Expression)

 1char x;
 2
 3char *p;
 4
 5char **q;
 6
 7p = &x;
 8
 9q = &p;
10
11*p = 10;
12
13**q = 100;

Expression

Description

x

  • x is a character

&x

  • &x is address of a character

  • &x is a single pointer

p

  • p is a pointer to a character

  • p is a single pointer

&p

  • &p is address of a pointer

  • &p is a double pointer

*p

p[0]

q

  • q is a double pointer and holds the address of a single pointer

&q

  • &q is address of a double pointer

  • &q is a triple pointer

*q

q[0]

**q

*q[0]

q[0][0]

r

  • r is a triple pointer and holds the address of a double pointer

&r

  • &r is a fourth pointer

*r

r[0]

**r

*r[0]

r[0][0]

***r

**r[0]

r[0][0][0]

Expression

Size

Description

sizeof(x)

1 Byte

sizeof(&x)

8 Bytes

sizeof(p)

8 Bytes

sizeof(&p)

8 Bytes

sizeof(*p)

1 Byte

sizeof(p[0])

1 Byte

sizeof(q)

8 Bytes

sizeof(&q)

8 Bytes

sizeof(*q)

8 Bytes

sizeof(q[0])

8 Bytes

sizeof(**q)

1 Byte

sizeof(*q[0])

1 Byte

sizeof(q[0][0])

1 Byte

sizeof(r)

8 Bytes

sizeof(&r)

8 Bytes

sizeof(*r)

8 Bytes

  • Step 1 : sizeof(*r) equals sizeof(q). See Equation 15

  • Step 2 : sizeof(q) equals sizeof(type_of(q))

  • Step 3 : sizeof(type_of(q)) equals sizeof(char **)

  • Step 4 : sizeof(char **) equals 8 Bytes

sizeof(r[0])

8 Bytes

  • Step 1 : sizeof(r[0]) equals sizeof(q). See Equation 15

  • Step 2 : sizeof(q) equals sizeof(type_of(q))

  • Step 3 : sizeof(type_of(q)) equals sizeof(char **)

  • Step 4 : sizeof(char **) equals 8 Bytes

sizeof(**r)

8 Bytes

sizeof(*r[0])

8 Bytes

sizeof(r[0][0])

8 Bytes

sizeof(***r)

1 Byte

sizeof(**r[0])

1 Byte

sizeof(r[0][0][0])

1 Byte

Expression

Type

Description

type_of(x)

char

type_of(&x)

char *

type_of(p)

char *

type_of(&p)

char **

type_of(*p)

char

  • Step 1 : type_of(*p) equals type_of(x), because *p = x. See Equation 2

  • Step 2 : type_of(x) equals char

type_of(p[0])

char

  • Step 1 : type_of(p[0]) equals type_of(x), because p[0] = x. See Equation 3

  • Step 2 : type_of(x) equals char

type_of(q)

char **

type_of(&q)

char ***

type_of(*q)

char *

type_of(q[0])

char *

type_of(**q)

char

type_of(*q[0])

char

type_of(q[0][0])

char

type_of(r)

char ***

type_of(&r)

char ****

type_of(*r)

char **

  • Step 1 : type_of(*r) equals type_of(q). See Equation 15

  • Step 2 : type_of(q) equals char **

type_of(r[0])

char **

  • Step 1 : type_of(r[0]) equals type_of(q). See Equation 15

  • Step 2 : type_of(q) equals char **

type_of(**r)

char *

type_of(*r[0])

char *

type_of(r[0][0])

char *

type_of(***r)

char

type_of(**r[0])

char

type_of(r[0][0][0])

char

Expression

Address/Value

Description

x

Value

  • Step 1 : x is a character

  • Step 2 : Hence x is a value

&x

Address

  • & operator indicates address

p

Address

  • Step 1 : p = &x See Equation 1

  • Step 2 : & operator indicates address

&p

Address

  • & operator indicates address

*p

Value

  • Step 1 : *p is a character. *p = x See Equation 2

  • Step 2 : Hence *p is a value

p[0]

Value

  • Step 1 : p[0] is a character. p[0] = x See Equation 3

  • Step 2 : Hence p[0] is a value

q

Address

  • Step 1 : q = &p See Equation 5

  • Step 2 : & operator indicates address

&q

Address

  • & operator indicates address

*q

Address

  • Step 1 : *q = p See Equation 6

  • Step 2 : p = &x

  • Step 3 : & operator indicates address

q[0]

Address

  • Step 1 : q[0] = p See Equation 7

  • Step 2 : p = &x

  • Step 3 : & operator indicates address

**q

Value

  • Step 1 : **q = x See Equation 10

  • Step 2 : x is a character

  • Step 3 : **q is a Value

*q[0]

Value

  • Step 1 : *q[0] = x See Equation 10

  • Step 2 : x is a character

  • Step 3 : *q[0] is a Value

q[0][0]

Value

  • Step 1 : q[0][0] = x See Equation 11

  • Step 2 : x is a character

  • Step 3 : q[0][0] is a Value

r

Address

&r

Address

  • Step 1 : & operator indicates address

*r

Address

r[0]

Address

**r

Address

*r[0]

Address

r[0][0]

Address

***r

Value

  • Step 1 : ***r = x See Equation 22

  • Step 2 : x is a character

  • Step 3 : r[0][0][0] is a Value

**r[0]

Value

  • Step 1 : **r[0] = x See Equation 22

  • Step 2 : x is a character

  • Step 3 : r[0][0][0] is a Value

r[0][0][0]

Value

  • Step 1 : r[0][0][0] = x See Equation 22

  • Step 2 : x is a character

  • Step 3 : r[0][0][0] is a Value

If fun(v) is function call then, fun(type_of(v)) is the prototype

Function call

Function Prototype

Description

fun(x)

void fun(char x);

fun(&x)

void fun(char *p);

fun(p)

void fun(char *p);

fun(&p)

void fun(char **p);

fun(*p)

void fun(char x);

  • Step 1 : fun(*p) equals fun(x)See Equation 2

  • Step 2 : fun(x) equals fun(type_of(x))

  • Step 3 : fun(type_of(x)) equals fun(char)

fun(p[0])

void fun(char x);

  • Step 1 : fun(p[0]) equals fun(x)See Equation 2

  • Step 2 : fun(x) equals fun(type_of(x))

  • Step 3 : fun(type_of(x)) equals fun(char)

fun(q)

void fun(char **q);

fun(&q)

void fun(char ***q);

fun(*q)

void fun(char *q);

  • Step 1 : fun(*q) equals fun(p)

  • Step 2 : fun(p) equals fun(type_of(p))

  • Step 3 : fun(type_of(p)) equals fun(char *)

fun(q[0])

void fun(char *q);

  • Step 1 : fun(q[0]) equals fun(p)

  • Step 2 : fun(p) equals fun(type_of(p))

  • Step 3 : fun(type_of(p)) equals fun(char *)

fun(**q)

void fun(char x);

  • Step 1 : fun(**q) equals fun(x) See Equation 10

  • Step 2 : fun(x) equals fun(type_of(x))

  • Step 3 : fun(type_of(x)) equals fun(char)

fun(*q[0])

void fun(char x);

  • Step 1 : fun(*q[0]) equals fun(x) See Equation 10

  • Step 2 : fun(x) equals fun(type_of(x))

  • Step 3 : fun(type_of(x)) equals fun(char)

fun(q[0][0])

void fun(char x);

  • Step 1 : fun(q[0][0]) equals fun(x) See Equation 11

  • Step 2 : fun(x) equals fun(type_of(x))

  • Step 3 : fun(type_of(x)) equals fun(char)

fun(r)

void fun(char ***r);

  • Step 1 : fun(r) equals fun(type_of(r))

  • Step 2 : fun(type_of(r)) equals fun(char ***)

fun(&r)

void fun(char ****s);

  • Step 1 : fun(&r) equals fun(type_of(&r))

  • Step 2 : fun(type_of(&r)) equals fun(char ****)

fun(*r)

void fun(char **q);

  • Step 1 : fun(*r) equals fun(q) See Equation 15

  • Step 2 : fun(q) equals fun(type_of(q))

  • Step 3 : fun(type_of(q)) equals fun(char **)

fun(r[0])

void fun(char **q);

  • Step 1 : fun(r[0]) equals fun(q) See Equation 15

  • Step 2 : fun(q) equals fun(type_of(q))

  • Step 3 : fun(type_of(q)) equals fun(char **)

fun(**r)

void fun(char *p);

  • Step 1 : fun(**r) equals fun(p) See Equation 19

  • Step 2 : fun(p) equals fun(type_of(p))

  • Step 3 : fun(type_of(p)) equals fun(char *)

fun(*r[0])

void fun(char *p);

  • Step 1 : fun(*r[0]) equals fun(p) See Equation 19

  • Step 2 : fun(p) equals fun(type_of(p))

  • Step 3 : fun(type_of(p)) equals fun(char *)

fun(r[0][0])

void fun(char *p);

  • Step 1 : fun(**r) equals fun(p) See Equation 19

  • Step 2 : fun(p) equals fun(type_of(p))

  • Step 3 : fun(type_of(p)) equals fun(char *)

fun(***r)

void fun(char x);

  • Step 1 : fun(***r) equals fun(x) See Equation 22

  • Step 2 : fun(x) equals fun(type_of(x))

  • Step 3 : fun(type_of(x)) equals fun(char)

fun(**r[0])

void fun(char x);

  • Step 1 : fun(**r[0]) equals fun(x) See Equation 22

  • Step 2 : fun(x) equals fun(type_of(x))

  • Step 3 : fun(type_of(x)) equals fun(char)

fun(r[0][0][0])

void fun(char x);

  • Step 1 : fun(r[0][0][0]) equals fun(x) See Equation 22

  • Step 2 : fun(x) equals fun(type_of(x))

  • Step 3 : fun(type_of(x)) equals fun(char)

4. Summary

#

?

Size in Bytes

Type

Address or Value

Function call

Function Prototype

x

Character

4

char

Value

fun(x)

void fun(char x);

&x

Single Pointer

8

char *

Address

fun(&x)

void fun(char *p);

p

Single Pointer

8

char *

Address

fun(p)

void fun(char *p);

&p

Double Pointer

8

char **

Address

fun(&p)

void fun(char **q);

*p

Character

4

char

Value

fun(*p)

void fun(char x);

p[0]

Character

4

char

Value

fun(p[0])

void fun(char x);

q

Double Pointer

8

char **

Address

fun(q)

void fun(char **q);

&q

Triple Pointer

8

char ***

Address

fun(&q)

void fun(char ***r);

*q

Single Pointer

8

char *

Address

fun(*q)

void fun(char *p);

q[0]

Single Pointer

8

char *

Address

fun(q[0])

void fun(char *p);

**q

Character

4

char

Value

fun(**q)

void fun(char x);

*q[0]

Character

4

char

Value

fun(*q[0])

void fun(char x);

q[0][0]

Character

4

char

Value

fun(q[0][0])

void fun(char x);

r

Triple Pointer

8

char ***

Address

fun(r)

void fun(char ***r);

&r

Fourth Pointer

8

char ****

Address

fun(&r)

void fun(char ****s);

*r

Double Pointer

8

char **

Address

fun(*r)

void fun(char **q);

r[0]

Double Pointer

8

char **

Address

fun(r[0])

void fun(char **q);

**r

Single Pointer

8

char *

Address

fun(**r)

void fun(char *p);

*r[0]

Single Pointer

8

char *

Address

fun(*r[0])

void fun(char *p);

r[0][0]

Single Pointer

8

char *

Address

fun(r[0][0])

void fun(char *p);

***r

Character

4

char

Value

fun(***r)

void fun(char x);

**r[0]

Character

4

char

Value

fun(**r[0])

void fun(char x);

r[0][0][0]

Character

4

char

Value

fun(r[0][0][0])

void fun(char x);