All pastes #268724 Raw Edit

Someone

public text v1 · immutable
·published 2006-12-05 23:25 UTC
rendered paste body
/* typecast.c - Script 10.2 */

#include <stdio.h>
#include <stdlib.h>
int main(void) { 
	//Test conflict - to do so, uncomment
	//int x = 3;
	//Define and initialize a void pointer variable 
	void *x = NULL;
	
	// Request block of memory large enough to hold an integer
	x = malloc(sizeof(int));
	
	//Check for a NULL
	if (x == NULL) {
			printf("Unable to allocate!\n");
			printf("Exitting the program\n");
			getchar();
			return 0;
	}
	// Print out starting address of the memory block
	printf("Starting address: %p.\n", x);

	// Store integer value into meory block using type cast and derefrencing
	*(int *)x = 1234;
	// Print value
	printf("Value stored in the memory block: %d\n", *(int *)x);
	free(x);
	x = NULL;
	
	getchar();
	return 0;
	
} // Complete main function