Question: I have an XML feed that looks like this:

```
<?xml version="1.0" encoding="UTF-8"?>
<smf:xml-feed xmlns:smf="http://www.simplemachines.org/" xmlns="http://www.simplemachines.org/xml/recent" xml:lang="en-US">
  <recent-post>
    <time>April 04, 2021, 04:20:47 pm</time>
    <id>1909114</id>
    <subject>Title</subject>
    <body><![CDATA[<a href="#"><img src="image.png">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure rerum in tempore sit ducimus doloribus quod commodi eligendi ipsam porro non fugiat nisi eaque delectus harum aspernatur recusandae incidunt quasi.</a>]]></body>
  </recent-post>
</smf:xml-feed>

```

I want to extract the image `src` from the `body` and then save it to a new XML file that includes an element for `image`.

So far, I have

```
$xml = 'https://example.com/feed.xml';
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->recover = true;
libxml_use_internal_errors(true);
$dom->loadXML($xml);

$xpath = new DOMXPath( $dom );
$nodes = $xpath->query( 'smf:xml-feed/recent-post/body' );

foreach( $nodes as $node )
{
    $html = new DOMDocument();
    $html->loadHTML( $node->nodeValue );
    $src = $html->getElementsByTagName( 'img' )->item(0)->getAttribute('src');
    echo $src;
}

```

But when I try to print out `$nodes`, I get nothing. What am I missing?

Answer: 
You're not only dereferencing the pointer, you're updating the value as well.

```
 ptr[2] = 0x05;

```

updates the value at 3rd octet. So, for a starting value of

```
 (0x) 04 03 02 01

```

it gets modified like

```
 (0x) 04 05 02 01    
         ^--------- ptr[2]

```

To add, from `C11`, chapter 6.3.2.3,

> 
> *[...] When a pointer to an object is converted to a pointer to a character type, the result points to the lowest addressed byte of the object. Successive increments of the result, up to the size of the object, yield pointers to the remaining bytes of the object.*
> 
> 
> 

So, in a [little-endian system](https://en.wikipedia.org/wiki/Endianness), it looks like

```
ptr[0] = 01
ptr[1] = 02
ptr[2] = 03
ptr[3] = 04 

```

and you're modifying `ptr[2]`, so the value change is reflected in result.
`var` is an unsigned long variable, which is 4 bytes in a 32-bit system and 8 bytes in a 64-bit system.

`ptr` is a pointer to an unsigned char. `ptr` looks at the "first" byte of `var`, due to the fact that it is a **char** pointer.

`ptr[2]` is as '\*(ptr + 2)' in pointer arithmetics, and therefore this expression give us the address of 2 bytes ahead and dereferencing the pointer.

So, in the end, the hex value `0x05` will be assigned to the 3rd byte of `var`.