<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pointer on Cheat Sheet</title><link>/tags/pointer/</link><description>Recent content in Pointer on Cheat Sheet</description><generator>Hugo</generator><language>en</language><atom:link href="/tags/pointer/index.xml" rel="self" type="application/rss+xml"/><item><title>Pointers and Arrays</title><link>/programming/c/pointer/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/programming/c/pointer/</guid><description>&lt;h1 id="pointers-and-arrays"&gt;Pointers and Arrays&lt;a class="anchor" href="#pointers-and-arrays"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;h2 id="pointer-and-array"&gt;Pointer and Array&lt;a class="anchor" href="#pointer-and-array"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id="pointer-decay"&gt;Pointer Decay&lt;a class="anchor" href="#pointer-decay"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;In C, an array expression in most contexts automatically converts (&amp;ldquo;decays&amp;rdquo;) into a pointer to its first element.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When an array is passed as an argument to a function, what is actually passed is a pointer to its first element.&lt;/li&gt;
&lt;li&gt;The following function parameter declarations have identical signatures:
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-c" data-lang="c"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#cf222e"&gt;void&lt;/span&gt; &lt;span style="color:#6639ba"&gt;f&lt;/span&gt;&lt;span style="color:#1f2328"&gt;(&lt;/span&gt;&lt;span style="color:#cf222e"&gt;int&lt;/span&gt; arr&lt;span style="color:#1f2328"&gt;[]);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#cf222e"&gt;void&lt;/span&gt; &lt;span style="color:#6639ba"&gt;f&lt;/span&gt;&lt;span style="color:#1f2328"&gt;(&lt;/span&gt;&lt;span style="color:#cf222e"&gt;int&lt;/span&gt; arr&lt;span style="color:#1f2328"&gt;[&lt;/span&gt;&lt;span style="color:#0550ae"&gt;10&lt;/span&gt;&lt;span style="color:#1f2328"&gt;]);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#cf222e"&gt;void&lt;/span&gt; &lt;span style="color:#6639ba"&gt;f&lt;/span&gt;&lt;span style="color:#1f2328"&gt;(&lt;/span&gt;&lt;span style="color:#cf222e"&gt;int&lt;/span&gt; &lt;span style="color:#0550ae"&gt;*&lt;/span&gt;arr&lt;span style="color:#1f2328"&gt;);&lt;/span&gt; &lt;span style="color:#57606a"&gt;// Adjusted signature
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="multidimensional-array-parameters"&gt;Multidimensional Array Parameters&lt;a class="anchor" href="#multidimensional-array-parameters"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;When passing a multidimensional array to a function, all dimensions except the first must be explicitly specified:&lt;/p&gt;</description></item><item><title>Variables and Basic Types</title><link>/programming/cpp/primer/variables-and-basic-types/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/programming/cpp/primer/variables-and-basic-types/</guid><description>&lt;h1 id="variables-and-basic-types"&gt;Variables and Basic Types&lt;a class="anchor" href="#variables-and-basic-types"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Based on &lt;em&gt;C++ Primer, 5th ed.&lt;/em&gt; Chapter 2 (Variables and Basic Types).&lt;/p&gt;
&lt;h2 id="type-definition"&gt;Type Definition&lt;a class="anchor" href="#type-definition"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The type of an object defines the &lt;strong&gt;data&lt;/strong&gt; that an object might contain and what &lt;strong&gt;operations&lt;/strong&gt; that object can perform. Among the operations that many types support is the ability to &lt;strong&gt;convert&lt;/strong&gt; objects of the given type to other, related types.&lt;/p&gt;
&lt;h2 id="string-literal"&gt;String Literal&lt;a class="anchor" href="#string-literal"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The type of a string literal is &lt;code&gt;const char *&lt;/code&gt;. See &lt;a href="../../programming/c/c-vs-cpp/#string-literal-typing"&gt;String Literal Typing&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Pointer</title><link>/programming/go/pointer/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/programming/go/pointer/</guid><description>&lt;h1 id="pointer"&gt;Pointer&lt;a class="anchor" href="#pointer"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Go is technically a &lt;strong&gt;pass-by-value&lt;/strong&gt; language. However, certain types behave as if they are &lt;strong&gt;pass-by-reference&lt;/strong&gt; because they are implemented using pointers under the hood.&lt;/p&gt;
&lt;h2 id="types-with-pointer-implementation"&gt;Types with Pointer Implementation&lt;a class="anchor" href="#types-with-pointer-implementation"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The following types are implemented as pointers or contain pointers in their internal headers. When passed to a function, the pointer is copied (passed by value), but it still points to the same underlying data.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;slice&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;map&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;function&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;channel&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;interface&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="slice-caveat"&gt;Slice Caveat&lt;a class="anchor" href="#slice-caveat"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;While you can modify the elements of a slice passed to a function, you cannot change its length (eg. by &lt;code&gt;append&lt;/code&gt;) such that the change is reflected in the caller. This is because the slice header (which contains the length and capacity) is passed by value.&lt;/p&gt;</description></item></channel></rss>