Equations of Character Single Pointer ============================================================= In this section, you are going to learn .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What are the different ways of declarations ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow How to dervie equations ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What are the Properties of Variable ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What are the Properties of Expression ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Topics in this section, * :ref:`Derive Equations for Single Pointer ` * :ref:`Step 1 : Understand different methods to declare Single Pointer ` * :ref:`Declaration 1 : Char x, Pointer p are declared and assigned in same line ` * :ref:`Declaration 2 : Char x, Pointer p are declared and assigned in separate lines ` * :ref:`Declaration 3 : Char x, Pointer p are declared in one line and assigned in another line ` * :ref:`Table of Declarations for Single Pointer ` * :ref:`Step 2 : Split pointer declarations and assignments into separate lines ` * :ref:`Step 3 : Derive Equations ` * :ref:`Step 4 : Apply above equations to analyse C statements ` * :ref:`Table of Equations for Single Pointer ` * :ref:`Properties of a variable ` * :ref:`Property 1 : Type ` * :ref:`Property 2 : sizeof() ` * :ref:`Property 3 : Scope, Lifetime and Memory of a variable ` * :ref:`Properties of Expressions ` * :ref:`Table of Expressions ` * :ref:`Table of Size (for Expressions) ` * :ref:`Table of Types (for Expressions) ` * :ref:`Table of Address/Value (for Expression) ` * :ref:`Table of Function Prototype (for Expression) ` * :ref:`Summary ` 1. Equations of Single Pointer *********************************************************************** .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow In this section, you are going to learn * How to derive pointer equations for single pointer ? * How to apply these equations to understand C statements ? .. _variable_and_ptr_sp_char_ptr_ex_1: .. tab-set:: .. tab-item:: Derive Equations for Single Pointer .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow You can derive equations looking at C declarations ! .. _variable_and_ptr_sp_char_ptr_ex_2: .. tab-set:: .. tab-item:: Step 1 : Understand different methods to declare Single Pointer .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow There are many methods in C, using which a single pointer can be declared. See below .. _variable_and_ptr_sp_char_ptr_ex_3: .. tab-set:: .. tab-item:: Declaration 1 : Char ``x``, Pointer ``p`` are declared and assigned in same line .. code-block:: c :linenos: :emphasize-lines: 5 #include int main(void) { char x = 10, *p = &x; *p = 20; printf("x = %d, *p = %d\n", x, *p); return 0; } .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow In this example, * ``x`` is a character * ``p`` is a character pointer * ``x`` and ``p`` are declared in one Single Line * ``x`` and ``p`` are assigned in one Single Line * ``x`` is assigned with value 10 * ``p`` is assigned with address of ``x`` .. _variable_and_ptr_sp_char_ptr_ex_4: .. tab-set:: .. tab-item:: Declaration 2 : Char ``x``, Pointer ``p`` are declared and assigned in separate lines .. code-block:: c :linenos: :emphasize-lines: 5, 7 #include int main(void) { char x = 10; char *p = &x; *p = 20; printf("x = %d, *p = %d\n", x, *p); return 0; } .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow In this example, * ``x`` is a character * ``p`` is a character pointer * ``x`` is declared in a separate line * ``p`` is declared in a separate line * ``x`` is assigned in the same line of declaration * ``p`` is assigned in the same line of declaration * ``x`` is assigned with value 10 * ``p`` is assigned with address of ``x`` .. _variable_and_ptr_sp_char_ptr_ex_5: .. _variable_and_ptr_sp_char_ptr_declaration_3: .. tab-set:: .. tab-item:: Declaration 3 : Char ``x``, Pointer ``p`` are declared in one line and assigned in another line .. code-block:: c :linenos: :emphasize-lines: 5, 7, 9, 11 #include int main(void) { char x; char *p; x = 10; p = &x; *p = 20; printf("x = %d, *p = %d\n", x, *p); return 0; } .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow In this example, * ``x`` is a character * ``p`` is a character pointer * ``x`` is declared in a separate line * ``p`` is declared in a separate line * ``x`` is assigned and is not part of declaration * ``p`` is assigned and is not part of declaration * ``x`` is assigned with value 10 * ``p`` is assigned with address of ``x`` .. _variable_and_ptr_sp_char_ptr_ex_6: .. tab-set:: .. tab-item:: Table of Declarations for Single Pointer ========== ========================= =========================================================================== Decl # Declaration Description ========== ========================= =========================================================================== Decl 1 * char x = 10, \*p = &x; Char x, Pointer p are declared and assigned in same line Decl 2 * char x = 10; Char x, Pointer p are declared and assigned in separate lines * char \*p = &x; Decl 3 * char x; Char x, Pointer p are declared in one line and assigned in another line * char \*p; * x = 10; * p = &x; ========== ========================= =========================================================================== .. _variable_and_ptr_sp_char_ptr_ex_7: .. tab-set:: .. tab-item:: Step 2 : Split pointer declarations and assignments into separate lines * 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 :ref:`Declaration 3 ` .. _variable_and_ptr_sp_char_ptr_ex_8: .. tab-set:: .. tab-item:: Step 3 : Derive Equations .. _variable_and_ptr_sp_char_ptr_eq_1: * Equation 1 : Obtained from ``Step 2`` .. code-block:: c p = &x; .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Implication : ``p`` holds the address of ``x`` .. _variable_and_ptr_sp_char_ptr_eq_2: * Equation 2 : Move ``&`` to the left of First Equation. It turns in to ``*`` .. code-block:: c *p = x; .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Implication : ``x`` and ``*p`` are one and the same ! .. _variable_and_ptr_sp_char_ptr_eq_3: * Equation 3 : ``*p`` has an alias ``p[0]``. Means ``*p`` and ``p[0]`` are one and the same ! .. code-block:: c p[0] = x; .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Implication : ``x`` and ``p[0]`` are one and the same ! .. _variable_and_ptr_sp_char_ptr_eq_4: * Equation 4 : From Equation 2, Equation 3, we can derive that ``x``, ``*p``, ``p[0]`` all are same ! .. code-block:: c *p = p[0] = x; .. _variable_and_ptr_sp_char_ptr_ex_9: .. tab-set:: .. tab-item:: Step 4 : Apply above equations to analyse C statements .. tab-set:: .. tab-item:: Example 1 : :ref:`See Equation 2 `: Changing ``*p`` changes the value of ``x``. .. code-block:: c *p = 100; printf("x = %d, *p = %d\n", x, *p); .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Output : ``x`` = 100, ``*p`` = 100 .. tab-set:: .. tab-item:: Example 2 : :ref:`See Equation 3 ` : Changing ``p[0]`` changes the value of ``x`` .. code-block:: c p[0] = 100; printf("x = %d, p[0] = %d\n", x, p[0]); .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Output : ``x`` = 100, ``p[0]`` = 100 .. tab-set:: .. tab-item:: Example 3 : :ref:`See Equation 4 ` : Changing ``x`` changes the value of ``*p`` and ``p[0]`` .. code-block:: c x = 100; printf("*p = %d, p[0] = %d\n", *p, p[0]); .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Output : ``*p`` = 100, ``p[0]`` = 100 .. tab-set:: .. tab-item:: Step 5 : Complete program .. code-block:: c :linenos: #include int main(void) { char x; char *p; x = 10; p = &x; printf("x = %d, *p = %d, p[0] = %d\n", x, *p, p[0]); x = 20; printf("x = %d, *p = %d, p[0] = %d\n", x, *p, p[0]); *p = 30; printf("x = %d, *p = %d, p[0] = %d\n", x, *p, p[0]); p[0] = 40; printf("x = %d, *p = %d, p[0] = %d\n", x, *p, p[0]); return 0; } .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Output : ``x`` = 10, ``*p`` = 10, ``p[0]`` = 10 ``x`` = 20, ``*p`` = 20, ``p[0]`` = 20 ``x`` = 30, ``*p`` = 30, ``p[0]`` = 30 ``x`` = 40, ``*p`` = 40, ``p[0]`` = 40 .. _variable_and_ptr_sp_char_ptr_ex_10: .. tab-set:: .. tab-item:: Table of Equations for Single Pointer ========== ============== ============================================================ 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 \*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 ========== ============== ============================================================ 2. Properties of a variable *********************************************************************** .. _variable_and_ptr_sp_char_ptr_ex_11: .. tab-set:: .. tab-item:: Properties of a variable .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow 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 ? .. _variable_and_ptr_sp_char_ptr_ex_12: .. tab-set:: .. tab-item:: Property 1 : Type .. _variable_and_ptr_sp_char_ptr_property_1_1: .. tab-set:: .. tab-item:: Property 1.1 : type_of(variable) .. code-block:: c :linenos: :emphasize-lines: 1, 3 char x; char *p; p = &x; *p = 10; * In above code snippet, there are two variables ``x``, ``p`` =========== ========= ============================================================================== Variable Type Description =========== ========= ============================================================================== type_of(x) char See Line 1 type_of(p) char \* See Line 3 =========== ========= ============================================================================== .. _variable_and_ptr_sp_char_ptr_property_1_2: .. tab-set:: .. tab-item:: Property 1.2 : type_of(&variable) .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Adress of variable must be stored in next level pointer type always .. code-block:: c :linenos: :emphasize-lines: 1, 3 char x; char *p; p = &x; *p = 10; * In above code snippet, there are two variables ``x``, ``p`` =========== ========= ============================================================================== 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 **`` =========== ========= ============================================================================== .. _variable_and_ptr_sp_char_ptr_ex_13: .. tab-set:: .. tab-item:: Property 2 : sizeof() .. tab-set:: .. tab-item:: Property 2.1 : sizeof() of basic types ======================= ======= Sizeof(type) Size ======================= ======= sizeof(char) 1 Bytes sizeof(int) 4 Bytes sizeof(float) 4 Bytes sizeof(double) 8 Bytes ======================= ======= .. tab-set:: .. tab-item:: Property 2.2 : sizeof() of pointer types .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow ``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., ======================= ======= .. _variable_and_ptr_sp_char_ptr_property_2_3: .. tab-set:: .. tab-item:: Property 2.3 : sizeof(&variable) - sizeof address of variable .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow ``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;`` ======================= ======= ======================== .. _variable_and_ptr_sp_char_ptr_property_2_4: .. tab-set:: .. tab-item:: Property 2.4 : sizeof() of variable .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow ``sizeof(variable)`` equals ``sizeof(typeof(variable))`` .. code-block:: c :linenos: :emphasize-lines: 1, 3 char x; char *p; p = &x; *p = 10; * In above code snippet, there are two variables ``x``, ``p`` ======================= ======= ================================================================================ 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`` ======================= ======= ================================================================================ .. _variable_and_ptr_sp_char_ptr_ex_14: .. tab-set:: .. tab-item:: Property 3 : Scope, Lifetime and Memory of a variable * Global Scope and Lifetime .. code-block:: c :linenos: :emphasize-lines: 1, 3 char x; char *p; int main(void) { p = &x; *p = 10; return 0; } * In above code snippet, * Scope * Two variables ``x``, ``p`` are defined in Global Scope at Lines 1, 3 * Which means, they can be accessed in any function defined in current file * Which means, they can be accessed in any function defined in other files using extern keyword .. code-block:: c :linenos: :emphasize-lines: 1, 3 extern char x; extern char *p; void display(void) { printf("x = %d, *p = %d\n", x, *p); } * Lifetime * Lifetime of variables ``x``, ``p`` is same as Lifetime of Process(Program) * Memory * Memory of ``1 Byte`` for variable ``x`` is reserved/allocated on Data Segment of the Process * Memory of ``8 Bytes`` for variable ``p`` is reserved/allocated on Data Segment of the Process * Local Scope and Lifetime .. code-block:: c :linenos: :emphasize-lines: 3, 5 int do_calc(void) { char x; char *p; p = &x; *p = 10; return 0; } int main(void) { do_calc(); return 0; } * In above code snippet, * Scope * Two variables ``x``, ``p`` are defined in Local Scope at Lines 3, 5 inside function ``do_calc`` * Which means, they can be accessed only inside a function ``do_calc`` and not anywhere else * Lifetime * Lifetime of variables ``x``, ``p`` is same as Lifetime of function ``do_calc`` * Memory * When a function call is made for ``do_calc``, stack frame for function ``do_calc`` is created * Memory of ``1 Byte`` for variable ``x`` is reserved/allocated on stack frame of function ``do_calc`` * Memory of ``8 Bytes`` for variable ``p`` is reserved/allocated on stack frame of function ``do_calc`` * When a function ``do_calc`` returns at Line 11, stack frame for function ``do_calc`` is deleted * With this memory of variables ``x``, ``p`` are also deleted 3. Properties of Expressions *********************************************************************** .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow 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) .. _variable_and_ptr_sp_char_ptr_ex_15: .. tab-set:: .. tab-item:: Properties of Expressions .. code-block:: c :linenos: char x; char *p, *q; char sum; //Write to x x = 10; //Read from x sum = x + 100; //Write to p p = &x; //Read from p q = p; //Write to *p or Write to x *p = 20; //Read from *p or Read from x sum = *p + 200; //Write to p[0] or Write to x p[0] = 40; //Read from p[0] or Read from x sum = p[0] + 400; printf("x = %x, &x = %x, p = %x, &p = %x, *p = %x, p[0] = %x\n", x, &x, p, &p, *p, p[0]); .. tab-set:: .. tab-item:: What is an Expression ? * Expressions must be understood always in a non-declaration C statement * Expressions are the valid operations on a given variable - (I am defining this for simplicity !) .. tab-set:: .. tab-item:: Valid Operations/Expressions of variable ``x`` * Write of ``x`` * At Line 8, ``Write`` operation is done on variable ``x`` which is storing value of ``10`` into ``x`` * Read of ``x`` * At Line 11, ``Read`` operation is done on variable ``x`` which is reading content of variable ``x`` * Fetch Address of ``x`` (&x) * At Line 14, Address of variable ``x`` is being fetched and assigned to pointer variable ``p`` .. tab-set:: .. tab-item:: Valid Operations/Expressions of variable ``p`` * Write of ``p`` * At Line 14, ``Write`` operation is done on variable ``p`` which is storing address of ``x`` into ``p`` * Read of ``p`` * At Line 17, ``Read`` operation is done on variable ``p`` which is reading content of ``p`` * ``p`` contains address of ``x`` * Fetch Address of ``p`` (&p) * See Line 31 * Dereference of ``p`` * How to derefer ? * Dereferencing using ``*`` operator is valid * ``*p`` is valid * Dereferencing using ``[]`` operator is valid * ``p[0]`` is valid * Write * At Line 20, ``Write`` operation is done on ``*p`` which is storing value of ``20`` into ``*p`` * Storing value to ``*p`` is equal to storing value to ``x`` * At Line 26, ``Write`` operation is done on ``p[0]`` which is storing value of ``40`` into ``p[0]`` * Storing value to ``p[0]`` is equal to storing value to ``x`` * Read * At Line 23, ``Read`` operation is done on ``*p`` which is reading content of ``*p`` * Reading value from ``*p`` is equal to Reading value from ``x`` * At Line 29, ``Read`` operation is done on ``p[0]`` which is reading content of ``p[0]`` * Reading value from ``p[0]`` is equal to Reading value from ``x`` * Since ``p`` is defined as Single Pointer, ``p`` can be dereferenced only once ! .. tab-set:: .. tab-item:: Let us write-down expression tables for below code snippet .. code-block:: c :linenos: :emphasize-lines: 1, 3 char x; char *p; p = &x; *p = 10; .. _variable_and_ptr_sp_char_ptr_ex_16: .. tab-set:: .. tab-item:: Table of Expressions ========== ================================================================================================== 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`` is a character, because ``*p = x``. :ref:`See Equation 2 ` p[0] * ``p[0]`` is a character, because ``p[0] = x``. :ref:`See Equation 3 ` ========== ================================================================================================== .. _variable_and_ptr_sp_char_ptr_ex_17: .. tab-set:: .. tab-item:: Table of Size (for Expressions) =============== ======= ================================================================= Expression Size Description =============== ======= ================================================================= sizeof(x) 1 Byte * :ref:`See Property 2.4 ` sizeof(&x) 8 Bytes * :ref:`See Property 2.3 ` sizeof(p) 8 Bytes * :ref:`See Property 2.4 ` sizeof(&p) 8 Bytes * :ref:`See Property 2.3 ` sizeof(\*p) 1 Byte * Step 1 : ``sizeof(*p)`` equals ``sizeof(x)`` :ref:`See Equation 2 ` * Step 2 : ``sizeof(x)`` equals ``sizeof(type_of(x))`` :ref:`See Property 2.4 ` * Step 3 : ``sizeof(type_of(x))`` equals ``sizeof(char)`` :ref:`See Property 1.1 ` * Step 4 : ``sizeof(char)`` equals 1 Bytes sizeof(p[0]) 1 Byte * Step 1 : ``sizeof(p[0])`` equals ``sizeof(x)``= x`` :ref:`See Equation 3 ` * Step 2 : ``sizeof(x)`` equals ``sizeof(type_of(x))`` :ref:`See Property 2.4 ` * Step 3 : ``sizeof(type_of(x))`` equals ``sizeof(char)`` :ref:`See Property 1.1 ` * Step 4 : ``sizeof(char)`` equals 1 Byte =============== ======= ================================================================= .. _variable_and_ptr_sp_char_ptr_ex_18: .. tab-set:: .. tab-item:: Table of Types (for Expressions) ================ ========== ================================================================================================================= Expression Type Description ================ ========== ================================================================================================================= type_of(x) char * :ref:`See Property 1.1 ` type_of(&x) char \* * :ref:`See Property 1.2 ` type_of(p) char \* * :ref:`See Property 1.1 ` type_of(&p) char \*\* * :ref:`See Property 1.2 ` type_of(\*p) char * Step 1 : ``type_of(*p)`` equals ``type_of(x)``, because ``*p = x``. :ref:`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``. :ref:`See Equation 3 ` * Step 2 : ``type_of(x)`` equals ``char`` ================ ========== ================================================================================================================= .. _variable_and_ptr_sp_char_ptr_ex_19: .. tab-set:: .. tab-item:: Table of Address/Value (for Expression) ========== ============== ==================================================== 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`` :ref:`See Equation 1 ` * Step 2 : & operator indicates address &p Address * & operator indicates address \*p Value * Step 1 : ``*p`` is a character. ``*p = x`` :ref:`See Equation 2 ` * Step 2 : Hence ``*p`` is a value p[0] Value * Step 1 : ``p[0]`` is a character. ``p[0] = x`` :ref:`See Equation 3 ` * Step 2 : Hence ``p[0]`` is a value ========== ============== ==================================================== .. _variable_and_ptr_sp_char_ptr_ex_20: .. tab-set:: .. tab-item:: Table of Function Prototype (for Expression) .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow 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); * :ref:`See Property 1.1 ` fun(&x) void fun(char \*p); * :ref:`See Property 1.2 ` fun(p) void fun(char \*p); * :ref:`See Property 1.1 ` fun(&p) void fun(char \*\*p); * :ref:`See Property 1.2 ` fun(\*p) void fun(char x); * Step 1 : ``fun(*p)`` equals ``fun(x)``:ref:`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)``:ref:`See Equation 2 ` * Step 2 : ``fun(x)`` equals ``fun(type_of(x))`` * Step 3 : ``fun(type_of(x))`` equals ``fun(char)`` ============= ====================== ==================================================================== .. _variable_and_ptr_sp_char_ptr_ex_21: 4. Summary *********************************************************************** ======= ============== ============= ========== ================ ============= ======================= # ? Size in Bytes Type Address or Value Function call Function Prototype ======= ============== ============= ========== ================ ============= ======================= x Char 1 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 Char 1 char Value fun(\*p) void fun(char x); p[0] Char 1 char Value fun(p[0]) void fun(char x); ======= ============== ============= ========== ================ ============= ======================= .. card:: See Also * :doc:`dp_char_ptr` * :doc:`tp_char_ptr` .. card:: See Also * Current Module * :doc:`variable_and_ptr` * Next Module * :doc:`../array_n_ptrs/array_n_ptrs` * Other Modules * :doc:`../malloc_ptr/malloc_ptr` * :doc:`../typecasting_n_ptr/typecasting_n_ptr` * :doc:`../funcs_n_ptrs/funcs_n_ptrs` * :doc:`../memcpy_ptr/memcpy_ptr` * :doc:`../const_ptr/const_ptr` * :doc:`../void_ptr/void_ptr` * :doc:`../array_of_ptr/array_of_ptr` * :doc:`../ptr_to_array/ptr_to_array` * :doc:`../function_ptr/function_ptr` * :doc:`../pre_incr_ptr/pre_incr_ptr` * :doc:`../post_incr_ptr/post_incr_ptr` * :doc:`../pre_decr_ptr/pre_decr_ptr` * :doc:`../post_decr_ptr/post_decr_ptr`