The following code is given in my Data Structure reference book.

#include<stdio.h>
main()
{
	int i, *pi;
	float f, *pf;
	pi = (int *) malloc(sizeof(int));
	pf = (float *) malloc(sizeof(float));
	*pi = 1024;
	*pf = 3.14;
	printf("an integer = %d, a float = %f", *pi, *pf);
	free(pi);
	free(pf);
}

But when i compile it, it gives the following error:

malloc.c: In function ‘main’:
malloc.c:6:15: warning: incompatible implicit declaration of built-in function ‘malloc’
malloc.c:11:2: warning: incompatible implicit declaration of built-in function ‘free’

Recommended Answers

All 2 Replies

malloc() and free() are declared in <stdlib.h>, you failed to include that header.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.