1
In the course of some questions here in the SO I saw this example and I was left with doubts.
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void main()
{
clrscr();
int *ptr,*temp;
int i;
ptr = (int *)malloc(4*sizeof(int));
temp = ptr;
for(i=0;i < 4;i++)
{
printf("Enter the Number %d : ",i);
scanf("%d",ptr);
ptr++;
}
ptr = temp;
for(i=0;i < 4;i++)
{
printf("\nNumber(%d) : %d",i,*ptr);
ptr++;
}
getch();
}
What is really happening in this example?
Why do you wear ptr++
and not ptr[x]
?
malloc does not always allocate continuous memory?