0

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’

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by lastbencher
1

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.