Hello everybody, I am a beginner c/c++ wannabe programmer who is currently taking his first course on it. I was confused about pointers so I read the article on them on cplusplus.com, and while it clarified them a great deal, towards the very end I encountered some code that no matter how hard I tried, just couldn't make any sense as to why it works. Here it is:

#include <iostream>
using namespace std;
void increase (void* data, int psize)
  if ( psize == sizeof(char) )
  { char* pchar; pchar=(char*)data; ++(*pchar); }
  else if (psize == sizeof(int) )
  { int* pint; pint=(int*)data; ++(*pint); }
int main ()
  char a = 'x';
  int b = 1602;
  increase (&a,sizeof(a));
  increase (&b,sizeof(b));
  cout << a << ", " << b << endl;
  return 0;
This code returns: y, 1603.

The particular issue that I have here is with the definition of the function increase; let's examine it's behavior when it's first argument is an int: it checks to see if it's input psize is the size of int. All right. It then creates a pointer called pint. Great. Now, it assigns to the POINTER pint the VALUE to which the pointer "data" points at, which... doesn't make sense at all to me! Doesn't that mean the the pointer now points to an address in memory that is equal to the value of "data"? And what in the world is at that address? The function then dereferences pint and therefore increases the value of what's pointed at by pint by 1, that part I understand. BUT, how comes that the value of what's pointed at by pint is the value of data?! - I have already shown before how I came to the conclusion that before executing ++(*pint), the pointer pint is changed to point to the location in memory with the value of what's pointed at by the pointer data - and who knows what's at that location in memory! (but it certainly isn't the value of data).

I am sorry for this long text, but I found no other/shorter way of explaining my problem/incapacity to understand. I apologize if this might seem foolish if you're an experienced programmer, but again, I'm a novice and I'm really trying to understand and break down everything to it's basics until I start actually using it. That being said, could you please set me straight on the explained above?