increment float array ptr

eat*_*mon 0 c arrays pointers

I am trying to move the float array ptr 256 "units" from the start so (256 * 4 bytes) for floats. I am receiving a compile time error.

long new_capture_length = 4096;
long step_size = 256;
float data[new_capture_length];
data+=step_size;
Run Code Online (Sandbox Code Playgroud)

error: invalid operands to binary + (have ‘float[(long unsigned int)(new_capture_length)]’ and ‘float *’)

How can I achieve this?

Tyl*_*nry 5

你不能“移动”一个数组。您可以将指针移动到数组中,例如:

long new_capture_length = 4096;
long step_size = 256;
float data[new_capture_length];
float* p_data = &data[0];

p_data+=step_size; /* p_data now points 256 floats into data, i.e. to data[256]  */
Run Code Online (Sandbox Code Playgroud)

但是data它本身的位置永远不能改变,因为它不是一个指针。

我最近对一个非常相似的问题给出了更详细的答案:C 指针问题(我不喜欢将“这段代码有什么问题”类型的问题称为完全重复,即使它们具有相同的潜在问题)。