In the above program,I assign 0 memory by using ary=(int*)malloc(0*sizeof(int));Code:#include <stdio.h> #include <stdlib.h> int main(void){ int i,*ary; ary=(int*)malloc(0*sizeof(int)); //assign memory for(i=0;i<5;i++){ //input 5numbers printf("\n Please input number %d : ",i); scanf("%d",ary+i); } for(i=0;i<5;i++){ //output the numbers printf("\n%d -> %d",i,ary[i]); } free(ary); }
Since the memory is zero, it should not be able to read any values and output it rite? this program somehow inputs and outputs all the numbers.
Wheres' the error? any one knows?
thanx.