I am new to structures and I'm trying to do some tutorials to see if i understood well what i've been learning. Here's the code I wrote:
#include <stdio.h>
#include <stdlib.h>
typedef struct variables{
float Vx;
float Vy;
float Vz;
}velocity;
int main(){
velocity *pv;
pv = (velocity*)malloc(sizeof(velocity));
pv[0].Vx = 1;
pv[0].Vy = 2;
pv[0].Vz = 3;
free(pv);
return 0;
}
So my questions are 2:
Did I allocate the three variables in correct way?
Since I'm using the array notation why should I ever write
[0]
instead of[1]
or[2]
or so on?