CrazyEngineers
  • C++ Pointers-Concept Explained

    Updated: Oct 21, 2024
    Views: 974
    C++ pointer or simply a pointer is a simple variable that has the capability to store the memory address of some location.<BR><BR>Lets discuss a small program for illustration:<BR>
    <BR>int * p;<BR>int q=10;<BR>p=&q;<BR>cout&lt;&lt;"Address of q is: "&lt;&lt;p&lt;&lt;endl;<BR>cout&lt;&lt;"Value of q is: "&lt;&lt;*p&lt;&lt;endl;<BR>
    <UL>
    [*]Here p is a pointer variable and q is a simple interger variable.
    [*]& is the address operator. So when we've the statement p=&q, we are actually initializing p with the memory address of q.
    [*]As memory addresses are generally of hexadecimal type, so p now also has some hexadecimal value.
    [*]p as such has no data type. But int *p means that the data type of the contents of memory location referenced by p (i.e. q) is interger.
    [*]So p is also called pointer to integer.
    [*]Displaying p will display the memory address of the variable q.
    [*]*p displays the content of the memory location it refers to i.e. value of q.</UL>
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Home Channels Search Login Register