Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>(Un)fortunately, the asterisk <code>*</code> has many <em>different</em> meanings depending on context. So, let's look at the relevant ones. Let us write <code>T</code> for some arbitrary type (say <code>int</code>):</p> <pre><code>T x; // variable of type x, stored somewhere in memory T * pt; // a pointer to a variable of type x -- doesn't have a value just yet pt = &amp;x; // the value of pt is now the address of the variable x </code></pre> <p>So far so good. We have used the asterisk to designate a new <em>type</em>, namely <code>T*</code>, which is a "pointer to <code>T</code>".</p> <p>But what do we do with a pointer? We can <em>dereference</em> it to get to the value of the variable <em>at the address pointed to by the pointer</em>:</p> <pre><code>T y; // another variable of type T y = *pt; // equivalent to y = x; *pt = 81; // equivalent to x = 81; </code></pre> <p>So, if the asterisk is part of the typename, then it designates a pointer type. If it comes before a variable name (which is itself of pointer type), then it dereferences the pointer.</p> <p>[Clarification:] <em>In C</em>, pointers naturally go hand-in-hand with the "address-of" operator <code>&amp;</code>, which is used to actually obtain a pointer to something. <em>In Obj-C, a pointer is obtained as the result of object allocation (+ initailization):</em> <code>T * pt = [T new];</code></p> <p>Beware that Obj-C offers an alternative syntax to the traditional C and C++ pointer syntax, so you may encounter pointers in other guises.[/Clarification]</p> <p>(The asterisk can also be used as a binary operator of course, so you can have something like this: <code>int x = 5; int * p = &amp;x; int y = *p * *p;</code>.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload