Can someone expalin what
int *x=(int *)malloc(n*sizeof(int)); means
sizeof(int)
is the amount of memory needed for one int (usually 4 bytes )
n*sizeof(int)
is memory needed for n integers
malloc(n*sizeof(int))
allocates a block of dynamic memory of required size and returns a void* to it
(int *)malloc(n*sizeof(int))
converts tat void* to an int*
int *x=(int *)malloc(n*sizeof(int));
assigns it to a variable
Last edited on