C++ pointer arithmetic

#include <iostream>

using namespace std;
const int MAX = 3;

int main () {
   int  var[MAX] = {10, 100, 200};
   int  *ptr;

   // let us have array address in pointer.
   ptr = var;
   
   for (int i = 0; i < MAX; i++) {
      cout << "Address of var[" << i << "] = ";
      cout << ptr << endl;

      cout << "Value of var[" << i << "] = ";
      cout << *ptr << endl;

      // point to the next location
      ptr++;
   }
   
   return 0;
}

4.67
3
Nick DeLeone 130 points

                                    #include &lt;stdio.h&gt;

const int MAX = 3;

int main () {

   int  var[] = {10, 100, 200};
   int  i, *ptr;

   /* let us have array address in pointer */
   ptr = &amp;var[MAX-1];
	
   for ( i = MAX; i &gt; 0; i--) {

      printf(&quot;Address of var[%d] = %x\n&quot;, i-1, ptr );
      printf(&quot;Value of var[%d] = %d\n&quot;, i-1, *ptr );

      /* move to the previous location */
      ptr--;
   }
	
   return 0;
}

4.67 (3 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
you can use pointer arithmetic in c pointers arithmetic c++ C++ pointer arithmetic C++ pointer arithmetic operations in c c++ arithmetic void pointer pointer arithmetic c++ examples void arithmetic pointer c++ what are pointer expression and arithmetic in c++ pointer arithmetics in c arithmetic of pointers in c what are the pointer arithmetic operations allowed in c++ how to do pointer arithmetic c++ c++ pointer arithmetic with reference pointer arithmetic program in c basic arithmetic operations using pointers c do pointer arithmetic c++ pointer arithmetic c c++ int function pointer arithmetic operations on pointers in c pointer arithmetic in c pointer arithmetic in c++ example arithmetic operations on pointers c pointer arithmetic pointer increment in c++ pointer operation pointer array address arithmetic in c++ pointer array address arithmetic in c+ pointer arithmetic pointer arithmetic in cpp arithmetic on pointers c++ program for implementing pointer arithemetic in cpp pointer arithmetic c__ does c++ use pointer arithmetic cpp pointer arithmetic arithmetic operations used with pointers c++ addition pointer c++ pointer addition c++ operations on addresses in cpp operations allowed on pointers c++ this pointer addition in c++ what is pointer arithmetic c++ array arithmetic c++ pointer arithmetic in c++ arithmetic operations in pointers in c++ pointer arithmetic c++ C++ Pointer arithmetiv c++ pointer addition do c++ have pointer arithmetic what is pointer arithmetic in c++ C++ pointer arithmetic
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source