<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3AHTTB%3APointers%3APointer_arithmetic</id>
	<title>SE250:HTTB:Pointers:Pointer arithmetic - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3AHTTB%3APointers%3APointer_arithmetic"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:HTTB:Pointers:Pointer_arithmetic&amp;action=history"/>
	<updated>2026-04-28T22:05:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE250:HTTB:Pointers:Pointer_arithmetic&amp;diff=2029&amp;oldid=prev</id>
		<title>Mark: 6 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:HTTB:Pointers:Pointer_arithmetic&amp;diff=2029&amp;oldid=prev"/>
		<updated>2008-11-03T05:09:51Z</updated>

		<summary type="html">&lt;p&gt;6 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td bgcolor=&amp;quot;#552200&amp;quot; width=&amp;quot;1000&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;image src=&amp;quot;http://www.rajithaonline.com/SE250/httb/pointers/final/arithmetic_head.png&amp;quot; width=&amp;quot;411&amp;quot; height=&amp;quot;92&amp;quot; alt=&amp;quot;Pointer Arithmetic Header Logo&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{SE250:HTTB:NAV&lt;br /&gt;
|prev=SE250:HTTB:Pointers:Basics&lt;br /&gt;
|next=SE250:HTTB:Pointers:Pointers_to_pointers}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Pointer Arithmetic===&lt;br /&gt;
Arithmetic Operations that can be performed on pointers include:&lt;br /&gt;
*Incrementing:&lt;br /&gt;
Incrementing a pointer increases the value of what the pointer is pointing to by 1.&lt;br /&gt;
The increment operator is (++).&amp;lt;br&amp;gt;&lt;br /&gt;
Eg.&amp;lt;br&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
 int *x;&lt;br /&gt;
 int arr[6];&lt;br /&gt;
 x = &amp;amp;arr[2];&lt;br /&gt;
 x++;&lt;br /&gt;
&lt;br /&gt;
So x will be pointing to the 3rd element in the array initially, after the increment, it will therefore point to the 4th element in the array.&amp;lt;br&amp;gt;&lt;br /&gt;
Note: In the diagram x is the value pointer is pointing at initially and x2 is the value its pointing at post increment.&amp;lt;br&amp;gt;&lt;br /&gt;
Ie.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;img src=&amp;#039;http://img114.imageshack.us/img114/4522/incptrxd0.png&amp;#039;&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
 *Just to clarify, incrementing will not increase the value, but the address being pointed to. &lt;br /&gt;
&lt;br /&gt;
*Decrementing&lt;br /&gt;
Decrementing is the opposite of incrementing, instead of increasing the value of the pointer by 1, it decreases the value by 1. The decrement operator is (--).&amp;lt;br&amp;gt;&lt;br /&gt;
Eg.&amp;lt;br&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
 int *x;&lt;br /&gt;
 int arr[6];&lt;br /&gt;
 x = &amp;amp;arr[2];&lt;br /&gt;
 --x;&lt;br /&gt;
So x will be pointing to the 3rd element in the array initially and after decrementing, it will therefore point to the 3rd element in the array.&lt;br /&gt;
Note: In the diagram x is the value pointer is pointing at initially and x2 is the value it’s pointing at post decrement.&amp;lt;br&amp;gt;&lt;br /&gt;
Ie.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;img src=&amp;#039;http://img114.imageshack.us/img114/2200/decptrjj5.png&amp;#039;&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
*Addition&lt;br /&gt;
You can add an integer to a pointer but you cannot add a pointer to a pointer.&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 int *x;&lt;br /&gt;
 int *y;&lt;br /&gt;
 int arr[6];&lt;br /&gt;
 x = &amp;amp;arr[2];&lt;br /&gt;
 y=x+2;&lt;br /&gt;
Here x is pointing to the 3rd element of the array and y will be pointing to the 5th element of the array.&amp;lt;br&amp;gt;&lt;br /&gt;
Ie.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;img src=&amp;#039;http://img114.imageshack.us/img114/1898/addptrmd5.png&amp;#039;&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
*Subtraction&lt;br /&gt;
Pretty much the opposite of addition…&amp;lt;br&amp;gt;&lt;br /&gt;
Example:&amp;lt;br&amp;gt;&lt;br /&gt;
 int *x;&lt;br /&gt;
 int *y;&lt;br /&gt;
 int arr[6];&lt;br /&gt;
 x = &amp;amp;arr[2];&lt;br /&gt;
 y=x-2;&lt;br /&gt;
Here x is pointing to the 3rd element of the array and y will be pointing to the 1st element of the array.&amp;lt;br&amp;gt;&lt;br /&gt;
Ie.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;img src=&amp;#039;http://img114.imageshack.us/img114/6645/subptrnx2.png&amp;#039;&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{SE250:HTTB:NAV&lt;br /&gt;
|prev=SE250:HTTB:Pointers:Basics&lt;br /&gt;
|next=SE250:HTTB:Pointers:Pointers_to_pointers}}&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>