Pointer Increment for different size variable - C++ Data Type

C++ examples for Data Type:Pointer

Description

Pointer Increment for different size variable

Demo Code

#include <iostream>
using namespace std;
typedef struct {
   char c;/*from w ww . j  ava2 s  .c o  m*/
   short s;
   int i;
   long l;
   float f;
   double d;
   long double ld;
} Primitives;

int main() {
   Primitives p[10];
   Primitives* pp = p;
   cout << "sizeof(Primitives) = " << sizeof(Primitives) << endl;
   cout << "pp = " << (long)pp << endl;
   pp++;
   cout << "pp = " << (long)pp << endl;
}

Result


Related Tutorials