[ create a new paste ] login | about

Link: http://codepad.org/Swssnokq    [ raw code | output | fork ]

C, pasted on Nov 18:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
	char *pool = malloc(sizeof(int) * 2 + sizeof(long) * 3 + sizeof(float) * 2);

	int *i = (int *)(pool);
	long *l = (long *)(pool + sizeof(int) * 2);
	float *f = (float *)(pool  + sizeof(int) * 2 + sizeof(long) * 3);

	i[0] = 0;
	i[1] = 1;

	l[0] = 2;
	l[1] = 3;
	l[2] = 4;

	f[0] = 5.0;
	f[1] = 6.0;

	printf("%d %d\n", i[0], i[1]);
	printf("%d %d %d\n", l[0], l[1], l[2]);
	printf("%f %f\n", f[0], f[1]);

	free(pool);

	return 0;
}


Output:
1
2
3
0 1
2 3 4
5.000000 6.000000


Create a new paste based on this one


Comments: