K&R——第五章 指针与数组

#include <stdio.h>

#define maxsize 5000

char buf[maxsize];
char *head = buf;

char *new(int size)
{
	//分配元素字长
	
	//可用内存分配完毕
	if (maxsize - (buf - head) < size) 
		return 0;
	head += size;
	return head - size;
}

int *arr;
int *arr2;
char *str;

int main()
{
	arr = new(3 * sizeof(int));
	arr2 = new(3 * sizeof(int));
	str = new(10 * sizeof(char));
	
	for (int i=0;i<3;i++)
		scanf("%d",&arr[i]);
	for (int i=0;i<3;i++)
		scanf("%d",&arr2[i]);
	
	scanf("%s",str);
	
	for (int i=0;i<6;i++)
		printf("%d
",arr[i]);
	
	printf("%s
",str);
}

  

原文地址:https://www.cnblogs.com/dandi/p/4014402.html