gpt4 book ai didi

检查数组的长度

转载 作者:行者123 更新时间:2023-12-02 04:49:32 24 4
gpt4 key购买 nike

<分区>

#define lengthOfArray(x)  (sizeof(x) / sizeof(x[0]))

似乎在 main() 中给出了正确的答案,但在 array_set() 的 printf() 中。我错过了什么吗?

int* decValue2[BUF_SIZE] = {
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
0x99, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
};

#define lengthOfArray(x) (sizeof(x) / sizeof(x[0]))


void array_set(int* y_dest, int* y_src, int arrayLength){ // arrays
int i = 0;

printf("lengthOfArray in function: %d \n", lengthOfArray(y_src));
// [TODO] check that y_dest has enough space
for (i=0;i<arrayLength; i++)
y_dest[i] = y_src[i];
//
}


// In main()

int y_int = 0;
int y_array[BUF_SIZE];

int_set_right( &y_int, 9876543);
array_set(y_array, decValue2, BUF_SIZE);

printf("lengthOfArray: %d \n", lengthOfArray(y_array));

printf("Value int :: %d \n",y_int);
int i = 0;
for (i=0;i<BUF_SIZE; i++)
printf("%x ", (0xff & y_array[i]));

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com