<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>pointer | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/pointer/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Tue, 19 May 2020 08:17:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>pointer | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>Array vs pointer in C</title>
		<link>https://learncgames.com/array-vs-pointer-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=array-vs-pointer-in-c</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Wed, 27 May 2020 23:00:51 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[pointer]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=692</guid>

					<description><![CDATA[<p>A common pattern (I use the word loosely) in my C programs is to have an array of structs to hold things like asteroids and bullets in the game. There are two ways to process an array: As an array e.g. asteroids[index]. As a pointer to an individual array element. Asteroid * pAsteroid = &#38;(asteroids[index]); [&#8230;]</p>
The post <a href="https://learncgames.com/array-vs-pointer-in-c/">Array vs pointer in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:706,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/cocoparisienne-127419\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=826831&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20251116065429\/https:\/\/pixabay.com\/users\/cocoparisienne-127419\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 17:44:14&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-13 20:09:34&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-05 01:30:34&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-03-05 01:30:34&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:707,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=826831&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 17:44:21&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-13 20:09:38&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-05 01:30:34&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-03-05 01:30:34&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_693" aria-describedby="caption-attachment-693" style="width: 300px" class="wp-caption alignleft"><img fetchpriority="high" decoding="async" class="size-medium wp-image-693" src="https://learncgames.com/wp-content/uploads/2020/05/grid-826831_640-300x200.jpg" alt="Grid array" width="300" height="200" srcset="https://learncgames.com/wp-content/uploads/2020/05/grid-826831_640-300x200.jpg 300w, https://learncgames.com/wp-content/uploads/2020/05/grid-826831_640.jpg 640w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-693" class="wp-caption-text">Image by <a href="https://pixabay.com/users/cocoparisienne-127419/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=826831">Anja<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f917.png" alt="🤗" class="wp-smiley" style="height: 1em; max-height: 1em;" />#helpinghands #solidarity#stays healthy<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f64f.png" alt="🙏" class="wp-smiley" style="height: 1em; max-height: 1em;" /></a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=826831">Pixabay</a></figcaption></figure>
<p>A common pattern (<em>I use the word loosely</em>) in my C programs is to have an array of structs to hold things like asteroids and bullets in the game. There are two ways to process an array:</p>
<ol>
<li>As an array e.g. asteroids[index].</li>
<li>As a pointer to an individual array element. Asteroid * pAsteroid = &amp;(asteroids[index]); then refer to pAsteroid -&gt;</li>
</ol>
<p>One of the tents of software design though not that often said is that the easier the code is to read, the easier it is to understand. Programmers spend a lot of time reading code. Anything that lightens the cognitive load is good. I suspect it might also be faster, but not by a great deal.</p>
<p>Of course pointers make some programmers nervous. To me though they simplify the code. There is however another way to simplify the code. Use #define so you might have something like this:</p>
<pre><code class="language-c" data-line="">#define table asteroids[index]</code></pre>
<p>So everywhere you have a asteroids[index]., you put in table instead.<br />
This for example from Chapter 36 DrawAsteroids()</p>
<pre><code class="language-c" data-line="">	for (int i = 0; i&lt;MAXASTEROIDS; i++) {
		if (asteroids[i].active) {
			numAsteroids++;                    // keep track of how many onscreen
			int sizeIndex = asteroids[i].size; // 0-3
			int asize = sizes[sizeIndex];      // asteroid size 280,140, 70,35
			target.h = asize;
			target.w = asize;
			asteroidRect.h = asize;
			asteroidRect.w = asize;
			asteroidRect.x = asize * asteroids[i].rotdir;
			target.x = (int)asteroids[i].x;
			target.y = (int)asteroids[i].y;</code></pre>
<p>Would become</p>
<pre><code class="language-c" data-line="">	for (int i = 0; i&lt;MAXASTEROIDS; i++) {
		if (table.active) {
			numAsteroids++;                    // keep track of how many onscreen
			int sizeIndex = table.size; // 0-3
			int asize = sizes[sizeIndex];      // asteroid size 280,140, 70,35
			target.h = asize;
			target.w = asize;
			asteroidRect.h = asize;
			asteroidRect.w = asize;
			asteroidRect.x = asize * table.rotdir;
			target.x = (int)table.x;
			target.y = (int)table.y;</code></pre>
<p>What do you think?</p>The post <a href="https://learncgames.com/array-vs-pointer-in-c/">Array vs pointer in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">692</post-id>	</item>
	</channel>
</rss>
