<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[multi dimensional array with pointer  ??]]></title><description><![CDATA[<p>Hello, I am looking a prof's code. At some point, I found codes like following.</p>
<pre><code>char	**myob[2];
int 	**obj_n[10][2];
</code></pre>
<p>could anyone tell me please what does the first and second codes mean. I understand that char** carray is same like char* carray[] i.e. array of string. But I do not know what char ** myob[2] mean. I also do not know how I can get access to the elements of this object.<br />
Similarly, at other place I see code like</p>
<pre><code>template &lt;class T&gt;
int DeAlloc2DMemory(T ***ppArray, int nr, int nc);
</code></pre>
<p>What does the three stars means and how can I call it? Could anyone can answer these two question please?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/301264/multi-dimensional-array-with-pointer</link><generator>RSS for Node</generator><lastBuildDate>Wed, 12 Aug 2026 04:34:16 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/301264.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 22 Mar 2012 21:25:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to multi dimensional array with pointer  ?? on Thu, 22 Mar 2012 21:25:07 GMT]]></title><description><![CDATA[<p>Hello, I am looking a prof's code. At some point, I found codes like following.</p>
<pre><code>char	**myob[2];
int 	**obj_n[10][2];
</code></pre>
<p>could anyone tell me please what does the first and second codes mean. I understand that char** carray is same like char* carray[] i.e. array of string. But I do not know what char ** myob[2] mean. I also do not know how I can get access to the elements of this object.<br />
Similarly, at other place I see code like</p>
<pre><code>template &lt;class T&gt;
int DeAlloc2DMemory(T ***ppArray, int nr, int nc);
</code></pre>
<p>What does the three stars means and how can I call it? Could anyone can answer these two question please?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2194381</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2194381</guid><dc:creator><![CDATA[euklid]]></dc:creator><pubDate>Thu, 22 Mar 2012 21:25:07 GMT</pubDate></item><item><title><![CDATA[Reply to multi dimensional array with pointer  ?? on Thu, 22 Mar 2012 21:38:07 GMT]]></title><description><![CDATA[<p>char **myob[2] is a array of two pointers to pointer to char.</p>
<p>i think this site can help you to understand the pointer structures: <a href="http://cdecl.ridiculousfish.com/?q=char+**+myob%5B2%5D" rel="nofollow">http://cdecl.ridiculousfish.com/?q=char+**+myob[2]</a></p>
<p>the function must be called in this way:</p>
<pre><code class="language-cpp">...
int     **obj_n[10][2]; //obj_n as array 10 of array 2 of pointer to pointer to int
DeAlloc2DMemory(&amp;obj_n, 10, 2);
</code></pre>
<p>the three stars means a pointer to a pointer to a pointer<br />
you should read something about pointers <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2194385</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2194385</guid><dc:creator><![CDATA[vario-500]]></dc:creator><pubDate>Thu, 22 Mar 2012 21:38:07 GMT</pubDate></item><item><title><![CDATA[Reply to multi dimensional array with pointer  ?? on Thu, 22 Mar 2012 21:44:38 GMT]]></title><description><![CDATA[<p>euklid schrieb:</p>
<blockquote>
<p>I understand that char** carray is same like char* carray[] i.e. array of string.</p>
</blockquote>
<p>Which is wrong in most cases. This might help you to understand why: <a href="http://c-faq.com/aryptr/aryptr2.html" rel="nofollow">http://c-faq.com/aryptr/aryptr2.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2194388</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2194388</guid><dc:creator><![CDATA[HyperSonic]]></dc:creator><pubDate>Thu, 22 Mar 2012 21:44:38 GMT</pubDate></item><item><title><![CDATA[Reply to multi dimensional array with pointer  ?? on Thu, 22 Mar 2012 22:07:12 GMT]]></title><description><![CDATA[<p>thank you so much for the answsers!</p>
<pre><code>char** myob[2];
	printf(&quot;size of aaray: %d\n&quot;,sizeof(myob));
	myob[0][0]	=&quot;a&quot;;
        myob[0][1]	=&quot;b&quot;;	

	int i;
	for( i=0; i &lt;2; i++)
	{
		printf(&quot;char %s \n&quot;,myob[0][0]);
	}
</code></pre>
<p>The size of mbob is it is showing 16. I do not understand why sizeof(char)=1 but sizeof(char*)=8. Similarly I do not know where is wrong in my above test code.<br />
could you please help me in some way.<br />
thank you so much in advance !</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2194398</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2194398</guid><dc:creator><![CDATA[euklid]]></dc:creator><pubDate>Thu, 22 Mar 2012 22:07:12 GMT</pubDate></item><item><title><![CDATA[Reply to multi dimensional array with pointer  ?? on Fri, 23 Mar 2012 10:19:16 GMT]]></title><description><![CDATA[<p>euklid schrieb:</p>
<blockquote>
<p>The size of mbob is it is showing 16. I do not understand why sizeof(char)=1 but sizeof(char*)=8.</p>
</blockquote>
<p>Read something about pointers. A pointer points to an address on your system, and therefore the type it points to has usually* no influence on its size.</p>
<p>* Although this is not required by the language, you would have trouble to find a system where sizeof(int*) != sizeof(double*).<br />
<a href="http://stackoverflow.com/questions/1241205/are-all-data-pointers-of-the-same-size-in-one-platform" rel="nofollow">http://stackoverflow.com/questions/1241205/are-all-data-pointers-of-the-same-size-in-one-platform</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2194403</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2194403</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Fri, 23 Mar 2012 10:19:16 GMT</pubDate></item><item><title><![CDATA[Reply to multi dimensional array with pointer  ?? on Fri, 23 Mar 2012 09:44:36 GMT]]></title><description><![CDATA[<p>euklid schrieb:</p>
<blockquote>
<pre><code>char	**myob[2];
int 	**obj_n[10][2];
</code></pre>
<p>could anyone tell me please what does the first and second codes mean.</p>
</blockquote>
<p>Try <a href="http://cdecl.org/" rel="nofollow">http://cdecl.org/</a><br />
Keep in mind that postfix operators/declarators have a higher precedence than prefix operators. So, your declarations are equivalent to</p>
<pre><code>char	*(*(myob[2]));
int 	*(*((obj_n[10])[2]));
</code></pre>
<p>(added parens for explicit grouping)<br />
You can practically read the declaration from the inside to the outside. Example:<br />
myob is a 2-element array of pointers to pointers to char.</p>
<p>euklid schrieb:</p>
<blockquote>
<p>Similarly, at other place I see code like</p>
<pre><code>template &lt;class T&gt;
int DeAlloc2DMemory(T ***ppArray, int nr, int nc);
</code></pre>
<p>What does the three stars means</p>
</blockquote>
<p>It means that you found <em>very</em> ugly C++ code written by a person that does not know what proper encapsulation is and how to use it effectivly.</p>
<p>euklid schrieb:</p>
<blockquote>
<p>and how can I call it?</p>
</blockquote>
<p>Probably like this:</p>
<pre><code class="language-cpp">const int nr = 42;
const int nc = 23;
int** ugly = 0;
Alloc2DMemory(&amp;ugly,nr,nc);
...
use it
...
DeAlloc2DMemory(&amp;ugly,nr,nc);
</code></pre>
<p>Of course, this is bad because <code>ugly</code> would be the only reference to the dynamically allocated memory while it is just a stupid pointer that does not feel responsible for managing this resource. This kind of coding style will eventually bite you in the a**. It's not exception-safe and puts the burden of managing the resource on the user instead of delegating this responsibility to some smart object. Also, this memory layout is at least questionable. I would prefer to use a single block of memory and order the elements in row major or column major.</p>
<p>Cheers!<br />
kk</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2194508</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2194508</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Fri, 23 Mar 2012 09:44:36 GMT</pubDate></item><item><title><![CDATA[Reply to multi dimensional array with pointer  ?? on Fri, 23 Mar 2012 09:54:56 GMT]]></title><description><![CDATA[<p>euklid schrieb:</p>
<blockquote>
<pre><code>char** myob[2];
printf(&quot;size of aaray: %d\n&quot;,sizeof(myob));
myob[0][0]=&quot;a&quot;;
myob[0][1]=&quot;b&quot;;
</code></pre>
</blockquote>
<p>First of all: This code invokes undefined behaviour. myob is an array of pointers which you did not initialize properly. The array contains garbage. But you actually read the pointer values and dereference them =&gt; UB</p>
<p>euklid schrieb:</p>
<blockquote>
<p>The size of mbob is it is showing 16.</p>
</blockquote>
<p>That's not an unusual result. Apparently, on your system you need 8 bytes to store a pointer value. Since myob is a 2-element array of pointers, you need 16 bytes to store this array.</p>
<p>euklid schrieb:</p>
<blockquote>
<p>I do not understand why sizeof(char)=1 but sizeof(char*)=8.</p>
</blockquote>
<p>Why not? What's so funny about that? char* is the type of a pointer to char. A pointer variable is supposed to store the memory address of something. On a 64bit system, a pointer is usually 64bit wide which explains the value of sizeof(char*) you observed.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2194517</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2194517</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Fri, 23 Mar 2012 09:54:56 GMT</pubDate></item></channel></rss>