世纪问题?我基本上想知道如果我将此代码编写为几个不同的变量或者我使用小数组,哪个会更有效。
int x = 34;
int y = 28;
int z = 293;
对比
double coordinate[3] = {34, 28, 293};
我有一个坐标结构,我将通过以下方式使用它:
typedef struct coordinates_t {
double x = 0.0;
double y = 0.0;
double z = 0.0;
} coordinates;
typedef struct car_t {
coordinates start; // car starting point
coordinates location; // car current Location
coordinates targCarVector; // Vector to car from target
coordinates altitude; // Altitude of car
coordinates distance; // Distance from car start to current position
} car;
我需要做以下事情:
distance = car1.location - car1.start;
如果我不使用数组,我将不得不有很多代码行,但如果我使用数组,我将不得不使用循环。数组和循环是否更占用内存/cpu?我基本上是想看看哪种是编写此代码的最有效方式。
谢谢, 半羊