I'm trying to find out the length of an array but i get weird numbers…
#include <stdio.h>
#include <stdlib.h>
const int numOfCoordinates = 100;
typedef struct {
int x;
int y;
int counter;
} Coordinate;
Coordinate *coordinatesMainArray;
Coordinate endPoint;
Coordinate startPoint;
int main(int argc, const char * argv[])
{
endPoint.x = 8;
endPoint.y = 3;
endPoint.counter = 0;
startPoint.x = 1;
startPoint.y = 4;
coordinatesMainArray = malloc(sizeof(Coordinate) * 1);
coordinatesMainArray[0] = endPoint;
int a = sizeof(coordinatesMainArray);
int b = sizeof(coordinatesMainArray[0]);
int coordinatesMainArrayLength = (a / b);
This is my code up until the part i need the length of coordinatesMainArray. But I get a = 8 and b = 12.
I assumed i would get two similar sizes so it shows i have one element in my array.
What am i doing wrong?