// Test1.cpp 
//
// Pointer Demo by Professor M. Csele 2008/01


#include "stdafx.h"

//Declare data type first
typedef struct
{
	int	TestVar1;
	int	TestVar2;
	int	TestVar3;
} TEST;

//Put function first to avoid need to describe prototype
void ChangeIt(TEST *TStruct)
{
	//This does NOT work ...
	//TStruct.TestVar2 =3;
	//TStruct is NOT a struct itself, but a pointer

	//This DOES work ...
	TStruct->TestVar2 =3;
	//It dereferences the pointer tStruct
}

int main(int argc, char* argv[])
{

	//POINTERS ....

	int Cells[9]={0x55555555};					//An array of 32-bit integers
	char TestString[80]="Hello Cruel World";	//A normal char string

	int Counter;								
	
	for(Counter=0;Counter<9;Counter++)			//Fill the entire array with "U"
		Cells[Counter]=0x55555555;

	Cells[2]=0x41;								

	printf("String = %s\n",TestString);
	printf("String2 = %s\n",(char *)&TestString[2]);	//Show address as pointer
	printf("String3 = %s\n\n",(char *)&Cells[0]);			//Show little endian and typecast


	//STRUCTS ....


	TEST TestStruct;
	
	TestStruct.TestVar1=0x100;
	TestStruct.TestVar2=0x101;
	TestStruct.TestVar3=0x102;
	
	printf("Pre TestVar1 = %d\n",TestStruct.TestVar1);
	printf("Pre TestVar2 = %d\n",TestStruct.TestVar2);
	printf("Pre TestVar3 = %d\n",TestStruct.TestVar3);

	ChangeIt(&TestStruct);

	printf("Post TestVar1 = %d\n",TestStruct.TestVar1);
	printf("Post TestVar2 = %d\n",TestStruct.TestVar2);
	printf("Post TestVar3 = %d\n",TestStruct.TestVar3);

	return 0;
}


