Click here to Skip to main content
15,039,359 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
void main()
{
	long int *ptr;
	clrscr();
	ptr=(long int*)malloc();
	*ptr=123456789;
	printf("%ld",*ptr);
	getch();
}

here I have not defined the size of malloc than also
it printing what is the reason

What I have tried:

output on the console is 123456789
Posted
Updated 17-Nov-17 22:00pm
Comments
Richard MacCutchan 18-Nov-17 5:35am
   
That should not even compile as malloc requires a parameter giving the required size in bytes.
keshav desai 18-Nov-17 6:46am
   
It is compiling without any error or warning I use turbo C compiler
Richard MacCutchan 18-Nov-17 6:54am
   
Then you should check the turbo C documentation on malloc to see what results to expect when you do not provide a size value.

1 solution

Quote:
here I have not defined the size of malloc than also
it printing what is the reason

Checking the dynamic memory allocation is your duty, making proper usage of malloc() is your responsability.
C will accept anything until it crash.

Advice: read malloc() documentation.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900