Why is the array not getting properly initialized?
Code:#include<stdio.h> main(void) { int *p = malloc(5 * sizeof(int)); int i=0; while(i<5) { *p = i; i++; p++; } i=0; while(i<5) { printf("a[%d] = %d\n",i,*p); i++; } getchar(); return(0); }
Why is the array not getting properly initialized?
Code:#include<stdio.h> main(void) { int *p = malloc(5 * sizeof(int)); int i=0; while(i<5) { *p = i; i++; p++; } i=0; while(i<5) { printf("a[%d] = %d\n",i,*p); i++; } getchar(); return(0); }