An array name is a pointer constant because the address stored in it cannot be changed at runtime

True/False: A) True<br>B) False</div> <fieldset class="source"> <legend> <i class="fa fa-quote-left fa-fw" aria-hidden="true"></i> Textbook&nbsp; </legend> <table cellspacing="0" cellpadding="0" class="textbook_container"> <tr> <td> <div class="textbook_coverpage"> <a target="_blank" href="https://biology-forums.com/index.php?action=textbook;id=343"> <img srx="https://images-na.ssl-images-amazon.com/images/I/51hJoz2BNLL._SX389_BO1,204,203,200_.jpg" title="Database Concepts, 7e. (Kroenke, Auer)" alt="Database Concepts"> </a> <div> <a data-fancybox="flashcards" data-type="ajax" src="https://biology-forums.com/index.php?action=textbook;page=info;topicid=-343" rel="nofollow"><i class="fa fa-search" aria-hidden="true"></i></a> </div> </div> </td> <td> <span style="font-weight:bold" itemprop="name"><h2 class="reset"><a target="_blank" href="https://biology-forums.com/index.php?action=textbook;id=343">Database Concepts</a></h2></span><br> <img style="vertical-align:text-bottom" srx="https://biology-forums.com/Themes/default/images/tree_branch.png" alt=""> Edition: <span style="font-weight:bold" itemprop="bookEdition">7<sup>th</sup></span><br> <img style="vertical-align:text-bottom" srx="https://biology-forums.com/Themes/default/images/tree_branch_end.png" alt=""> Authors: <span style="font-weight:bold" itemprop="author">Kroenke, Auer</span> </td> </tr> </table> </fieldset> </td> </tr> <tr> <td id="thread_details"> <div> Read 25 times </div> <div> <span itemprop="answerCount">1</span> Reply </div> </td> </tr> </table> </td> </tr> <tr> <td colspan="2"> <div id="post_buttons"> <div id="pb_report"> <a target="_blank" title="Report an Issue" href="https://biology-forums.com/index.php?action=reporttm;topic=741895.0;msg=2137937"> Report </a> </div> </div> <div id="post_options_container2137937" style="display:none"> <div id="post_buttons" style="padding-top:0"> </div> </div> </td> </tr> <tr> <td colspan="2"> <div class="post_signature_container"> <div class="post_signature_holder"> <span style="font-size:8pt;line-height:1.3em">Genuine Coder</span> </div> </div> </td> </tr> <tr> <td colspan="2" class="thread_ad"> <div class="adblock_468"> <script async>

Constant Pointers

A constant pointer in C cannot change the address of the variable to which it is pointing, i.e., the address will remain constant. Therefore, we can say that if a constant pointer is pointing to some variable, then it cannot point to any other variable.

Syntax of Constant Pointer

Declaration of a constant pointer is given below:

Let's understand the constant pointer through an example.

In the above code:

  • We declare two variables, i.e., a and b with values 1 and 2, respectively.
  • We declare a constant pointer.
  • First, we assign the address of variable 'a' to the pointer 'ptr'.
  • Then, we assign the address of variable 'b' to the pointer 'ptr'.
  • Lastly, we try to print the value of the variable pointed by the 'ptr'.

Output

An array name is a pointer constant because the address stored in it cannot be changed at runtime

In the above output, we can observe that the above code produces the error "assignment of read-only variable 'ptr'". It means that the value of the variable 'ptr' which 'ptr' is holding cannot be changed. In the above code, we are changing the value of 'ptr' from &a to &b, which is not possible with constant pointers. Therefore, we can say that the constant pointer, which points to some variable, cannot point to another variable.

Pointer to Constant

A pointer to constant is a pointer through which the value of the variable that the pointer points cannot be changed. The address of these pointers can be changed, but the value of the variable that the pointer points cannot be changed.

Syntax of Pointer to Constant

Declaration of a pointer to constant is given below:

Let's understand through an example.

  • First, we write the code where we are changing the value of a pointer

In the above code:

  • We declare two variables, i.e., a and b with the values 100 and 200 respectively.
  • We declare a pointer to constant.
  • First, we assign the address of variable 'a' to the pointer 'ptr'.
  • Then, we assign the address of variable 'b' to the pointer 'ptr'.
  • Lastly, we try to print the value of 'ptr'.

Output

An array name is a pointer constant because the address stored in it cannot be changed at runtime

The above code runs successfully, and it shows the value of 'ptr' in the output.

  • Now, we write the code in which we are changing the value of the variable to which the pointer points.

In the above code:

  • We declare two variables, i.e., 'a' and 'b' with the values 100 and 200 respectively.
  • We declare a pointer to constant.
  • We assign the address of the variable 'b' to the pointer 'ptr'.
  • Then, we try to modify the value of the variable 'b' through the pointer 'ptr'.
  • Lastly, we try to print the value of the variable which is pointed by the pointer 'ptr'.

Output

An array name is a pointer constant because the address stored in it cannot be changed at runtime

The above code shows the error "assignment of read-only location '*ptr'". This error means that we cannot change the value of the variable to which the pointer is pointing.

Constant Pointer to a Constant

A constant pointer to a constant is a pointer, which is a combination of the above two pointers. It can neither change the address of the variable to which it is pointing nor it can change the value placed at this address.

Syntax

Declaration for a constant pointer to a constant is given below:

Let's understand through an example.

In the above code:

  • We declare two variables, i.e., 'a' and 'b' with the values 10 and 90, respectively.
  • We declare a constant pointer to a constant and then assign the address of 'a'.
  • We try to change the value of the variable 'a' through the pointer 'ptr'.
  • Then we try to assign the address of variable 'b' to the pointer 'ptr'.
  • Lastly, we print the value of the variable, which is pointed by the pointer 'ptr'.

Output

An array name is a pointer constant because the address stored in it cannot be changed at runtime

The above code shows the error "assignment of read-only location '*ptr'" and "assignment of read-only variable 'ptr'". Therefore, we conclude that the constant pointer to a constant can change neither address nor value, which is pointing by this pointer.


Can you change the address that an array name points to?

The difference between a pointer variable and an array name is that you can never change the address of the array name. It will always point to the first element of the array as long as it exists.

How does pointer store address?

A pointer is a special kind of variable. Pointers are designed for storing memory address i.e. the address of another variable. Declaring a pointer is the same as declaring a normal variable except you stick an asterisk '*' in front of the variables identifier.

Does a pointer store a memory address?

A pointer variable (or pointer in short) is basically the same as the other variables, which can store a piece of data. Unlike normal variable which stores a value (such as an int, a double, a char), a pointer stores a memory address.