What's the difference between 1 and 2?
-
int *p; p = malloc(2 * sizeof(int));
-
int *p = malloc(2 * sizeof(int));
The way I first learned it is number 1, but I've seen someone do it number 2. Is number 1 and 2 the same thing? I'm assuming it is, but I'm confused because I don't understand why number 2 is
int *p = malloc(2 * sizeof(int));
not
int p = malloc(2 * sizeof(int));
The way he used it was for array. Later in the code, he used p to save some desired values.
Like this.
p[0] = i;
p[1] = j;