const char triple pointer =========================== In this section, you are going to learn .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What is ``const char ***r;`` ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What is ``const char *const **r;`` ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What is ``const char *const *const *r;`` ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What is ``const char *const *const *const r;`` ? * Inorder to answer above questions, let us remember a very simple rule .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Anything after ``const`` keyword CAN NOT be changed * Is it that simple ? * Yes. Let us see how do we apply above rule to answer the questions .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Topics in this section, * :ref:`Example 1 : const char ***r; ` * :ref:`Example 2 : const char *const **r; ` * :ref:`Example 3 : const char *const *const *r; ` * :ref:`Example 4 : const char *const *const *const r; ` * :ref:`Summary ` .. _const_ptr_char_tp_ex_1: .. tab-set:: .. tab-item:: Example 1 : const char \*\*\*r; * Step 1 : Consider the statement .. code-block:: c const char ***r; * Step 2 : Remove all keywords after ``const`` .. code-block:: c const ***r; * Step 3 : Remove everything before ``const`` .. code-block:: c const ***r; * Step 4 : Remove assignment .. code-block:: c const ***r; * Step 5 : Now apply the rule. Anything after ``const`` keyword CAN NOT be changed .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow * We see ``***r`` after ``const`` * Means, ``***r`` CAN NOT be changed again in next line * Step 6 : Bonus point ! r, \*r, \*\*r, \*\*\*r are different .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Means, ``r``, ``*r``, ``**r`` can still be changed .. _const_ptr_char_tp_ex_2: .. tab-set:: .. tab-item:: Example 2 : const char \*const \*\*r; * There are two occurences of const keyword * Hence, let us apply the same rules two times .. tab-set:: .. tab-item:: 2.1 : Rules w.r.t first const * Step 1 : Consider the statement .. code-block:: c const char *const **r * Step 2 : Remove all keywords after first const .. code-block:: c const ***r * Step 3 : Remove everything before first const .. code-block:: c const ***r * Step 4 : Remove assignment .. code-block:: c const ***r * Step 5 : Now apply the rule. Anything after const keyword CAN NOT be changed .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow \*\*\*r CAN NOT be changed .. tab-set:: .. tab-item:: 2.2 : Rules w.r.t second const * Step 1 : Consider the statement .. code-block:: c const char *const **r * Step 2 : Remove all keywords after second const .. code-block:: c const char *const **r * Step 3 : Remove everything before second const .. code-block:: c const **r * Step 4 : Remove assignment .. code-block:: c const **r * Step 5 : Now apply the rule. Anything after const keyword CAN NOT be changed .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow \*\*r CAN NOT be changed .. tab-set:: .. tab-item:: Summary of Example 2 .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow * \*\*\*r, \*\*r CAN NOT be changed * \*r, r can be changed .. _const_ptr_char_tp_ex_3: .. tab-set:: .. tab-item:: Example 3 : const char \*const \*const \*r; * There are three occurences of const keyword * Hence, let us apply the same rules three times .. tab-set:: .. tab-item:: 3.1 : Rules w.r.t first const * Step 1 : Consider the statement .. code-block:: c const char *const *const *r; * Step 2 : Remove all keywords after first const .. code-block:: c const ***r; * Step 3 : Remove everything before first const .. code-block:: c const ***r; * Step 4 : Remove assignment .. code-block:: c const ***r; * Step 5 : Now apply the rule. Anything after const keyword CAN NOT be changed .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow \*\*\*r CAN NOT be changed .. tab-set:: .. tab-item:: 3.2 : Rules w.r.t second const * Step 1 : Consider the statement .. code-block:: c const char *const *const *r; * Step 2 : Remove all keywords after second const .. code-block:: c const char *const **r; * Step 3 : Remove everything before second const .. code-block:: c const **r; * Step 4 : Remove assignment .. code-block:: c const **r; * Step 5 : Now apply the rule. Anything after const keyword CAN NOT be changed .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow \*\*r CAN NOT be changed .. tab-set:: .. tab-item:: 3.3 : Rules w.r.t third const * Step 1 : Consider the statement .. code-block:: c const char *const *const *r; * Step 2 : Remove all keywords after third const .. code-block:: c const char *const *const *r; * Step 3 : Remove everything before third const .. code-block:: c const *r; * Step 4 : Remove assignment .. code-block:: c const *r; * Step 5 : Now apply the rule. Anything after const keyword CAN NOT be changed .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow \*r CAN NOT be changed .. tab-set:: .. tab-item:: Summary of Example 3 .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow * \*\*\*r, \*\*r, \*r, CAN NOT be changed * r can be changed .. _const_ptr_char_tp_ex_4: .. tab-set:: .. tab-item:: Example 4 : const char \*const \*const \*const r; * There are Four occurences of const keyword * Hence, let us apply the same rules Four times .. tab-set:: .. tab-item:: 4.1 : Rules w.r.t first const * Step 1 : Consider the statement .. code-block:: c const char *const *const *const r; * Step 2 : Remove all keywords after first const .. code-block:: c const ***r; * Step 3 : Remove everything before first const .. code-block:: c const ***r; * Step 4 : Remove assignment .. code-block:: c const ***r; * Step 5 : Now apply the rule. Anything after const keyword CAN NOT be changed .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow \*\*\*r CAN NOT be changed .. tab-set:: .. tab-item:: 4.2 : Rules w.r.t second const * Step 1 : Consider the statement .. code-block:: c const char *const *const *const r; * Step 2 : Remove all keywords after second const .. code-block:: c const char *const **r; * Step 3 : Remove everything before second const .. code-block:: c const **r; * Step 4 : Remove assignment .. code-block:: c const **r; * Step 5 : Now apply the rule. Anything after const keyword CAN NOT be changed .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow \*\*r CAN NOT be changed .. tab-set:: .. tab-item:: 4.3 : Rules w.r.t third const * Step 1 : Consider the statement .. code-block:: c const char *const *const *const r; * Step 2 : Remove all keywords after third const .. code-block:: c const char *const *const *r; * Step 3 : Remove everything before third const .. code-block:: c const *r; * Step 4 : Remove assignment .. code-block:: c const *r; * Step 5 : Now apply the rule. Anything after const keyword CAN NOT be changed .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow \*r CAN NOT be changed .. tab-set:: .. tab-item:: 4.4 : Rules w.r.t fourth const * Step 1 : Consider the statement .. code-block:: c const char *const *const *const r; * Step 2 : Remove all keywords after fourth const .. code-block:: c const char *const *const *const r; * Step 3 : Remove everything before fourth const .. code-block:: c const r; * Step 4 : Remove assignment .. code-block:: c const r; * Step 5 : Now apply the rule. Anything after const keyword CAN NOT be changed .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow r CAN NOT be changed .. tab-set:: .. tab-item:: Summary of Example 4 .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow \*\*\*r, \*\*r, \*r, r CAN NOT be changed .. _const_ptr_char_tp_ex_5: .. tab-set:: .. tab-item:: Summary ===================================== ==================================================== Statement Meaning ===================================== ==================================================== const char \*\*\*r; * ``***r`` CAN NOT be changed again * ``**r`` can be changed again * ``*r`` can be changed again * ``r`` can be changed again const char \*const \*\*r; * ``***r`` CAN NOT be changed again * ``**r`` CAN NOT be changed again * ``*r`` can be changed again * ``r`` can be changed again const char \*const \*const \*r; * ``***r`` CAN NOT be changed again * ``**r`` CAN NOT be changed again * ``*r`` CAN NOT be changed again * ``r`` can be changed again const char \*const \*const \*const r; * ``***r`` CAN NOT be changed again * ``**r`` CAN NOT be changed again * ``*r`` CAN NOT be changed again * ``r`` can be changed again ===================================== ==================================================== .. card:: See Also * Current Module * :doc:`../const_ptr` * Previous Module * :doc:`../../memcpy_ptr/memcpy_ptr` * Next Module * :doc:`../../void_ptr/void_ptr` * Other Modules * :doc:`../../variable_and_ptr/variable_and_ptr` * :doc:`../../array_n_ptrs/array_n_ptrs` * :doc:`../../malloc_ptr/malloc_ptr` * :doc:`../../typecasting_n_ptr/typecasting_n_ptr` * :doc:`../../funcs_n_ptrs/funcs_n_ptrs` * :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`