/*******************************************************************

 Some Pointer Examples (winXP with MS-VC++ v2003)


 int *a = NULL; // empty pointer to an integer
     &a = 0013FE00  address of a
      a = 00000000  content of a

 int b = 0x00434241;    // define any value
     &b = 0013FDF4        address of b
      b = 00434241        content of b
      b = 4407873         seen as int
      b = 434241          seen as hex
      b = 4407873.000000  cast to float
      b = A               cast to char

 a = &b;        // address of b becomes content of a
     &a = 0013FE00  address of a
      a = 0013FDF4  content of a equal to
     &b = 0013FDF4  address of b
      b = 00434241  content of b
      a = ABC  seen as zero-terminated string

 (float *) &b;  // cast to float
     &a = 0013FE00  address of a
      a = 0013FDF4  content of a equal to
     &b = 0013FDF4  address of b
      b = 00434241  content of b

 (char *) &b;  // cast to char
     &a = 0013FE00  address of a
      a = 0013FDF4  content of a equal to
     &b = 0013FDF4  address of b
      b = 00434241  content of b

 b = b++;  // changing b
     &a = 0013FE00  address of a
      a = 0013FDF4  content of a equal to b
     *a = 00434242  deref of a
    &*a = 0013FDF4  address of deref of a
     &b = 0013FDF4  address of b
      b = 00434242  hex content of b
      b = 4407874  dec content of b

 a = &b;   // how looks it now?
      a = BBC  seen as zero-terminated string


Press any key to continue


************************** pointer.cpp *****************************/


#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>


void example(void)
{
	printf("\n\n Some Pointer Examples (winXP with MS-VC++ v2003)  \n\n");

	int *a = NULL;		// pointer to an integer 
	printf("\n int *a = NULL;	// empty pointer to an integer \n");
	printf("     &a = %p  address of a \n", &a);
	printf("      a = %p  content of a \n", a);

	int b = 0x00434241;	// define any value 
	printf("\n int b = 0x%p;	// define any value   \n", b);
	// ( Das Intel integer-Format ist doppelt verdreht)
	printf("     &b = %p\t  address of b \n", &b);
	printf("      b = %p\t  content of b \n", b);
	printf("      b = %i\t  seen as int \n", b);
	printf("      b = %x\t  seen as hex \n", b);
	printf("      b = %f  cast to float \n", (float) b);
	printf("      b = %c\t\t  cast to char \n", (char) b);

	a = &b;		// address of b becomes content of a
	printf("\n a = &b;	// address of b becomes content of a   \n");
	printf("     &a = %p  address of a \n", &a);
	printf("      a = %p  content of a equal to \n", a);
	printf("     &b = %p  address of b \n", &b);
	printf("      b = %p  content of b \n", b);
	printf("      a = %s  seen as zero-terminated string \n", a);

	(float *) &b;  // cast to float (unchanged)
	printf("\n (float *) &b;  // casting to float   \n");
	printf("     &a = %p  address of a \n", &a);
	printf("      a = %p  content of a equal to \n", a);
	printf("     &b = %p  address of b \n", &b);
	printf("      b = %p  content of b \n", b);

	(char *) &b;  // cast to char (unchanged)
	printf("\n (char *) &b;  // casting to char  \n");
	printf("     &a = %p  address of a \n", &a);
	printf("      a = %p  content of a equal to \n", a);
	printf("     &b = %p  address of b \n", &b);
	printf("      b = %p  content of b \n", b);

	b = b++;	// changing b
	printf("\n b = b++;  // changing b  \n");
	printf("     &a = %p  address of a \n", &a);
	printf("      a = %p  content of a equal to b \n", a);
	printf("     *a = %p  deref of a \n", *a);
	printf("    &*a = %p  address of deref of a \n", &*a);
	printf("     &b = %p  address of b \n", &b);
	printf("      b = %p  hex content of b \n", b);
	printf("      b = %d  dec content of b \n", b);
	// printf("     *b = %p  deref of b (error) \n", *b);

	a = &b;		// how looks it now?
	printf("\n a = &b;   // how looks it now? \n");
	printf("      a = %s  seen as zero-terminated string \n", a);

	printf("\n\n");

}


int main(void) 
{
   example();
}



/*******************************************************************

Programm ausführen unter MS Visual C++ :
	1) Datei/Neu/Projekt/Visual C++/ "WIN32-Konsolenanwendung"
	2) pointer.cpp einfügen
	3) Erstellen/... erstellen
	4) Menue/Debuggen/ "Starten ohne Debuggen"

Open Source: www.gfai.de/~heinz/techdocs/pointer.cpp

*/

